Error in building MPI program

2019-07-15 08:39发布

问题:

I'm new to MPI. I'm trying to write a program for calculating PI using MPI and FORTRAN. But when I try to build the program I get the following messages.

make all
 gfortran -O2 -g \
    -o bin/MpiTest.exe \
    src/MpiTest.f -fno-range-check
C:/Program Files/MicrosoftMPI/Inc/mpif.h:344.38:
    Included at src/MpiTest.f:11:

       PARAMETER (MPI_AINT=z'4c00043b')                                 
                                      1
Error: PARAMETER attribute of 'mpi_aint' conflicts with PARAMETER attribute at (1)
C:/Program Files/MicrosoftMPI/Inc/mpif.h:359.35:
    Included at src/MpiTest.f:11:

       PARAMETER (MPI_ADDRESS_KIND=INT_PTR_KIND())                      
                                   1
Error: Function 'int_ptr_kind' in initialization expression at (1) must be an intrinsic function
make: *** [all] Error 1

Can anyone help me here ?

P.S :

PROGRAM CalculatePI
        include "C:/Program Files/MicrosoftMPI/Inc/mpif.h"

            INTEGER :: i = 0, nThrows = 0, nSuccess = 0, ierror =0, numOfProcessors=0,myID=0
            REAL :: x = 0, y = 0, results = 0

            INTEGER :: Counter = 0

            call mpi_init(ierror)
            call mpi_comm_rank(MPI_COMM_WORLD, myID, ierror)
            call mpi_comm_size(MPI_COMM_WORLD, numOfProcessors, ierror)
            ....

回答1:

INT_PTR_KIND is an Intel Fortran compiler extension function; that is, it is not a Fortran intrinsic. The second of the error messages that you report indicates that gfortran is baulking at compiling code which contains references to a function it can't find. I guess the first error arises from the same problem, you are trying to compile with the 'wrong' compiler.

As Alexander Vogt has suggested you might make better progress using a compiler wrapper such as mpif90, but it has to be the right wrapper, the one which calls gfortran and links with the MS MPI library. Whether that wrapper exists I do not know, but look for it under C:/Program Files/MicrosoftMPI/.

However, since those errors emanate from the mpif.h file you have included you'll also have to find a corresponding include file for compiling with gfortran. I don't use MS MPI but it won't surprise me if you find that it only provides tools, libraries and include files for compilation with Intel Fortran.



回答2:

You should not compile your MPI code with gfortran alone. Instead, use the wrapper provided by your MPI library. Typically it is called mpif90.

Thanks to High Performance Mark for the clarifications.



标签: fortran mpi