I have a very ᴄᴘᴜ intensive (50 millions calls and over 100 bilions looping phase) for loop such as :
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 break statements aren't 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 perfectly works without openmp. But however 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
doesn't seems to change, so it turns to an infinite loop.
Does this 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);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.