I would like to parallalize a c++ code with OpenMP. The code is not quite simple, but in my opinion the parallelization shoud not be hard, as I have an ensemble of independent systems, and i want to parellelize the for loop that spans over the std::vector which contains the systems.
The dimension of the ensamble is DIM_ENSEMBLE
Here is the interesting part of the code, with my attempt to parallelize. which of course doesn't work.
vector<Systems> system(DIM_ENSEMBLE);
vector<double> current(100);
System is a struct which contain some 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
Here is a compilation error:
one-node-hirsch-parallel.cpp:173: error: ‘cout’ not specified in enclosing parallel
one-node-hirsch-parallel.cpp:154: error: enclosing parallel