Parallel computation of loops
Posted: Sun Nov 10, 2019 12:55 am
Hello,
I have the following loop in cs_user_extra_operations.c file:
This code calculates a variable(Tau_Wall_Mean) in a loop and then writes it to a file(MEAN_SHEAR.dat). I use 8 cores for processing.
When I open the exported file, It gives me 8 different values at each time step number which means that each core is computing (maybe a part of) the loop separately and gives a different value and the code does not collect the result from the cores.
How can I force the loop to collect the results from all cores and give me just one number?
Does this problem occur just for the loops which a variable should be summed by its previous value?
CS version: 5.0.9
Regards,
Mohammad
I have the following loop in cs_user_extra_operations.c file:
Code: Select all
for (cs_lnum_t i = 0; i < n_faces; i++) {
face_id = face_list[i];
iel = b_face_cells[face_id];
Tau_Wall_Mean += Tau_wall[iel];
}
FILE *f1 = NULL;
f1 = fopen("MEAN_SHEAR.dat","a");
fprintf(f1, "%i\t%f\n", ntcabs, Tau_Wall_Mean/n_faces);
fclose (f1);
When I open the exported file, It gives me 8 different values at each time step number which means that each core is computing (maybe a part of) the loop separately and gives a different value and the code does not collect the result from the cores.
How can I force the loop to collect the results from all cores and give me just one number?
Does this problem occur just for the loops which a variable should be summed by its previous value?
CS version: 5.0.9
Regards,
Mohammad