我有一个非常ᴄᴘᴜ密集(50万次调用和超过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);
}
}
Run Code Online (Sandbox Code Playgroud)
由于#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);
}
}
Run Code Online (Sandbox Code Playgroud)
没有openmp就完美无缺.但是当我添加时
#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);
}
}
Run Code Online (Sandbox Code Playgroud)
值i似乎没有改变,所以它变成了一个无限循环.
小智 1
这有帮助吗?
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
232 次 |
| 最近记录: |