Repository navigation
An example and a readme file #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
cc2cc15
6eb1508
e5b1595
96aa739
48d1af2
16a20fb
54c6050
2900e95
28720ef
ab87c25
025240f
14f7aff
6b10a30
9c56823
6240bdb
1fa3987
1fc25d2
12706bf
eee24ab
f0af52a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } | ||
| 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) |
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|  | ||
| 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` | ||
|  | ||
| 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)` | ||
|  | ||
| 7. Build the MPIHelloWorld project | ||
|  | ||
| 8. Test run the program on the command line | ||
|  | ||
|
|
||
| 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. | ||
|  | ||
|
|
||
| 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` | ||
|  | ||
|
|
||
| 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` | ||
|  | ||
|
|
||
| You may use the `nmake` command from Developer Command Prompt to compile and build the exmaple using the provided [`Makefile`](Makefile). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A vcproject file may be useful instead.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure that we need 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/ :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Jithin Jose (@jithinjosepkl) what do you mean? I included a Anna Daly (@AnnaDaly) |
||
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created the
helloworldfolder underexampleto host the code and readme file.