#include <stdio.h>
#include <stdlib.h>
#include <c6x.h>
void test()
{
int a = 0;
for (int i = 0; i<100000; i++)
a++;
printf("a is :%ld\n",a);
}
int main()
{
printf("starting running\n");
unsigned long long t1,t2;
TSCL = 0;
TSCH = 0;
t1 = _itoll(TSCH,TSCL);
for (int i = 0; i<100; i++)
test();
t2 = _itoll(TSCH,TSCL);
printf("time is: %ld\n",(t2-t1));
}
这个时我单核的一个Demo,运行时间时210318543
#include <ti/omp/omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <c6x.h>
void test()
{
int a = 0;
for (int j = 0; j<100000; j++)
a++;
printf("a is :%ld\n",a);
}
void main()
{
printf("starting running\n");
unsigned long long t1,t2;
TSCL = 0;
TSCH = 0;
t1 = _itoll(TSCH,TSCL);
#pragma omp parallel for
for (int i = 0; i<100; i++)
test();
t2 = _itoll(TSCH,TSCL);
printf("time is: %ld\n",(t2-t1));
}
这个时我用OMP指定四核来跑这个Demo,时间是682829192.
按理说多核的时间应该比单核少3倍多,怎么反而多了3倍多呢???
Thomas Yang1:
您的变量 a 定义在哪个memory 空间的,另外把 printf去掉试试