Difference between revisions of "MPI hello world in C"
From ScientificComputing
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | + | {{back_to_tutorials}} | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Load modules == | == Load modules == | ||
Line 95: | Line 89: | ||
− | + | {{back_to_tutorials}} | |
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 09:41, 7 June 2021
< Examples |
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/user [user@eu-login-10 user]$ mkdir test_mpi [user@eu-login-10 user]$ cd test_mpi [user@eu-login-10 test_mpi]$
- Download the MPI Hello World example
[user@eu-login-10 test_mpi]$ wget https://scicomp.ethz.ch/public/examples/mpi/mpi_hello_world.c
- 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 with BSUB command line
- 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]$
- Check the output file lsf.o155090084
[user@eu-login-10 test_mpi]$ cat lsf.o155090084
Create a job script
- Create a job script called job_script.bsub
#!/usr/bin/bash #BSUB -n 4 #BSUB -W 10 #BSUB -J test_mpi mpirun mpi_hello_world
- Submit a job using the job script
[user@eu-login-10 test_mpi]$ bsub < job_script.bsub MPI job. Job <155090224> is submitted to queue <normal.4h>.
< Examples |