Many a curriculum requires you to perform MPI development as part of the Parallel Computing course.
This article will walk you through setting up WSL(Windows Subsystem For Linux) and Visual Studio Code for MPI Development, running under the Ubuntu WSL Distro from the Microsoft Store
Setting up WSL
On recent releases of Windows, WSL is enabled by default and all you need to do is install a distribution under it
We’ll begin by downloading the Ubuntu Distribution from the Microsoft Store. Open the store from the start menu and search for Ubuntu 18.04 or click here
after it’s done installing, open it, and follow all the prompts to enter your default username and password, et cetera.
Installing OpenMPI and Build Tools for OpenMPI
You should now be looking at a command line window, running bash, with the ubuntu logo as the app icon in the taskbar. If you see this, that means you’ve successfully installed the ubuntu distro under WSL
Now type in the following command to install OpenMPI. In the case of the below screenshot, it’s already been installed.
sudo apt update && sudo apt install openmpi-bin libopenmpi-dev
After this, you will immediately be able to use mpicc and mpirun to run MPI programs, but you’ll soon see this message
This is due to one of the parameters that WSL is configured by default with. To solve this, we need to run this command
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
After this the warning will simply disappear.
If you just want to execute programs on the terminal and not set up Visual Studio Code, you can now do so by using mpicc and mpirun.
Otherwise, keep reading to find out how to set up VSCode for the task.
Setting up VSCode
We’re assuming that you already have VSCode Installed, if not, grab it from their website.
We’ll need to install the WSL Remote from it’s Visual Studio Extensions page, after that, click on the new icon on the bottom left to launch a new WSL session
After that, it’ll ask you to choose a directory you want to open. Go ahead and open the directory that you plan to perform your development in.
To enable syntax highlighting, intellisense and other language aware features, we need to set up the C/C++ Support in VSCode as well. For that, go to the extensions pane and install it
Now, by default, VSCode is not going to be able to find mpi.h, which is essential to be able to provide suggestions for MPI Interfaces, for that we’ll need to configure the includePath and the executable path in the C/C++ Settings. Create a file named c_ccp_properties.json in the .vscode folder in your MPI Program directory and paste in this configuration
Auto Build And Run (Optional)
In addition to this, if you want to be able to Build and Run directly from VSCode, we need to add the following build and launch tasks
With that set up, you should be able to use your default keyboard shortcuts for Run without Debug(Ctrl+F5) and Build (Ctrl+Shift+B) to Build and Run your MPI Programs.
Do clap if you found this article helpful!