Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
21 changes: 21 additions & 0 deletions example/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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to move this into examples/helloworld? That way, we can include more examples as needed.

@hpourreza Hossein Pourreza (hpourreza) Sep 19, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created the helloworld folder under example to host the code and readme file.

19 changes: 19 additions & 0 deletions example/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)
35 changes: 35 additions & 0 deletions example/Run_MPIHelloWorld.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Compile and run a sample MPI code on Windows
1. Download MS-MPI SDK and Redist installers and install them. The download link can be found on
our [homepage](https://docs.microsoft.com/en-us/message-passing-interface/microsoft-mpi)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to point it to the releases tab in github.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the link to point to the releases page of Github

2. After installation, you can verify that the MS-MPI environment variables have been set (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`
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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A vcproject file may be useful instead.

@AnnaDaly Anna Daly (AnnaDaly) Sep 18, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that we need $(MSMPI_INC)\x64 or $(MSMPI_INC)\x86 in includes, $(MSMPI_INC) should be enough for simple C++ example..

UPD: as long as it is in sync with https://blogs.technet.microsoft.com/windowshpc/2015/02/02/how-to-compile-and-run-a-simple-ms-mpi-program/

:)

@hpourreza Hossein Pourreza (hpourreza) Sep 19, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A vcproject file may be useful instead.

Jithin Jose (@jithinjosepkl) what do you mean? I included a vcxproj file. Should I create it in some special way?

Anna Daly (@AnnaDaly)
I used most of that blog post for this Readme. This readme is going to replace that blog post since some of references in that blog post is no longer valid.

Binary file added example/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 example/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 example/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 example/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 example/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 example/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 example/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 example/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.