Skip to content

Commit c8daf40

Browse files
Merge pull request microsoft#20 from hpourreza/master
An example and a readme file
2 parents c38ad83 + f0af52a commit c8daf40

File tree

13 files changed

+130
-0
lines changed

13 files changed

+130
-0
lines changed

docs/RunningMSMPI.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The `mpiexec` program from MSMPI can be used to launch applications on multiple nodes. There are two ways to launch applications
2+
on multiple nodes:
3+
1. Using MS-MPI Launch Service:
4+
* Start MS-MPI Launch Service on all the compute nodes
5+
* Specify your compute nodes in the `mpiexec` command line (either using `hosts` or `hostfile`), for example:<br>
6+
`mpiexec -c 1 -hosts 2 node1 node2 -wdir c:\Tests MPIHelloWorld.exe`<br>
7+
The above command runs the `MPIHelloWorld.exe` program on two hosts (`node1` and `node2`) using one core from each node
8+
2. Using `spmd`:
9+
* Run `spmd -d` on all compute nodes
10+
* The `spmd.exe` program is availble after installation of MSMPI (in the folder pointed by the `MSMPI_BIN` variable)
11+
* Specify your compute nodes in the `mpiexec` command line (either using `hosts` or `hostfile`)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// A simple MPI code printing a message by each MPI rank
2+
3+
#include <iostream>
4+
#include <mpi.h>
5+
6+
7+
int main()
8+
{
9+
int my_rank;
10+
int world_size;
11+
12+
MPI_Init(NULL, NULL);
13+
14+
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
15+
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
16+
17+
std::cout << "Hello World from process " << my_rank << " out of " << world_size << " processes!!!" << std::endl;
18+
19+
MPI_Finalize();
20+
return 0;
21+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
4+
<ItemGroup Label="ProjectConfigurations">
5+
<ProjectConfiguration Include="Debug|x64">
6+
<Configuration>Debug</Configuration>
7+
<Platform>x64</Platform>
8+
</ProjectConfiguration>
9+
</ItemGroup>
10+
11+
<PropertyGroup Label="Globals">
12+
<VCProjectVersion>16.0</VCProjectVersion>
13+
<ProjectGuid>{A05D6B11-34C1-462A-AE8B-93D43A6B358D}</ProjectGuid>
14+
<RootNamespace>MPIHelloWorld</RootNamespace>
15+
</PropertyGroup>
16+
17+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
18+
19+
<PropertyGroup Label="Configuration">
20+
<ConfigurationType>Application</ConfigurationType>
21+
<UseDebugLibraries>false</UseDebugLibraries>
22+
<PlatformToolset>v142</PlatformToolset>
23+
<CharacterSet>Unicode</CharacterSet>
24+
</PropertyGroup>
25+
26+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
27+
28+
29+
<ItemDefinitionGroup>
30+
<ClCompile>
31+
<AdditionalIncludeDirectories>$(MSMPI_INC);$(MSMPI_INC)\x64</AdditionalIncludeDirectories>
32+
</ClCompile>
33+
34+
<Link>
35+
<SubSystem>Console</SubSystem>
36+
<AdditionalLibraryDirectories>$(MSMPI_LIB64)</AdditionalLibraryDirectories>
37+
<AdditionalDependencies>msmpi.lib;%(AdditionalDependencies)</AdditionalDependencies>
38+
</Link>
39+
</ItemDefinitionGroup>
40+
41+
<ItemGroup>
42+
<ClCompile Include="MPIHelloWorld.cpp" />
43+
</ItemGroup>
44+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
45+
</Project>

examples/helloworld/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ld=link
2+
cc=cl
3+
4+
cflags=/I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include"
5+
ldflags=/libpath:"C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64"
6+
7+
libs=msmpi.lib
8+
9+
output=affinity.exe
10+
objs=affinity.obj
11+
12+
all: $(objs)
13+
$(ld) $(libs) $(ldflags) -out:$(output) $(objs)
14+
15+
.cpp.obj:
16+
$(cc) $(cflags) /c $*.cpp
17+
clean:
18+
@del /Q $(objs)
19+
@del /Q $(output)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
![inline](./screenshots/set_msmpi.png)
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+
![inline](./screenshots/inc_dir.png)
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+
![inline](./screenshots/lib_dir.png)
16+
7. Build the MPIHelloWorld project
17+
![inline](./screenshots/vs_build.png)
18+
8. Test run the program on the command line
19+
![inline](./screenshots/mpiexec.png)
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+
![inline](./screenshots/x64_prompt.png)
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+
![inline](./screenshots/compile.png)
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+
![inline](./screenshots/link.png)
33+
34+
You may use the `nmake` command from Developer Command Prompt to compile and build the exmaple using the provided [`Makefile`](Makefile).
34.9 KB
Loading
35.6 KB
Loading
38.5 KB
Loading
14 KB
Loading
12.1 KB
Loading

0 commit comments

Comments
 (0)