Computational Science Community Wiki

RCS How-To: Compile, Link, Run and Debug FORTRAN MPI Programs Using Microsoft Visual Studio

Test-system(s) used: VMware virtual machine of WinXP x64 Pro, MS Visual Studio 2008 with Intel Visual Fortran 11.0.047 running mpich2

Installation

For the 64 bit test system, care has to be taken regarding compatibility of components one wishes to use together. Given only a 32 bit Visual Studio (VS) 2008 is available for free to Univ of Manchester researchers, a 32 bit version of mpich2 is used. We downloaded the 32 bit Windows binary from the mpich2 web site. (Using 64 bit mpich2 gives link time errors.)

Following the mpich2 for MS Windows instructions (see README.winbin.rtf) we add the relevant mpich2 include and library components to a VS project's build. For VS 2008 this is as follows; for other versions the actual locations vary. We presume you're aware of how to set parameters for your chosen build/project/configuration.

You should now be able to compile and link, or to build, a Fortran MPI program.

Launching MPI from Visual Studio

Rather than running the newly created executable, known to VS as $(TargetPath), we wish to launch mpiexec.exe and pass that the required mpich2 parameters and the executable. This can be achieved by

Then the MPI executable can be launched from VS by Debug - Start Without Debugging (Ctrl+F5). (Debug - Start Debugging (F5) also works but VS complains there's no debugging information for the mpiexec.exe itself)

NB if you try and use breakpoints etc it appears not to honour these - see below for how to debug.

Troubleshooting

These are just some of the problems you may see. For an exhaustive list please search the Internet.

You can now run your MPI program. If you see only one MPI process then you may not have launched the MPI processes correctly. You can check whether you program behaves as expecting by opening a terminal window (eg Start - Run - cmd) and then manually launching using {fullpath/}mpiexec.exe -n {num} {fullpath/}your.exe

If prompted for a username/password this will be the username/password used to authenticate to login to Windows. You can use mpiexec to register username/passwords. From a terminal window use mpiexec.exe -help2 for the full help on mpiexec.

If you get an error regarding inablity to connect it may due to MS Windows (or other) firewall settings. You may also occasionally need to start the mpich2 process manager (smpd.exe in the mpich2 bin directory) manually. As per Windows, a restart may help.

The VS Output window may occasionally show "First-chance exception at 0x7d4e237e in mpiexec.exe: 0x000006C5: The tag is invalid." but it appears these can be ignored.

Debugging Fortran MPI Using Visual Studio

by attaching to a currently running process (one VS window for all selected MPI processes)

This is a generic method and gives you one VS debugging window but you can move between MPI processes

launching VS from mpiexec (one VS window per MPI process)

Firstly, having compiled and linked (or built) your executable (project), close all VS application windows. From a terminal window

Open another terminal window we can now launch the VS executable on each MPI process with the following command (this is one command and shouldn't be split over lines but your browser may reformat):

"c:\Program Files (x86)\MPICH2\bin\mpiexec.exe" -n 2 "c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"  "c:\Program Files (x86)\MPICH2\examples\Debug\fpi.exe"

where you should use the path to your mpiexec.exe and to your VS executable (devenv.exe} and to the required executable (or Fortran file or project) This will give you two (or NUM if you use -n NUM) VS applications, one for each thread. You can then debug as normal - you will have to manually start each debugging thread and you may have to "Break All" to bring up the source code for adding break and watch points.

More Information

The above was compiled by trial, error and help from the mpich2 team.

For further help and discussion