How to break opemp loop?

I have a very intense (50 million calls and over 100 cycles of cycle cycles) for a cycle, for example:

for(int i=0;i<*string;i++){ if(!check_some_stuff(string+i)) { do_some_stuff(i,string-2); if(!string) break; do_yet_other_stuff(string); } } 

As the break statements allowed for #pragma omp parallel for odered , I thought I could set i to a very large value.

 for(int i=0;i<*string;i++){ if(!check_some_stuff(string+i)) { do_some_stuff(i,string-2); if(!string) i=0x7FFFFFFB; do_yet_other_stuff(string); } } 

which works fine without openmp. But when I add

 #pragma omp parallel for ordered shared(string) for(int i=0;i<*string;i++){ if(!check_some_stuff(string+i)) { do_some_stuff(i,string-2); #pragma omp critical if(!string) i=0x7FFFFFFB; // it seems the assignment has no effect on the value of i. do_yet_other_stuff(*string); } } 

the value of i does not seem to change, so it refers to an infinite loop.

+6
source share
1 answer

Does it help?

 int abort = 0; #pragma omp parallel for ordered shared(string, abort) for(int i=0;i<*string;i++) { #pragma omp flush(abort) if(!abort) { if(!check_some_stuff(string+i)) { #pragma omp flush(abort) if(!abort) do_some_stuff(i,string-2); if(!string) abort = 1; #pragma omp flush(abort) if(!abort) do_yet_other_stuff(*string); } } } 
0
source

All Articles