diff --git a/docs/RunningMSMPI.md b/docs/RunningMSMPI.md new file mode 100644 index 0000000..db3d159 --- /dev/null +++ b/docs/RunningMSMPI.md @@ -0,0 +1,11 @@ +The `mpiexec` program from MSMPI can be used to launch applications on multiple nodes. There are two ways to launch applications +on multiple nodes: +1. Using MS-MPI Launch Service: + * Start MS-MPI Launch Service on all the compute nodes + * Specify your compute nodes in the `mpiexec` command line (either using `hosts` or `hostfile`), for example:
+ `mpiexec -c 1 -hosts 2 node1 node2 -wdir c:\Tests MPIHelloWorld.exe`
+ The above command runs the `MPIHelloWorld.exe` program on two hosts (`node1` and `node2`) using one core from each node +2. Using `spmd`: + * Run `spmd -d` on all compute nodes + * The `spmd.exe` program is availble after installation of MSMPI (in the folder pointed by the `MSMPI_BIN` variable) + * Specify your compute nodes in the `mpiexec` command line (either using `hosts` or `hostfile`) diff --git a/examples/helloworld/MPIHelloWorld.cpp b/examples/helloworld/MPIHelloWorld.cpp new file mode 100644 index 0000000..4547b36 --- /dev/null +++ b/examples/helloworld/MPIHelloWorld.cpp @@ -0,0 +1,21 @@ +// A simple MPI code printing a message by each MPI rank + +#include +#include + + +int main() +{ + int my_rank; + int world_size; + + MPI_Init(NULL, NULL); + + MPI_Comm_size(MPI_COMM_WORLD, &world_size); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + + std::cout << "Hello World from process " << my_rank << " out of " << world_size << " processes!!!" << std::endl; + + MPI_Finalize(); + return 0; +} diff --git a/examples/helloworld/MPIHelloWorld.vcxproj b/examples/helloworld/MPIHelloWorld.vcxproj new file mode 100644 index 0000000..72f29e6 --- /dev/null +++ b/examples/helloworld/MPIHelloWorld.vcxproj @@ -0,0 +1,45 @@ + + + + + + Debug + x64 + + + + + 16.0 + {A05D6B11-34C1-462A-AE8B-93D43A6B358D} + MPIHelloWorld + + + + + + Application + false + v142 + Unicode + + + + + + + + $(MSMPI_INC);$(MSMPI_INC)\x64 + + + + Console + $(MSMPI_LIB64) + msmpi.lib;%(AdditionalDependencies) + + + + + + + + diff --git a/examples/helloworld/Makefile b/examples/helloworld/Makefile new file mode 100644 index 0000000..429b438 --- /dev/null +++ b/examples/helloworld/Makefile @@ -0,0 +1,19 @@ +ld=link +cc=cl + +cflags=/I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include" +ldflags=/libpath:"C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64" + +libs=msmpi.lib + +output=affinity.exe +objs=affinity.obj + +all: $(objs) + $(ld) $(libs) $(ldflags) -out:$(output) $(objs) + +.cpp.obj: + $(cc) $(cflags) /c $*.cpp +clean: + @del /Q $(objs) + @del /Q $(output) diff --git a/examples/helloworld/Run_MPIHelloWorld.md b/examples/helloworld/Run_MPIHelloWorld.md new file mode 100644 index 0000000..5b2c84c --- /dev/null +++ b/examples/helloworld/Run_MPIHelloWorld.md @@ -0,0 +1,34 @@ +## Compile and run a sample MPI code on Windows +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. +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) +![inline](./screenshots/set_msmpi.png) +3. Open Visual Studio and create a Console App project. Let's name the project `MPIHelloWorld` + * Instead of creating a project, you may open the provided `MPIHelloWorld.vcxproj` project file in Visual Studio and go to step 7. +4. Use [this](MPIHelloWorld.cpp) code in the newly created project +5. Setup the include directories so that the compiler can find the MS-MPI header files. Note that we will be building +for 64 bits so we will point the include directory to `$(MSMPI_INC);$(MSMPI_INC)\x64`. If you will be building for 32 bits +please use `$(MSMPI_INC);$(MSMPI_INC)\x86` +![inline](./screenshots/inc_dir.png) +6. Setup the linker options. Add `msmpi.lib` to the Additional Dependencies and also add `$(MSMPI_LIB64)` to the Additional +Library Directories. Note that we will be building for 64 bits so we will point the Additional Library Directories to $(MSMPI_LIB64). +If you will be building for 32 bits please use `$(MSMPI_LIB32)` +![inline](./screenshots/lib_dir.png) +7. Build the MPIHelloWorld project +![inline](./screenshots/vs_build.png) +8. Test run the program on the command line +![inline](./screenshots/mpiexec.png) + +Alternatively, you can use Developer Command Prompt for your version of Visual Studio to compile and link the `MPIHelloWorld.cpp` +code (replacing steps 3-7 above). To build a 64-bit application, choose x64 Native Tools Command Prompt from the Visual Studio folder +in the Start menu. +![inline](./screenshots/x64_prompt.png) + +To compile your program into an `.obj` file, go to the folder where `MPIHelloWorld.cpp` exists and run (you may ignore the warning message):
+`cl /I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include" /c MPIHelloWorld.cpp` +![inline](./screenshots/compile.png) + +To create an executable file from the .obj file created in the previous step, run:
+`link /machine:x64 /out:MPIHelloWorld.exe "msmpi.lib" /libpath:"C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64" MPIHelloWorld.obj` +![inline](./screenshots/link.png) + +You may use the `nmake` command from Developer Command Prompt to compile and build the exmaple using the provided [`Makefile`](Makefile). diff --git a/examples/helloworld/screenshots/compile.png b/examples/helloworld/screenshots/compile.png new file mode 100755 index 0000000..8d75c66 Binary files /dev/null and b/examples/helloworld/screenshots/compile.png differ diff --git a/examples/helloworld/screenshots/inc_dir.png b/examples/helloworld/screenshots/inc_dir.png new file mode 100755 index 0000000..f3c63c6 Binary files /dev/null and b/examples/helloworld/screenshots/inc_dir.png differ diff --git a/examples/helloworld/screenshots/lib_dir.png b/examples/helloworld/screenshots/lib_dir.png new file mode 100755 index 0000000..ba34178 Binary files /dev/null and b/examples/helloworld/screenshots/lib_dir.png differ diff --git a/examples/helloworld/screenshots/link.png b/examples/helloworld/screenshots/link.png new file mode 100755 index 0000000..ea7a1bf Binary files /dev/null and b/examples/helloworld/screenshots/link.png differ diff --git a/examples/helloworld/screenshots/mpiexec.png b/examples/helloworld/screenshots/mpiexec.png new file mode 100755 index 0000000..a2a1364 Binary files /dev/null and b/examples/helloworld/screenshots/mpiexec.png differ diff --git a/examples/helloworld/screenshots/set_msmpi.png b/examples/helloworld/screenshots/set_msmpi.png new file mode 100755 index 0000000..004b7a1 Binary files /dev/null and b/examples/helloworld/screenshots/set_msmpi.png differ diff --git a/examples/helloworld/screenshots/vs_build.png b/examples/helloworld/screenshots/vs_build.png new file mode 100755 index 0000000..f15c844 Binary files /dev/null and b/examples/helloworld/screenshots/vs_build.png differ diff --git a/examples/helloworld/screenshots/x64_prompt.png b/examples/helloworld/screenshots/x64_prompt.png new file mode 100755 index 0000000..2624deb Binary files /dev/null and b/examples/helloworld/screenshots/x64_prompt.png differ