我想用 OpenMP 并行化 c++ 代码。代码不是很简单,但在我看来,并行化应该不难,因为我有一个独立系统的集合,我想并行化跨越包含系统的 std::vector 的 for 循环。
集合的维度是 DIM_ENSEMBLE
这是代码中有趣的部分,我尝试并行化。这当然行不通。
vector<Systems> system(DIM_ENSEMBLE);
vector<double> current(100);
System 是一个包含一些 std::vector 的结构
/* 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