Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions RunningMSMPI.md
Original file line number Diff line number Diff line change
@@ -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:<br>
`mpiexec -c 1 -hosts 2 node1 node2 -wdir c:\Tests MPIHelloWorld.exe`<br>
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`)
21 changes: 21 additions & 0 deletions examples/helloworld/MPIHelloWorld.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// A simple MPI code printing a message by each MPI rank

#include <iostream>
#include <mpi.h>


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;
}
59 changes: 59 additions & 0 deletions examples/helloworld/MPIHelloWorld.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{A05D6B11-34C1-462A-AE8B-93D43A6B358D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MPIHelloWorld</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(MSMPI_INC);$(MSMPI_INC)\x64</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(MSMPI_LIB64)</AdditionalLibraryDirectories>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;msmpi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="MPIHelloWorld.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
19 changes: 19 additions & 0 deletions examples/helloworld/Makefile
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 34 additions & 0 deletions examples/helloworld/Run_MPIHelloWorld.md
Original file line number Diff line number Diff line change
@@ -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):<br>
`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:<br>
`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).
Binary file added examples/helloworld/screenshots/compile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/helloworld/screenshots/inc_dir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/helloworld/screenshots/lib_dir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/helloworld/screenshots/link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/helloworld/screenshots/mpiexec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/helloworld/screenshots/set_msmpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/helloworld/screenshots/vs_build.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/helloworld/screenshots/x64_prompt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.