You are on page 1of 8

HPC Running parallel 'C' Code

through PBSMPI User Guide

KFUPM

HPC-KFUPM

Running MPI C Program in parallel through PBS on HPC at KFUPM:


User can use maximum of 4 nodes to run their parallel MPI code. Each node has 8 cores that's mean
user can use 32 cores in total. If user requires more than 4 nodes, he can request for extra nodes by
sending email to hpc@kfupm.edu.sa
There are five steps that a user needs to follow in order to run their parallel MPI 'C' program
1)
2)
3)
4)
5)

Login using Putty Client


Setting environment variables
Compiling the program
Creating Script file
Submitting job

1) Login using PUTTY Client :


Login using PUTTY as shown below by typing the hostname as 10.146.1.130 with port 22

Then login using your username and password provided by the Administrator. After login user will see
the screen as shown below

http://hpc.kfupm.edu.sa

HPC-KFUPM

2) Setting Environment Variables:


Before user starts compiling and executing their codes, environment variables for Intel compilers
must be set.
For 32-bit : user@hpcmas02]$source /opt/intel/composerxe-2011.0.084/bin/iccvars.sh ia32
For 64-bit : user@hpcmas02]$source /opt/intel/composerxe-2011.0.084/bin/iccvars.sh intel64

3) Compiling the program:


Here we are writing and compiling simple Hello World MPI 'C' Program for tutorial purpose. User
can transfer its file from his desktop computer to the HPC cluster by using Winscp (Please see how
to connect and transfer files from user desktop computer to HPC using Winscp in the
Documentation section of our website). Or user can directly write its program using VI editor.
First user needs to write the program as shown below

http://hpc.kfupm.edu.sa

HPC-KFUPM

#include<mpi.h>
#include<stdio.h>
main(int argc, char**argv)
{
int numtasks, rank;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
printf("Hello World from process %d of %d\n",rank,numtasks);
MPI_Finalize();
}

Save the file and exit (esc+shift :, then wq to save the file)
Now type the following command to compile your program
$mpiicc -o hello_MPI_c hello.c

http://hpc.kfupm.edu.sa

HPC-KFUPM

This will create an executable file by the name hello_MPI_c, user can check by typing ls command.

4) Creating Script file:


Here we are creating PBS script file with the name pbsscript_c

#PBS -N MPI_c
#PBS -l nodes=2:ppn=4
mpirun -np 8 -r ssh ./hello_MPI_c > MPI_c_output

http://hpc.kfupm.edu.sa

HPC-KFUPM

Save the file and exit (esc+shift :, then wq to save the file)

5) Submitting job:
Users can submit their jobs by using qsub command followed by pbsscript name, as shown below

http://hpc.kfupm.edu.sa

HPC-KFUPM

User can use qstat command to check his job as shown below, basic commands related to PBS can
be found here.

User can check if their job is running or not by typing qstat command, if he doesnt find his job in the
list it means his job has completed, now he can check his result file with the name MPI_c_output in
his home folder, user can open this file in vi editor or can copy this file from his home folder to his
local machine using winscp.

http://hpc.kfupm.edu.sa

HPC-KFUPM

OUTPUT:

http://hpc.kfupm.edu.sa

You might also like