OpenMP嵌套任务构造行为疑问及编译器一致性问题咨询
OpenMP嵌套任务构造的跨编译器行为疑问
测试MagIC程序时,我遇到了OpenMP嵌套任务构造(详见OpenMP 5.0规范第137页)相关问题。使用Intel、GNU和Arm编译器编译该程序时,表现出不一致的行为:Intel与GNU编译器编译的程序运行正常,而Arm编译器编译的程序执行时触发段错误。
以下是可复现问题的简化伪代码(完整示例详见MagIC项目src/updateS.f90文件第199-308行):
!$omp parallel default(shared) [...] !$omp single !$omp task default(shared) & !$omp private(l1) & !$omp private(n,i) [...] l1=l1_value n=5 do i=1,n !$omp task default(shared) & !$omp firstprivate(i) [...] [使用l1作为索引访问数组] !$omp end task end do !$omp taskwait !$omp end task !$omp end single !$omp end parallel
在原代码中,内层任务构造内l1的值变为未定义,导致执行时访问数组触发段错误。我测试了l1的多种声明方式,将其在内层任务构造中声明为firstprivate可修复问题(使最内层构造获取l1的最终值)。
但我仍对规范存在疑问,规范中提到:
If a task construct is encountered during execution of an outer task, the generated task region that corresponds to this construct is not a part of the outer task region unless the generated task is an included task.
我的疑问如下:
- OpenMP是否将内层任务构造视为外层任务的included task?
- 原代码中,l1的值是否应传递到内层任务构造中,还是本就应处于未定义状态?
- 哪个编译器的行为符合规范,以便我正确提交问题报告?
内容的提问来源于stack exchange,提问作者JulieGaspar
相关产品推荐
相关产品推荐

