我正在编写一段代码,其中包含一个循环(~10^6-10^7),其中一个数组(比方说,我的结果)是通过对大量贡献的求和来计算的。在使用OpenMP的Fortran 90中,如下所示:
!$omp parallel do
!$omp& reduction(+:myresult)
do i=1,N
myresult[i] = myresult[i] + [contribution]
enddo
!$omp end parallel代码将在带有Intel Xeon协处理器的系统上运行,如果可能的话,当然希望从它们的存在中获益。我试过使用MIC卸载语句(!dir$ offload target .)使用OpenMP,循环只在协处理器上运行,但当它坐在那里等待协处理器完成时,我却在浪费主机CPU时间。理想情况下,我们可以在主机和设备之间划分循环,所以我想知道下面这样的内容是否可行(或者是否有更好的方法);循环只能在主机上的一个核心上运行(尽管可能使用OMP_NUM_THREADS=2?):
!$omp parallel sections
!$omp& reduction(+:myresult)
!$omp section ! parallel calculation on device
!dir$ offload target mic
!$omp parallel do
!$omp& reduction(+:myresult)
(do i=N/2+1,N)
!$omp end parallel do
!$omp section ! serial calculation on host
(do i=1,N/2)
!$omp end parallel sections发布于 2014-05-19 17:43:23
一般的想法是使用异步卸载到MIC,以便CPU可以继续。撇开如何划分工作的细节不谈,这是如何表述的:
module m
!dir$ attributes offload:mic :: myresult, micresult
integer :: myresult(10000)
integer :: result
integer :: micresult
end module
use m
N = 10000
result = 0
micresult = 0
myresult = 0
!dir$ omp offload target(mic:0) signal(micresult)
!$omp parallel do reduction(+:micresult)
do i=N,N/2
micresult = myresult(i) + 55
enddo
!$omp end parallel do
!$omp parallel do reduction(+:result)
do i=1,N/2
result = myresult(i) + 55
enddo
!$omp end parallel do
!dir$ offload_wait target(mic:0) wait(micresult)
result = result + micresult
end发布于 2014-05-16 18:39:07
您考虑过使用MPI对称模式而不是卸载吗?如果没有,MPI可以做您刚才描述的事情:启动两个MPI级别,一个在主机上,一个在协处理器上。每个级别使用OpenMP执行一个并行循环。
https://stackoverflow.com/questions/23690335
复制相似问题