Sunday, February 26, 2012

Using MPICH on Windows 7 with MS Visual Studio 2010

Installing MPICH2
  • Download 32-bit or 64-bit MPICH installer (if you have Visual Studio 32-bit, you MUST use the 32-bit MPICH) from http://www.mcs.anl.gov/research/projects/mpich2/downloads/index.php?s=downloads
  • Open the start menu
  • Type "cmd"; this will bring up cmd.exe in the search results
  • Right-click on the cmd.exe icon and click "Run as admistrator"
  • Change directories to the location of the .msi file you just downloaded
  • Execute the .msi file by entering it's name on the command prompt.
  • You may be prompted with a security messgae from windows, continue
  • Make sure to remember the "authentication passphrase for smpd".  You must have this to run a program with mpich.

NOTE: If you have problems with installing MPICH2 or running it, you may need to lower the "User Account Control" settings on Windows 7.  You can do so by doing the following:
  1.  Open the Start Menu
  2. Type "User Account Control"
  3. Choose "Change User Account Control Settings" from the search results.
  4. You can lower the slider to the bottom to reduce the security level of Windows 7.
  5. Install MPICH
  6. Reset the security level back to what it was before.

Setting up Execution Service
After installing MPICH, check that the smpd.exe service is installed properly (this DOES NOT happen by default): check to see if there is a windows service called "MPICH2 Process Manager, Argonne National Lab".  If it is not, do the following to install it (assumes 32-bit, remove (x86) for 64-bit):
  • Open a command prompt
  • Change directories to C:\Program Files (x86)\MPICH2\bin
  • run "smpd -install"; the output will be: "MPICH2 Process Manager, Argonne National Lab installed."

Setting up Visual Studio
First, make sure that your Visual Studio version and MPICH version are using the same architecture.  That is, if you have VS 2010 32-bit (the default student edition), you MUST have the 32-bit MPICH installed.  You can check this by the MPICH installation directory.  If MPICH is installed in C:\Program Files (x86), then you're using the 32-bit version; whereas, if it's installed in C:\Program Files, you're using the 64-bit version.

Once you're ready to code, setup the Visual Studio Project to use MPICH:
  1. Right click on the solution in the "Solution Explorer" window; choose properties (figure 1).
  2. Under "Configuration Properties", choose "VC++ Directories".
  3. Highlight the "Include Directories" row at the right.
  4. Click the down arrow at the far right of the highlighted row.
  5. Click "Edit<...>"
  6. Click the "New Line" icon (a folder with a start on it) at the top of the "Include Directories" dialog box.
  7. Click the "..." button.
  8. Add the MPICH include file location; for a 32-bit build, this is C:\Program Files (x86)\MPICH2\include, for a 64-bit build, this is C:\Program Files\MPICH2\include
  9. Click "Select Folder".  Click "OK".
  10. Highlight the "Library Directories" row.
  11. Repeat steps 4 through 9 for the library directory of MPICH: C:\Program Files (x86)\MPICH2\lib or C:\Program Files\MPICH2\lib
  12. Under "C/C++", choose "General".
  13. Highlight "Additional Include Directories".
  14. Repeat steps 4 through 9 for the include directory of MPICH: C:\Program Files (x86)\MPICH2\include or C:\Program Files\MPICH2\include
  15. Under "Linker", choose "General".
  16. Highlight "Additional Library Directories".
  17. Repeat steps 4 through 9 for the libary directory of MPICH.
  18. Under "Input", choose "Input".
  19. Highlight "Additional Dependencies".
  20. Click the down arrow at the far right of the highlighted row.
  21. Click "Edit<...>"
  22. Add "cxx.lib" and "mpi.lib" (don't include the quotes).
  23. Click "OK".
  24. Click "OK" in the " Property Pages" window.

Figure 1: The Project Properties

Setting up the MPICH execution Environment
  1. Open a command prompt
  2. Execute "mpiexec -register" (enter your windows password for the password)
  3. Validate the user by running "mpiexec -validate -user <username>"

Running an MPI program with MPICH
  • Add the MPICH bin directory, C:\Program Files (x86)\MPICH2\bin, to your path
  • Find the .exe file created by VS 2010.  I had to manually set the location of the .exe file in the "Output" section's "General" tab in the properties of the solution.
  • If you have trouble, use the cpi.exe example (this is the first code example in the Using MPI book):


NOTE: I was unable to get more than 1 process running.  I've emailed the MPICH discussion list to see if anybody knows what's wrong.

5 comments:

  1. Thanks Nick! Very helpful install guide. A few other helpful tips :

    1. Add ...\MPICH2\bin to your user PATH. This way you can use mpiexec from any directory in your system. Doing this will mean you do not have to output your code binaries to the ...\MPICH2\bin folder every time you create a new project in VS.

    2. If you want the mpi manager to remember your user credentials you can use :
    mpiexec -register -user [number]

    leave the account field empty (if you are doing this for yourself) and type in your windows password to create user credential [number]. You can then execute an mpi job with :
    mpiexec -user [number] -n [num_nodes] [exe_loc]

    and will not have to re-enter your credentials in every time you launch a new process.

    -Anshul

    ReplyDelete
  2. Dear Sir,

    I Have Try Above Said Steps To Run Mpich Programs. While I Compile It, It Compile Successfully. But While I Debugg That Program For Generatting .exe File For That Program I Got An Error, Which Is As:
    LINK : fatal error LNK1104: cannot open file '..\..\..\..\..\..\..\Program Files\MPICH2\bin\OpenMPI_Practical.exe'

    So Can You Guve Me Solution For That Error.

    Kindly Reply With Solution

    ReplyDelete
  3. Hi, nice method of Installation using MPICH on Windows 7 with MS Visual Studio 2010.Thanks,its extremely helped me....

    -Aparna
    Theosoft

    ReplyDelete
  4. can anybody help me? whenever i try to do validation part, and it prompted me to key in the passphrase for smpd, i get the following error:
    Please specify an authentication passphrase for smpd:
    Error while connecting to host, No connection could be made because the target m
    achine actively refused it. (10061)

    I'm pretty sure that i've entered the correct passphrase.

    ReplyDelete
  5. Thank you so much! I needed this for my college and it works perfectly. I have managed to get multiple processes working at once. I just followed the walkthrough on a freshly formatted computer and it works as it should.

    ReplyDelete