测试代码:
#include<stdio.h>
#include<stdlib.h>
#include <sys/time.h>
int main(void)
{
int i,j;
int sec;
struct timeval t1, t2;
gettimeofday(&t1, NULL);
//#pragma omp parallel
{
for (i=0;i<10000;i++)
{
for(j=0; j<100000; j++)
;
}
}
gettimeofday(&t2, NULL);
sec = t2.tv_sec*1000 + t2.tv_usec/1000 - (t1.tv_sec*1000 + t1.tv_usec/1000);
printf("sec:%d\n", sec);
return 0;
}
无openmp的测试代码编译方法:
arm-hisiv300-linux-gcc -o noomp_test omp_test.c -static
有openmp的测试代码编译方法:
arm-hisiv300-linux-gcc -fopenmp -o omp_test omp_test.c -static
同时将上面#pragma omp parallel打开
在设备(4核CPU)上测试结果如下:
/home # ./omp_test
sec:1700ms
/home # ./noomp_test
sec:5717ms
使用omp的编译比没有omp的要快很多