I have the following piece of code which I want to add omp for to:
for ( int i = 0 ; i < N ; i++ ) {
double max2 = 0.;
(calculate max2);
for ( int j = 0 ; j < 3 ; j++) {
int m = group[i].member[j];
if ( members[m].norm < max2 ) {
members[m].norm = max2;
}
}
}
The access to members needs to be protected but I would like to use a named critical section so as to avoid the speed penalty of effectively serializing that loop. What I want to do is this:
#pragma omp parallel for
for ( int i = 0 ; i < N ; i++ ) {
double max2 = 0.;
(calculate max2);
for ( int j = 0 ; j < 3 ; j++) {
int m = group[i].member[j];
#pragma omp critical (m)
if ( members[m].norm < max2 ) {
members[m].norm = max2;
}
}
}
so that only threads actually writing to the same m value wait for each other. My question is: is "m" used as a string for the critical name or is it actually evaluated and its value used as the name of the critical section? It does compile but I do not know if it does what I think it does. I would greatly appreciate if anyone can clarify what omp does here (eg how omp implements these).
Thank you * very much.