Difference between revisions of "MPI hello world in C"

From ScientificComputing
Jump to: navigation, search
m (Jarunanp moved page MPI Hello World in C++ to MPI Hello World in C)
Line 2: Line 2:
 
We will use the new software stack in this tutorial:
 
We will use the new software stack in this tutorial:
  
   $ env2lmod   
+
   [user@eu-login-10 ~]$ env2lmod   
   $ module load gcc/6.3.0 openmpi/4.0.2
+
   [user@eu-login-10 ~]$ module load gcc/6.3.0 openmpi/4.0.2
  
 
   The following have been reloaded with a version change:
 
   The following have been reloaded with a version change:
 
     1) gcc/4.8.5 => gcc/6.3.0
 
     1) gcc/4.8.5 => gcc/6.3.0
  
   $ which mpirun
+
   [user@eu-login-10 ~]$ which mpirun
 
   /cluster/apps/gcc-6.3.0/openmpi-4.0.2-4airvo32ypyuapzgi4fp2kjea5psqu3t/bin/mpirun
 
   /cluster/apps/gcc-6.3.0/openmpi-4.0.2-4airvo32ypyuapzgi4fp2kjea5psqu3t/bin/mpirun
  
 
== MPI Hello World ==
 
== MPI Hello World ==
 +
* Go to $SCRATCH and create a work directory
 +
  [user@eu-login-10 ~]$ cd $SCRATCH
 +
  [user@eu-login-10 user]$ pwd
 +
  /cluster/scratch/jarunanp/user
 +
  [user@eu-login-10 user]$ mkdir test_mpi
 +
  [user@eu-login-10 user]$ cd test_mpi
 +
  [user@eu-login-10 test_mpi]$
  
This MPI Hello World example is taken from [http://www.mpitutorial.com www.mpitutorial.com]
+
* Download the MPI Hello World example. This example code is taken from [http://www.mpitutorial.com www.mpitutorial.com].  
  $ cd $SCRATCH
 
  $ git clone git@../examples_euler.git
 
  $ gcc ... mpi_hello_world.cpp
 
  
 +
* Compile the code
 +
  [user@eu-login-10 test_mpi]$ mpicc -o mpi_hello_world mpi_hello_world.c
  
== Submit a batch job ==
+
* Run the executable
Request an interactive session with a compute node:
+
  [user@eu-login-10 test_mpi]$ mpirun -np 2 mpi_hello_world
   $ bsub -n 18 -W 01:00 -Is bash
+
  Hello world from processor eu-login-10, rank 0 out of 2 processors
 +
  Hello world from processor eu-login-10, rank 1 out of 2 processors
 +
 
 +
== Run a BSUB interactive session ==
 +
 
 +
* Request an interactive session on a compute node:
 +
   [user@eu-login-10 test_mpi]$ bsub -n 4 -W 01:00 -Is bash
 +
  Generic job.
 +
  Job <155089738> is submitted to queue <normal.4h>.
 +
  <<Waiting for dispatch ...>>
 +
  <<Starting on eu-ms-022-14>>
 +
  [user@eu-ms-022-14 test_mpi]$
 +
 
 +
* Run the executable
 +
  [user@eu-ms-022-14 test_mpi]$ mpirun -np 4 mpi_hello_world
 +
  Hello world from processor eu-ms-022-14, rank 0 out of 4 processors
 +
  Hello world from processor eu-ms-022-14, rank 1 out of 4 processors
 +
  Hello world from processor eu-ms-022-14, rank 2 out of 4 processors
 +
  Hello world from processor eu-ms-022-14, rank 3 out of 4 processors
 +
  [user@eu-ms-022-14 test_mpi]$
  
Check out how to submit a job with a BSUB commandline or create a job script
+
* Exit the interactive session
 +
  [user@eu-ms-022-14 test_mpi]$ exit
 +
  exit
 +
  [user@eu-login-10 test_mpi]$
  
Check the job status
 
  $ bjobs
 
  
or
+
== Submit a batch job ==
 +
* You can submit a job by using BSUB command line
 +
  [user@eu-login-10 test_mpi]$ bsub -n 4 -W 10 "mpirun mpi_hello_world"
 +
  MPI job.
 +
  Job <155090084> is submitted to queue <normal.4h>.
  
   $ bbjobs
+
* Check the job status
 +
   [user@eu-login-10 test_mpi]$ bjobs
 +
  JOBID      USER    STAT  QUEUE      FROM_HOST  EXEC_HOST  JOB_NAME  SUBMIT_TIME
 +
  155090084  user PEND  normal.4h  eu-login-10            *llo_world Dec  8 15:53
 +
  [user@eu-login-10 test_mpi]$

Revision as of 14:55, 8 December 2020

Load modules

We will use the new software stack in this tutorial:

 [user@eu-login-10 ~]$ env2lmod  
 [user@eu-login-10 ~]$ module load gcc/6.3.0 openmpi/4.0.2
 The following have been reloaded with a version change:
   1) gcc/4.8.5 => gcc/6.3.0
 [user@eu-login-10 ~]$ which mpirun
 /cluster/apps/gcc-6.3.0/openmpi-4.0.2-4airvo32ypyuapzgi4fp2kjea5psqu3t/bin/mpirun

MPI Hello World

  • Go to $SCRATCH and create a work directory
 [user@eu-login-10 ~]$ cd $SCRATCH
 [user@eu-login-10 user]$ pwd
 /cluster/scratch/jarunanp/user
 [user@eu-login-10 user]$ mkdir test_mpi
 [user@eu-login-10 user]$ cd test_mpi
 [user@eu-login-10 test_mpi]$ 
  • Compile the code
 [user@eu-login-10 test_mpi]$ mpicc -o mpi_hello_world mpi_hello_world.c
  • Run the executable
 [user@eu-login-10 test_mpi]$ mpirun -np 2 mpi_hello_world
 Hello world from processor eu-login-10, rank 0 out of 2 processors
 Hello world from processor eu-login-10, rank 1 out of 2 processors

Run a BSUB interactive session

  • Request an interactive session on a compute node:
 [user@eu-login-10 test_mpi]$ bsub -n 4 -W 01:00 -Is bash
 Generic job.
 Job <155089738> is submitted to queue <normal.4h>.
 <<Waiting for dispatch ...>>
 <<Starting on eu-ms-022-14>>
 [user@eu-ms-022-14 test_mpi]$
  • Run the executable
 [user@eu-ms-022-14 test_mpi]$ mpirun -np 4 mpi_hello_world
 Hello world from processor eu-ms-022-14, rank 0 out of 4 processors
 Hello world from processor eu-ms-022-14, rank 1 out of 4 processors
 Hello world from processor eu-ms-022-14, rank 2 out of 4 processors 
 Hello world from processor eu-ms-022-14, rank 3 out of 4 processors
 [user@eu-ms-022-14 test_mpi]$
  • Exit the interactive session
 [user@eu-ms-022-14 test_mpi]$ exit
 exit
 [user@eu-login-10 test_mpi]$


Submit a batch job

  • You can submit a job by using BSUB command line
 [user@eu-login-10 test_mpi]$ bsub -n 4 -W 10 "mpirun mpi_hello_world"
 MPI job.
 Job <155090084> is submitted to queue <normal.4h>.
  • Check the job status
 [user@eu-login-10 test_mpi]$ bjobs
 JOBID      USER    STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
 155090084  user PEND  normal.4h  eu-login-10             *llo_world Dec  8 15:53
 [user@eu-login-10 test_mpi]$