Configuring MPI on Windows 10 and Executing the Hello World Program in Visual Studio Code 2019

Nickson Joram
May 4 · 4 min read

The Message Passing Interface (MPI) is a portable and standardized message-passing standard intended to function on parallel computing architectures. The MPI system requires the syntax and semantics of library routines that can be used by a broad variety of users who are writing portable message-passing programs in C, C++, and Fortran. There are many open-source MPI implementations, which have aided in the development of the parallel software industry and the development of portable and scalable large-scale parallel applications.

Photo by Tadas Sar on Unsplash

In this article, we are going to set up MPI in a Windows 10 machine.

  1. Download and install Visual Studio 2019

You can find the latest Visual Studio 2019 here. Choose the Community version as it is free and that is enough for this.

2. Choose the “Desktop development with C++” workload

Image from https://docs.microsoft.com/en-us/cpp/build/vscpp-step-0-installation?view=msvc-160

3. Download MS-MPI SDK and Redist installers (msmpisetup.exe and msmpisdk.msi) and install them.

You can get them here. You can verify your installation as follows.

Image by Author

If you get any error, set the Environment and restart your machine and execute it again.

4. Open Visual Studio 2019 and create a new Empty Project (Console App). Let’s name it as you wish, I’m naming it as MPI with other default settings

Image by Author

5. Click on the project name (i.e., MPI) in the solution explorer, and add a new C++ Source File (Project -> Add New Item -> C++ File)

Image by Author
Image by Author

6. Use the following code

#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the rank of the process
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
// Print the message
printf("Hello World! My rank is %d\n", my_rank);
// Finalize the MPI environment.
MPI_Finalize();
}

It will show some errors. You may not have configured the MPI for the particular project. Let’s do that first before we compile it.

7. Open the “Property Pages” (Project -> Properties). Add the following in the area.

If you will be building for x64:

If you will be building for x86:

Image by Author

Press Apply.

8. Setup the linker library by adding to the

Image by Author

Remember, you’ve to add after the to separate other dependencies from newly included dependency.

9. Add the following to the .

If you will be building for x64:

If you will be building for x86:

Image by Author

10. Now, Build the solution (Build -> Build Solution).

Image by Author

You will receive a success message like this.

1>------ Build started: Project: MPI, Configuration: Debug Win32 ------1>HelloWorld.cpp1>MPI.vcxproj -> C:\Users\A Nickson Joram\source\repos\MPI\Debug\MPI.exe========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

If you get any linking error messages, it is most likely you’re building for 64 bits yet specifying 32 bits linking libraries.

11. To test the program or to execute the program, go to the directory and execute the following commands.

mpiexec –n <number of processing elements> ./<executable file>
Image by Author

That’s it! It is done. Let’s analyze the code in another article.

Hope the article can help. Share your thoughts too.

Geek Culture

Proud to geek out. Follow to join our +500K monthly readers.

Nickson Joram

Written by

Computer Science Undergrad | Java Lover | Passionate about Software Engineering, Parallel Computing, AI, and Robotics | Learner | Tech Enthusiast | Being human

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Nickson Joram

Written by

Computer Science Undergrad | Java Lover | Passionate about Software Engineering, Parallel Computing, AI, and Robotics | Learner | Tech Enthusiast | Being human

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store