You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在do-while循环中使用OpenMP并行化PDE迭代求解器?

关于PDE迭代求解器的OpenMP并行化问题

我有一个用于求解PDE(例如Poisson方程)的迭代求解器,需多次迭代才能收敛到正确解。该函数占用大量代码运行时间,因此尝试用OpenMP对其并行化。

原do-while循环示例代码如下:

int count = 0;
    
// Begin do-while loop
do{         
// Make Calculations: multiplication and some addition
        
// Increase iteration count by 1
count = count + 1;
        
// Calculate error
it_error = fabs((newsol_max-oldsol_max)/newsol_max); // newsol_max = max value of new solution and oldsol_max is the solution in the previous iteration

//err_max is the error we want to converge to   
// If error is too high and we haven't reached the max iterations yet, repeat iterations
}while( it_error > err_max && count  <= max_iter && newsol_max > err_max); 
return count;

这个do-while循环先执行循环体,再判断while条件:it_error > err_max && count <= max_iter && newsol_max > err_max。

我看到过一段展示OpenMP与while循环结合的通用思路代码:

int counter = 0;
#pragma omp parallel
while(1) {
     int local_counter;
     #pragma omp atomic read
     local_counter = counter;
     if (local_counter >= MAX) {
          break;
     }
     // do monte carlo stuff
     // if a certain condition is met, counter is incremented
     if (certain_condition) {
         #pragma omp atomic update
         counter++;
     }
}

但我不确定这种思路是否适用于先执行循环体再判断条件的do-while循环,同时想知道此处的&&运算符是否存在归约可能性。

注:我可提供最小可运行示例


内容的提问来源于stack exchange,提问作者Jamie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 15:27:44