Configuring Open MPI in Windows

This tutorial covers the setup of Open MPI and the compiling and running of MPI programs in the Microsoft Windows environment.

Open MPI and Windows

Open MPI is an implementation of the MPI standard. It is cross platform and makes use of your installed C++ or Fortran compiler. Getting everything working in a Linux environment is fairly easy provided gcc is installed. However when it comes to Windows there seems to be fairly few resources available on the internet that details the procedures to get everything up and running. After some playing around I eventual got everything working nicely.

My environment:

  • Windows 7 Ultimate x64
  • Open MPI 1.6.1 x64
  • Microsoft Visual Studio 2012 Professional x86 (only needed for cl.exe)

This tutorial does not make direct use of Visual Studio. Any version of Visual Studio should do, all we really need is the Microsoft C++ compiler and related tools that Open MPI uses.


Step 1: Installation

Download and install the latest version of Open MPI. Note that I downloaded the 64 bit version. I also changed the installation path to “Program Files” instead of the default “Program Files (x86)”. The Open MPI website states that this a temporary issue with their installer that should be fixed in time. If the installer asks to setup PATH variables then do so for all users. If the installer reports a failure when trying to do so, then don’t worry, we can do it manually as well.


Step 2: Open MPI PATH setup

For me the installer failed to setup any PATH variables, stating that my PATH was too long (not true). In this case we shall set it up manually. Simply add the bin directory of Open MPI to the global PATH variable. Thus in my case I added “C:\Program Files\OpenMPI_v1.6\bin” without the quotes to my PATH.


Step 3: cl.exe PATH setup

Open MPI for Windows is pre-configured to use the Microsoft C/C++ Compiler. It thus needs access to cl.exe, which controls the Microsoft Compiler and Linker. It is important here to add the correct directory to your PATH depending on the architecture (32 bit or 64 bit) of the Open MPI that you downloaded or else you will get linker errors. Since I downloaded the x64 version, I added the following directory to my global PATH: “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64” If you installed the x86 version of Open MPI then you can use the base bin directory (without the amd64 on the end).


Step 4: VCVARS

cl.exe won’t work out the box in any command prompt. It is required that the Visual Studio environmental variables are set up. The good news is that Microsoft provides bat files to do this for you. The bad news is that these settings are lost when you restart your computer. Thus here you have a choice, either simply run the bat file before you wish to compile MPI programs (not that much hassle since the bat file is in the same directory as cl.exe and thus in your PATH now), or you can add the file to your task scheduler to run at system startup. The name of the file is either vcvars32.bat or vcvars64.bat for x86 and x64 architectures respectfully. I just simply type vcvars64 into my command prompt before compiling the first time. At this point everything should be setup.


Compiling a simple MPI program:

I tested the setup with a simple program that has each process print out a greeting and exit. To compile: “mpic++ main.cpp” If everything is setup correctly then you should see output like this:

Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

"/LIBPATH:C:Program FilesOpenMPI_v1.6/lib"

Then to run the program with 10 processes: “mpirun -np 10 main.exe”

That’s it. Happy distributed programming.

36 thoughts on “Configuring Open MPI in Windows”




    1. I have added a simple openMPI hello world program in the downloads section. The expected output is included in the code.

      1. I Cant Find Any Program In This Post. Can You Send Me Mail On Above Given Mail Address.

        Kindly Reply On That Comment As Soon As Possible.

        I Also Want Some Other Programs.

          1. can i ask for path with windows 7 32 bit..i instal open mpi with 32 bit can i ask path cl.axe i don’t understand about “without the amd64 on the end” please tell me

  2. Here is a clarification for step3:
    64 bit installations:
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64
    32 bit installations:
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin

  3. can i ask if i shutdown my pc and my openmpi cannot be run..i don’t understand why this happen…but if i sleep openmpi is never error..i do this second format os..can you solve this problem..thanks before..

  4. In my case, I didnt found VCVARS32 or VCVARS64.bat,
    But i found a VCVARSALL.bat … will this work??? Reply plz…

    1. Make sure you in directory C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64 or C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin. VCVARSALL is generally in the C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC directory.

  5. setting configurasi successful running but i restart computer setting configuration have lost..and i cannot running program again… can you solve problem..

    1. As I have stated in the tutorial, it is required that you run vcvars or vcvars64 again after restarting.

          1. mpi run is stil not work..what have i doing now..run vcvars on cmd or i double click on windows?

  6. Hello Karl,

    Great tutorial! I’m having trouble running programs, though. I followed your instructions, installed open mpi 1.5.5 (x64), and am able to compile the following without errors:


    But when I run (mpirun -np 4 send_recv.exe) windows (8) tells me that “the program has stopped working”. The crash is occuring at the first call to mpi_send. Other programs I’ve run have been able to set up multiple processes, but again, mpi_send crashes. Any ideas? My goal is to run some MPI programs locally, by the way.

    1. Hi,

      I was able to execute the code you mentioned with no errors. Try updating to openMPI 1.6.1 at the least. I would normally recommend the latest version, but the Windows builds have been discontinued. So I think try with 1.6.1 and let me know.

  7. My global path is here:…;C:\Program Files\OpenMPI_v1.6.2-x64\bin;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include;C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
    and *.h files are in the include folder.
    But openmpi still gives
    “fatal error c1083: Cannot open include file: ‘stdio.h’ no such file or directory”
    error. How am I able to solve this problem? Thanks for helps.

      1. Code is here:
        /* C Example */

        int main (argc, argv)
        int argc;
        char *argv[];
        int rank, size;

        MPI_Init (&argc, &argv); /* starts MPI */
        MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
        MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */
        printf( “Hello world from process %d of %d\n”, rank, size );
        return 0;
        In internet there are some people having same problem. But none of them worked.

          1. Please paste your code in pastebin.com and give me the link as it is not showing correctly due to the angled brackets.

    1. I am using cygwin on windows7 and MPI and working , I set MPI Path but don’t about cl.exe path and unable to run MPI programs

  8. Hello Karl,

    thank you very much for this tutorial!
    I have a windows 8 computer trying to run fortran90 code including open mpi. I was doing fine until step 2, but on step 3 I have some trouble: My Microsoft Visual Studio seems to have no bin. Do I need to set up this path even though I am working with fortran or is it only necessary for C/C++?
    And how would you compile?
    I have tried like this: mpifort -o test test.f90
    but it tells me “‘mpifort’ is not recognized as an internal or external command”
    I would be very thankful for your help.

    1. The default executable name generated by the Microsoft c++ compiler is the same name as the source file. This can be changed, but will indeed depend on the compiler that you use.

  9. Hi again,

    I read it again and find the step

    To compile: “mpic++ main.cpp”

    Now when i try to compile i get errors

    error LNK2019: unresolved external symbol ___imp___MPI_ referenced in function _main


    MPI_Finalize, recv, send, ompi_mpi_int, MPI_Comm-size, MPI_Comm_rank, ompi_mpi_comm_wolrd and MPI_Init

    Can someone help me?

  10. Hi Karl,
    Very nice blog, thank you for the time and energy you put into it. I seem to have a problem with open mpi, I followed your instructions but here is my error output. Can you help, please? My goal is to set up a parallel environment to use the R statistical package. I’m on a windows 7 64 bit machine.
    Thank you so much.

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64>vcvars64

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64>mpic++ main.cpp

    Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
    Copyright (C) Microsoft Corporation. All rights reserved.

    c1xx : fatal error C1083: Cannot open source file: ‘main.cpp’: No such file or d

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64>cd\Program File

    C:\Program Files\OpenMPI_v1.6-x64>mpic++ main.cpp
    Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
    Copyright (C) Microsoft Corporation. All rights reserved.

    c1xx : fatal error C1083: Cannot open source file: ‘main.cpp’: No such file or d

    C:\Program Files\OpenMPI_v1.6-x64>

  11. Hi, very good tutorial. Can you please explain, how we can configure a cluster and run the MPI program within multiple nodes?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.