This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C6678使用openMP的问题



我在c6678使用openmp(版本是openmp_dsp_2_01_17_01)进行多核并行运算,遇到两个不解问题,在此请教大家

第一个问题:

编译器不识别#pragma omp parallel sections语句,我只有写成

#pragma omp parallel
{
#pragma omp sections
{
#pragma omp section
{......}

}

}

才能编译,不知道是怎么回事?

第二个问题,我若把每个section语句中用到的变量定义在section内部,则运行速度很快,能达到想要的效果,但是把这些变量定义到section外部,则速度特别慢,请问大家怎么回事?

例子对比

1、变量定义在section内部的代码

/*
* main.c
*/
#include "c6x.h" //测量程序执行时间用
#include "stdio.h"
#include "omp.h"
int zbj;
int main(void) {


TSCL=0;
long long t1,t2;

t1 = _itoll (TSCH, TSCL);

#pragma omp parallel
{
#pragma omp sections
{
#pragma omp section
{
unsigned int i,a;                                       //变量定义在section内部

for(i=0;i<50000;i++)
{
a=(i+1)+2*i;
zbj =a;
}

}
#pragma omp section
{
unsigned int j,b;                             //变量定义在section内部
for(j=0;j<50000;j++)
{
b=(j+1)+2*j;
}
zbj = zbj+b;

}

#pragma omp section
{
unsigned int k,c;                                 //变量定义在section内部
for(k=0;k<50000;k++)
{
c=(k+1)+2*k;
}
zbj = zbj+c;

}

#pragma omp section
{
unsigned int l,d;                                 //变量定义在section内部
for(l=0;l<50000;l++)
{
d=(l+1)+2*l;
}
zbj = zbj+d;

}
#pragma omp section
{
unsigned int m,e;                                   //变量定义在section内部
for(m=0;m<50000;m++)
{
e=(m+1)+2*m;
}
zbj = zbj+e;

}
#pragma omp section
{
unsigned int n,f;                                   //变量定义在section内部
for(n=0;n<50000;n++)
{
f=(n+1)+2*n;
}
zbj = zbj+f;

}
#pragma omp section
{
unsigned int o,g;                                           //变量定义在section内部
for(o=0;o<50000;o++)
{
g=(o+1)+2*o;
}
zbj = zbj+g;

}
#pragma omp section
{
unsigned int p,h;                                       //变量定义在section内部
for(p=0;p<50000;p++)
{
h=(p+1)+2*p;
}
zbj = zbj+h;

}

}
}
t2= _itoll(TSCH, TSCL);
printf("time is %lld,%d\n",t2-t1,DNUM);

printf("zbj is %d,%d\n",zbj,DNUM);

return 0;
}


[C66xx_0] time is 30868,0  //运行时间为30868个时钟周期
zbj is 1199984,0

2、变量定义在section外部


/*
* main.c
*/
#include "c6x.h" //测量程序执行时间用
#include "stdio.h"
#include "omp.h"
int zbj;
int main(void) {


TSCL=0;
long long t1,t2;
unsigned int i,j,k,l,m,n,o,p;                                   //变量定义在section外部
unsigned int a,b,c,d,e,f,g,h;                                 //变量定义在section外部
t1 = _itoll (TSCH, TSCL);

#pragma omp parallel
{
#pragma omp sections
{
#pragma omp section
{

for(i=0;i<50000;i++)
{
a=(i+1)+2*i;
zbj =a;
}

}
#pragma omp section
{

for(j=0;j<50000;j++)
{
b=(j+1)+2*j;
}
zbj = zbj+b;

}

#pragma omp section
{

for(k=0;k<50000;k++)
{
c=(k+1)+2*k;
}
zbj = zbj+c;

}

#pragma omp section
{

for(l=0;l<50000;l++)
{
d=(l+1)+2*l;
}
zbj = zbj+d;

}
#pragma omp section
{

for(m=0;m<50000;m++)
{
e=(m+1)+2*m;
}
zbj = zbj+e;

}
#pragma omp section
{

for(n=0;n<50000;n++)
{
f=(n+1)+2*n;
}
zbj = zbj+f;

}
#pragma omp section
{

for(o=0;o<50000;o++)
{
g=(o+1)+2*o;
}
zbj = zbj+g;

}
#pragma omp section
{

for(p=0;p<50000;p++)
{
h=(p+1)+2*p;
}
zbj = zbj+h;

}


}
}
t2= _itoll(TSCH, TSCL);
printf("time is %lld,%d\n",t2-t1,DNUM);

printf("zbj is %d,%d\n",zbj,DNUM);

return 0;
}


[C66xx_0] time is 27059993,0          //运行时间27059993个时钟周期
zbj is 1199984,0

可见变量定义在section内部远远比定义在外部快了许多?请问怎么回事?