|
| 1 | +## Compile and run a sample MPI code on Windows |
| 2 | +1. Download MS-MPI SDK and Redist installers and install them. The download link to a stable realease is available from [this](https://github.com/microsoft/Microsoft-MPI/releases) page. |
| 3 | +2. After installation, you can verify that the MS-MPI environment variables have been set correctly (you will want to use these environment variables in Visual Studio) |
| 4 | + |
| 5 | +3. Open Visual Studio and create a Console App project. Let's name the project `MPIHelloWorld` |
| 6 | + * Instead of creating a project, you may open the provided `MPIHelloWorld.vcxproj` project file in Visual Studio and go to step 7. |
| 7 | +4. Use [this](MPIHelloWorld.cpp) code in the newly created project |
| 8 | +5. Setup the include directories so that the compiler can find the MS-MPI header files. Note that we will be building |
| 9 | +for 64 bits so we will point the include directory to `$(MSMPI_INC);$(MSMPI_INC)\x64`. If you will be building for 32 bits |
| 10 | +please use `$(MSMPI_INC);$(MSMPI_INC)\x86` |
| 11 | + |
| 12 | +6. Setup the linker options. Add `msmpi.lib` to the Additional Dependencies and also add `$(MSMPI_LIB64)` to the Additional |
| 13 | +Library Directories. Note that we will be building for 64 bits so we will point the Additional Library Directories to $(MSMPI_LIB64). |
| 14 | +If you will be building for 32 bits please use `$(MSMPI_LIB32)` |
| 15 | + |
| 16 | +7. Build the MPIHelloWorld project |
| 17 | + |
| 18 | +8. Test run the program on the command line |
| 19 | + |
| 20 | + |
| 21 | +Alternatively, you can use Developer Command Prompt for your version of Visual Studio to compile and link the `MPIHelloWorld.cpp` |
| 22 | +code (replacing steps 3-7 above). To build a 64-bit application, choose x64 Native Tools Command Prompt from the Visual Studio folder |
| 23 | +in the Start menu. |
| 24 | + |
| 25 | + |
| 26 | +To compile your program into an `.obj` file, go to the folder where `MPIHelloWorld.cpp` exists and run (you may ignore the warning message):<br> |
| 27 | +`cl /I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include" /c MPIHelloWorld.cpp` |
| 28 | + |
| 29 | + |
| 30 | +To create an executable file from the .obj file created in the previous step, run:<br> |
| 31 | +`link /machine:x64 /out:MPIHelloWorld.exe "msmpi.lib" /libpath:"C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64" MPIHelloWorld.obj` |
| 32 | + |
| 33 | + |
| 34 | +You may use the `nmake` command from Developer Command Prompt to compile and build the exmaple using the provided [`Makefile`](Makefile). |
0 commit comments