Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29041 Discussions

How to compile MPI code in Visual Fortran

creepa1982
Beginner
1,927 Views
Hey,

I am trying to compile the following code in Visual Fortran (compiler version 11.0.066):

program simple
include 'mpif.h'
integer numtasks, rank, ierr, rc

call MPI_INIT(ierr)
if (ierr .ne. MPI_SUCCESS) then
print *,'Error starting MPI program. Terminating.'
call MPI_ABORT(MPI_COMM_WORLD, rc, ierr)
end if

call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, numtasks, ierr)
print *, 'Number of tasks=',numtasks,' My rank=',rank

! ****** do some work ******

call MPI_FINALIZE(ierr)

end

I get the error: Error 1 fatal error LNK1107: invalid or corrupt file: cannot read at 0x416B C:\Program Files\Intel\MPI\3.2.1.009\ia32\include\mpif.h 1

As mentioned in another thread I have added "additional libraries" under linker options: C:\Program Files\Intel\MPI\3.2.1.009\ia32\include plus mpif.h under Input-> additional dependencies.

Do I need to change the compiler to mpif90.bat? If so, how is this done in Visual Studio.

Thank you very much,

Benjamin
0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,928 Views

Do not put the .h file under "Additional Dependencies" in the linker property - that is the cause of the error. The folder containing that file should go under "Additional INCLUDE Directories" in the Fortran properties.
0 Kudos
creepa1982
Beginner
1,928 Views

Do not put the .h file under "Additional Dependencies" in the linker property - that is the cause of the error. The folder containing that file should go under "Additional INCLUDE Directories" in the Fortran properties.
I took out mpif.h from the linker settings. This resolved the above error, but now I get a new one:
Error 3 error LNK2019: unresolved external symbol _MPI_COMM_RANK referenced in function _MAIN__ main.obj
(All other MPI commands cannot be found either)

I have included the path C:Program FilesIntelMPI3.2.1.009ia32include as additional compiler and linker paths but still receive this error. Both files, mpif.h and mpi.h (this one has the mpi commands i need) are in the path.

Any ideas what is going wrong here?

Thanks ,

Benjamin
0 Kudos
Steven_L_Intel1
Employee
1,928 Views
It is not sufficient to list the library folder - you will need to add the name of the library. You can put this under "Additional Dependencies" in the Linker property page. I do not know, offhand, what the right library name is to use. Read the Intel MPI documentation to see which libraries are to be used. There may be more than one.
0 Kudos
TimP
Honored Contributor III
1,928 Views
It is not sufficient to list the library folder - you will need to add the name of the library. You can put this under "Additional Dependencies" in the Linker property page. I do not know, offhand, what the right library name is to use. Read the Intel MPI documentation to see which libraries are to be used. There may be more than one.
The mpiifort script could be used (in place of ifort) in the ifort command line window to find out which MPI libraries are linked. With the additional option -# these details are displayed.
0 Kudos
creepa1982
Beginner
1,928 Views
Quoting - tim18
The mpiifort script could be used (in place of ifort) in the ifort command line window to find out which MPI libraries are linked. With the additional option -# these details are displayed.
Thanks Tim, mpiifort was a very good hint. I found that the additional dependecy needed to complete the linking was: "impi.lib". The additional library directory in my case is: C:Program FilesIntelMPI3.2.1.009ia32lib. Works great.

Now to allow for multiple threads it is necessary to start the executable with mpiexec.exe instead of ifort.exe. Luckily I found a C++ tutorial for integrating MPI into Visual Studio (http://supercomputingblog.com/mpi/getting-started-with-mpi-using-visual-studio-2008-express/). To make it short, adding C:Program FilesIntelMPI3.2.1.009ia32binmpiexec.exe as command in debugging under properties and -n 2 $(TargetPath) under command arguments enables the use of two cores. Works perfectly!

The last thing remaining is to enable the debugger. I could not find information on this in the reference manual (except for I_MPI_DEBUG). Does anyone know if there is a way to get debugging to work for MPI code within Visual Studio?

Thanks,
Benjamin
0 Kudos
Vitaliy_R_2
Beginner
1,928 Views

Have read all above and still have a question:
HOW TO LINK mpif.h to the iFORTRAN (11)project in VISUAL STUDIO 2008, because no fluent answer was given.
Please, who have successfully made it, describe the procedure step-by-step.
Thanks.

0 Kudos
TimP
Honored Contributor III
1,928 Views
You don't link against header files. You add their folder to the include path, and set the fpp preprocessing option. The MPI compiler wrappers, such as mpif90, mpiifort,... take care of this, as well as linking the corresponding libraries, for you, when you use command line.
0 Kudos
Reply