今天用了一下openmp,本人表示非常喜欢openmp的傻瓜化模式,导入一个头文件
#include <iostream>
#include <omp.h>
using namespace std;
int main()
{
//cout<<"Thread num == "<<omp_get_thread_num()<<endl;
#pragma omp parallel for num_threads(4)
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
printf("(%d,%d)",i,j);
cout<<" Thread num == "<<omp_get_thread_num()<<endl;
}
}
}
可以看出这个编译指导语句中的for是只对这句下一个for有用
#include <iostream>
#include <omp.h>
using namespace std;
int main()
{
//cout<<"Thread num == "<<omp_get_thread_num()<<endl;
#pragma omp parallel num_threads(4)
{
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
printf("(%d,%d)",i,j);
cout<<" Thread num == "<<omp_get_thread_num()<<endl;
}
}
}
}
可以看出是所有4*4的循环完全打乱的情况
over~~~~~~
OpenMP #pragma omp parallel for并行化小探究
原文地址:http://blog.csdn.net/scythe666/article/details/45499631