对于循环,我有一个非常密集的ᴄᴘᴜ(5000万个呼叫和100多个双离子循环阶段),例如:
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);
}
}由于#pragma omp parallel for odered不允许break语句,所以我认为可以将i设置为一个非常大的值。
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);
}
}完全没有开胸的效果。但是当我加上
#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);
}
}i的值似乎没有变化,因此它变成了一个无限循环。
发布于 2015-12-27 05:09:40
这个有用吗?
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);
}
}
}https://stackoverflow.com/questions/34453935
复制相似问题