How to install setup mpi or mpich and run hello world program in Linux cluster with slurm files?

At first, you need to download the mpich file from mpich website. After getting the link, in the linux command prompt we need to write the command


To unzip the file, we need to use tar unzip command

tar -xvf mpich-3.3.2.tar.gz

Then we need to export path environment variable like the below command.

export PATH=$PATH:/home/username/mpi/mpich_install/bin

echo $PATH will show the path values like this.


Now, we need to write the hello_world problem.
the hello_world.c program is below:


int main(int argc, char *argv[])

int my_rank; int size;

MPI_Init(&argc, &argv); /*START MPI */

MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

MPI_Comm_size(MPI_COMM_WORLD, &size);

printf("Hello world! I'm rank (processor number) %d of %d processor \n", my_rank, size);

MPI_Finalize(); /* EXIT MPI */
return 0;

We need to compile the program. The code is below:

mpicc hello_world.c -o hello_world.exe

The executable file will be hello_world.exe. We can run the mpi file by the command

mpirun ./hello_world1.exe

The output will be
Hello world! I'm rank (processor number) 0 of 1 processor

If we run the command with n tasks, it will show the below output.

$ mpirun -n 4 ./hello_world1.exe
Hello world! I'm rank (processor number) 3 of 4 processor
Hello world! I'm rank (processor number) 0 of 4 processor
Hello world! I'm rank (processor number) 2 of 4 processor
Hello world! I'm rank (processor number) 1 of 4 processor

Now, we need to run the mpi program from slurm script. By using the vim we can add the bash scripting file to the folder.


it will show the editor where we can insert values. To insert text we need to press i, and after the editing we need to press escape key(esc) and :wq (to save and exit).
we can add the text to the file

#!/bin/bash -x



module load mpich/ge/gcc/64/3.3

#mpiexec ./hello_world.exe
mpirun ./hello_world.exe

here, job_name is hello_world, output file is out_hello_world, error file is err_hello_world. %j is for the job id.
Number of tasks ntasks is 4, number of nodes is 1.
We need to load mpich module form the module loader

My cat command we can see the text.


we can submit the shell script to the cluster by the below command and it will show us the job id

Submitted batch job 6266850

Here job id is 6266850.

To see the job status, we can use squeue command

squeue --user=userid

After the finishing the job, it squeue will not show no task in the queue.

By pressing ls command we can see the out_hello_world.6266850 file in the directory.

By cat out_hello_world.6266850 we can see the output.

cat out_hello_world.6266850
Hello world! I'm rank (processor number) 0 of 4 processor
Hello world! I'm rank (processor number) 1 of 4 processor
Hello world! I'm rank (processor number) 2 of 4 processor
Hello world! I'm rank (processor number) 3 of 4 processor

How to search mpi module available to load in Linux cluster?

To find the module to load Linux cluster, we need to type

module spider module_name_key
module_name_key is the partial name which we can use for searching.
it will bring us the modules which are available for us to load.
For example,
I wanted to load openmpi module from the Linux cluster. So I need to know the exact name of mpi module of the cluster. I search it by
module spider openmpi

it showed me the openmpi modules which are available for loading.

The Open MPI Project is an open source MPI-3 implementation.


For detailed information about a specific "OpenMPI" module (including how to load the modules) use the module's full name.

Suppose, we want to load the module OpenMPI/1.6.4-GCC-4.7.2

We need to load the module by this command

module load OpenMPI/1.6.4-GCC-4.7.2

By typing the following command I can check the module list in the cluster.

module list

It will show you the list which is loaded for you in the cluster.

To be specific

$ module list

Currently Loaded Modules:
1) shared 2) rc-base 3) DefaultModules 4) gcc/8.2.0 5) slurm/18.08.9 6) mpich/ge/gcc/64/3.3

$ module load OpenMPI/1.6.4-GCC-4.7.2
$ module list

Currently Loaded Modules:
1) shared 3) DefaultModules 5) slurm/18.08.9 7) GCC/4.7.2 9) OpenMPI/1.6.4-GCC-4.7.2
2) rc-base 4) gcc/8.2.0 6) mpich/ge/gcc/64/3.3 8) hwloc/1.6.2-GCC-4.7.2

How to overcome shell debugging error in linux cluster?

When I was working with bash files, it showed me this type of error.

Shell debugging temporarily silenced: export LMOD_SH_DBG_ON=1 for this output (/usr/share/lmod/lmod/init/bash)
Shell debugging restarted

To overcome this type of error, we need to type

export LMOD_SH_DBG_ON=1