Unresolved external symbol MPI_INIT when compiling MPI with PGI Visual Fortran

948 Views Asked by At

I am using Visual Fortran and I'm trying to implement a very simple code using MPI.

program hello_world
include 'C:\Program Files (x86)\Microsoft SDKs\MPI\Include\mpif.h'
integer ierr
call MPI_INIT ( ierr )
write(*,*) 'Hello world'
call MPI_FINALIZE ( ierr )
pause
end program hello_world

After I have defined the library and have done lots of steps that I found in many blogs I have this error:

"Error 1 error LNK2019: unresolved external symbol MPI_INIT referenced in function MAIN__ hello_world.obj"

What is the reason for that and how to come over it?

1

There are 1 best solutions below

4
On

The fundamental problem is that the entry point in the library is MPI_Init but because Fortran is not case-sensitive, and it would seem that PGI Fortran on Windows upcases all the names, MPI_INIT doesn't match MPI_Init. (I assume you are building for x64 and are linking to the x64 libraries.)

I note that MS MPI includes an MPI.f90 file that declares a module MPI. But this doesn't deal with the case issue either.

If you were using Intel (not PGI) Visual Fortran, you could add the following lines after the INCLUDE:

!DEC$ ATTRIBUTES DECORATE, ALIAS:"MPI_Init" :: MPI_INIT
!DEC$ ATTRIBUTES DECORATE, ALIAS:"MPI_Finalize" :: MPI_FINALIZE

and see if that works. PGI may have something similar. Obviously you will need to add additional directives to rename other MPI routines you call.