MSMPI就地MPI_Allreduce无法与MinGW-w64 gfortran一起使用 [英] MSMPI in-place MPI_Allreduce not working with MinGW-w64 gfortran

查看:169
本文介绍了MSMPI就地MPI_Allreduce无法与MinGW-w64 gfortran一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Minc-w64 gfortran(MSYS64提供的9.2版本)和Microsoft MPI(版本10)结合使用就地MPI_Allreduce

I am trying to use the in-place MPI_Allreduce with the combination of MinGW-w64 gfortran (version 9.2 provided by MSYS64) and Microsoft MPI (version 10),

call MPI_Allreduce(MPI_IN_PLACE, srcdst, n, MPI_REAL8, MPI_SUM, MPI_COMM_WORLD, ierr)

标准MPI_Allreduce(具有不同的源和目标)效果很好,当我使用C代替Fortran时就地变体也是如此.

The standard MPI_Allreduce (with distinct source and destination) works well, as does the in-place variant when I use C instead of Fortran.

完整的测试程序 test_allreduce.f90

program test_allreduce

    use iso_fortran_env, only: real64
    use mpi

    implicit none

    integer, parameter :: mpiint = kind(MPI_COMM_WORLD)

    integer(mpiint) :: n = 10
    integer(mpiint) :: ierr1 = -1, ierr2 = -1, ierr3 = -1, ierr4 = -1

    real(real64) :: src(10) = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /)
    real(real64) :: dst(10) = 0

    call MPI_Init(ierr1)
    call MPI_Allreduce(src, dst, n, MPI_REAL8, MPI_SUM, MPI_COMM_WORLD, ierr2)
    call MPI_Allreduce(MPI_IN_PLACE, src, n, MPI_REAL8, MPI_SUM, MPI_COMM_WORLD, ierr3)
    call MPI_Finalize(ierr4)

    write (*, '(I4)') MPI_IN_PLACE
    write (*, '(4I4)') ierr1, ierr2, ierr3, ierr4
    write (*, '(10F4.0)') src
    write (*, '(10F4.0)') dst

end program

这是我的编译方式:

set "PATH=C:\msys64\mingw64\bin;%PATH%"

x86_64-w64-mingw32-gfortran ^
    -fno-range-check ^
    "C:\Program Files (x86)\Microsoft SDKs\MPI\Include\mpi.f90" ^
    test_allreduce.f90 ^
    -I . ^
    -I "C:\Program Files (x86)\Microsoft SDKs\MPI\Include\x64" ^
    -o test_allreduce.exe ^
    C:\Windows\System32\msmpi.dll

这就是我执行它的方式(到目前为止,仅在单个过程中):

And this is how I execute it (in single process only so far):

test_allreduce.exe

当前,它会打印

   0
0   0   0   0
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
1.  2.  3.  4.  5.  6.  7.  8.  9. 10.

显然,在第二次(就地)对MPI_Allreduce的调用中,src缓冲区被垃圾覆盖.

Apparently, the src buffer gets overwritten by garbage in the second (in-place) call to MPI_Allreduce.

我在mpi.f90特定于Intel的DLLIMPORT指令的代码中看到了,甚至试图添加类比

I saw in the code of mpi.f90 Intel-specific DLLIMPORT directives and even attempted to add analogical

!GCC$ ATTRIBUTES DLLIMPORT :: MPI_IN_PLACE

没有任何效果.

推荐答案

原来的麻烦是,在MSMPI中,变量MPI_IN_PLACE包含在内部COMMON/MPIPRIV1/中,并且它是 gfortran中的已知错误,表明编译器无法正确导入COMMON阻止DLL中的变量.

It turns out that the trouble is that in MSMPI the variable MPI_IN_PLACE is contained in an internal COMMON block /MPIPRIV1/ and it is a known bug in gfortran that the compiler fails to properly import COMMON block variables from DLLs.

尽管如此,可以修复损坏的东西,最后要做的就是将 patch 应用于gfortran代码并在MSYS2( phew ... )中从头开始编译,添加指令

Nevertheless, broken things can be fixed, and in the end all that was needed was to apply a patch to gfortran code and compile it from scratch in MSYS2 (phew...), and add the directive

!GCC$ ATTRIBUTES DLLIMPORT ::  MPI_BOTTOM, MPI_IN_PLACE

上面提供的代码中implicit none之后的

. (指令中似乎都需要这两个变量,因为MPI_IN_PLACE在内部COMMON块中紧随MPI_BOTTOM之后排第二.)然后,就地MPI_Allreduce可以正常工作.

right after implicit none in the above presented code. (Both these variables seem to be needed in the directive, because MPI_IN_PLACE is second in the internal COMMON block just after MPI_BOTTOM.) Then the in-place MPI_Allreduce works flawlessly.

这篇关于MSMPI就地MPI_Allreduce无法与MinGW-w64 gfortran一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆