一:环境
Ubuntu 10.04(lucid) 内核Linux 2.6.32-30-generic
内存:2G 处理器: Pentium(R) Dual-Core cpu
#include<stdio.h>
#include<omp.h>
#include<time.h>
int main()
{
int N =1;
int i;
clock_t t0 =clock();
#pragma omp parallel for num_threads(5)
for(i=1;i<=100000;i++)
{
printf("total thread num is %d\n",omp_get_num_threads());
N *= i;
printf("the thread num is:%d\n",omp_get_thread_num());
}
clock_t t1 = clock();
printf("%d & %d\n",t0,t1);
printf("total time is %d\n",(int)(t1-t0));
printf("最后结果 = %d\n",N);
return 0;
}
很困惑使用OpenMP竟然更慢了,在这段程序中我只用了最基本的"parallel for",并没有很复杂的指令呀, 到底是什么原因变慢了呢,希望某位对OpenMP有研究的高手指点迷津!