Introduction to Parallel Programming with MPI: Setup

Compilers and MPI

In order to follow this workshop, you will need access to compilers and MPI libraries. You can either use a cluster or set things up on your own laptop, and instructions for both are provided below.

(Optional, not covered in online workshops) One part of the workshop deals with profiling parallel code using ARM Forge, and access to a SNIC cluster is required for the exercises in this part. It is convenient to install a local client to interact with the profiler running on the cluster, and instructions for setting this up are given below.

On your laptop

These instructions are based on installing compilers and MPI via the conda package manager, as it provides a convenient way to install binary packages in an isolated software environment.

Installing conda

Begin by installing Miniconda:

  1. Download the 64-bit installer from here for your operating system
    • for MacOS and Linux, choose the bash installer
    • on Windows, open a Linux-WSL terminal and type: wget If wget is not a recognised command, type sudo apt-get install wget and provide the password you chose when installing WSL.
  2. In a terminal, run the installer with bash Miniconda3-latest-<operating-system> (replace with correct name of installer)
  3. Agree to the terms of conditions, specify the installation directory (the default is usually fine), and answer “yes” to the questions “Do you wish the installer to initialize Miniconda3 by running conda init?”

You now have miniconda and conda installed. Make sure that it works by typing which conda and see that it points to where you installed miniconda (you may have to open a new terminal first).

We recommend that you create an isolated conda environment (this is good practice in software development):

conda create --name mpi-intro python=3.7
conda activate mpi-intro


If you want to use Python for the exercises, you will need to install mpi4py. mpi4py can be installed either using pip or conda, but with pip you will need to install MPI yourself first (e.g. OpenMPI or MPICH), while conda will install its own MPI libraries. If you don’t already have MPI installed on your laptop, it will be easiest to use conda:

(mpi-intro) $ conda install -c conda-forge mpi4py

Please also verify the installation. The following command should not give an error message:

(mpi-intro) $ python -c "from mpi4py import MPI"

and the following command should give a version number:

(mpi-intro) $ mpirun --version

C/C++ and Fortran

If you want to use C, C++ or Fortran for the exercises, you will need to install compilers and MPI libraries if you don’t already have them available. This can also be done using conda:

(mpi-intro) $ conda install -c conda-forge compilers
(mpi-intro) $ conda install -c conda-forge mpich

Please also verify the installation. The following commands should give version numbers:

(mpi-intro) $ mpicc --version
(mpi-intro) $ mpifort --version
(mpi-intro) $ mpirun --version

On a PDC cluster

To do the exercises at PDC, you will need:

Below you will find instructions for how to use the Tegner cluster for either Python or C/C++/Fortran MPI applications.


Python is available through the Anaconda distribution at PDC. To use mpi4py on Tegner, you need to load an Anaconda module and then switch to a specific conda environment:

module load anaconda/py37/5.0.1
source activate mpi4py

Loading the Anaconda module will also load the modules gcc/8.2.0 and openmpi/4.0-gcc-8.2, so you will be able to run Python code with:

mpirun -n 24 python

C/C++ and Fortran

We suggest that you use the gcc compiler together with OpenMPI libraries:

module load gcc/8.2.0
module load openmpi/4.0-gcc-8.2

You will then be able to compile and run MPI code with:

mpicc -o example example.c      
mpifort -o example example.f90  

mpirun -n 12 ./example

(not in online workshops) ARM Forge

The ARM Forge tools (Performance Reports, MAP and DDT) are installed on PDC clusters. These are graphical applications, and running them over an ssh connection can become sluggish or unstable. We therefore recommend to install the ARM Forge Remote Client, which runs on your local computer and can be used to connect to running processes on the cluster.

Begin by downloading the Remote Client, and installing it. Next you need to set up the connection to PDC:

If connecting fails, you may need to replace the default ssh used by Remote Client. First create the directory ~/.allinea. In this directory create a file called remote-exec. In this file, write

#!/bin/sh /correct/path/to/ssh [correct flags] $*