我想用OpenMP对C++代码进行并行化。代码不是很简单,但在我看来,并行化并不难,因为我有一个独立系统的集合,我想parellelize横跨包含系统的std :: vector的for循环。使用OpenMP对整体进行并行化计算
的ensamble的尺寸为DIM_ENSEMBLE
这里是代码的有趣的部分,我尝试并行。这当然不起作用。
vector<Systems> system(DIM_ENSEMBLE);
vector<double> current(100);
系统是其中含有一些的std ::矢量
/* do things
...
*/
while (time < T){
/*154*/ #pragma omp parallel for default(none) shared(r, DIM_ENSEMBLE, system, current) private(i, max_rate, time_increment, R, j, status)
for (i =0; i< DIM_ENSEMBLE; i++) {
max_rate = function_A_of(i);
time_increment = function_B_of(r,max_rate);
R = function_C_of(r,max_rate);
j = function_D_of(System, i, R);
status = update_the_system(&system[0], i, time_increment, j, ¤t[0]);
if (status!=1) {
#pragma omp critical
{
/*173*/ cout << "ERROR " << i << " " << time_increment << " " << j <<endl;
}
}
update_time(time);
} //end for loop
/* now calculate some averages and distributions from the ensemble
....
*/
} //end while loop
这里一个结构被编译错误:
one-node-hirsch-parallel.cpp:173: error: ‘cout’ not specified in enclosing parallel
one-node-hirsch-parallel.cpp:154: error: enclosing parallel
在您的书名中,您写了[OpenMP](http://en.wikipedia.org/wiki/OpenMP),并且在您编写的问题中[Open MPI](http://en.wikipedia.org/wiki/Open_MPI )... –
@Kyle_the_hacker。谢谢,完成。 – altroware