我想用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