User Tools

Site Tools


workshops:hpcprac3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
workshops:hpcprac3 [2017/07/05 09:52]
kevin
workshops:hpcprac3 [2021/12/09 16:42] (current)
Line 86: Line 86:
 Now use **nano** to create a file called hello_mpi.c Now use **nano** to create a file called hello_mpi.c
 <code C> <code C>
 +/* C Example */
 #include <stdio.h> #include <stdio.h>
 #include <mpi.h> #include <mpi.h>
-   + 
-main(int argc, char **argv)+int main (int argc, char *argv[])
 { {
-   int node+  int rank, size
-    + 
-   MPI_Init(&argc,&argv); +  MPI_Init (&argc, &argv); 
-   MPI_Comm_rank(MPI_COMM_WORLD, &node); +  MPI_Comm_rank (MPI_COMM_WORLD, &rank); 
-      +  MPI_Comm_size (MPI_COMM_WORLD, &size); 
-   printf("Hello World from Node %d\n",node); +  printf( "Hello world from process %d of %d\n", rank, size ); 
-             +  MPI_Finalize()
-   MPI_Finalize();+  return 0;
 } }
 </code> </code>
  
-Compile this with the **mpicc** MPI C compiler.+Compile this with the **mpicc** MPI C compiler:
  
-> Those of you who prefer Fortran will need to compile your hello_mpi.f90 with the **mpif90** compiler instead.+  mpicc -o hello_mpi.x  mpi_hello.c
  
-If you get an error that **mpicc* is not found, then you forgot to load the necessary modules:+> Those of you who prefer Fortran will need to compile your hello_mpi.f90 with the **mpif90** compiler instead.  
 + 
 +<code Fortran> 
 +!  Fortran example   
 +program hello 
 +include 'mpif.h' 
 +integer rank, size, ierror 
 + 
 +call MPI_INIT(ierror) 
 +call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierror) 
 +call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror) 
 +print*, 'node', rank, ': Hello world' 
 +call MPI_FINALIZE(ierror) 
 +end 
 +</code> 
 + 
 +> Compile the Fortran example with: 
 + 
 +  mpif90 -o hello_mpi.x   mpi_hello.f90 
 + 
 + 
 + 
 +If you get an error message complaining that **mpicc** (or **mpif90**) is not found, then you forgot to load the necessary modules:
  
 <code bash> <code bash>
Line 119: Line 142:
   1) gcc/5.1.0                      2) chpc/openmpi/2.0.2/gcc-5.1.0   1) gcc/5.1.0                      2) chpc/openmpi/2.0.2/gcc-5.1.0
 </code> </code>
 +
 +Now create a job script file to run your first MPI program, and save it as //hello.pbs//:
 +<code bash>
 +#!/bin/bash
 +#PBS -N Hello
 +#PBS -l select=1:ncpus=24:mpiprocs=24
 +#PBS -P Wchpc
 +#PBS -q R522145
 +#PBS -W group_list=training
 +#PBS -l walltime=4:00:00
 +
 +module load chpc/openmpi/2.0.2/gcc-5.1.0
 +
 +cd /mnt/lustre/users/studentNN/MPI
 +CWD=`pwd`
 +echo "Working directory is $CWD"
 +nproc=`cat $PBS_NODEFILE | wc -l`
 +echo "nproc = $nproc"
 +echo "Nodes used by this job:"
 +cat $PBS_NODEFILE
 +
 +echo "Starting run..."
 +echo "======="
 +
 +mpirun -n $nproc ./hello_mpi.x
 +
 +echo "======="
 +echo "... done."
 +</code>
 +
 +Launch the job script with **qsub**:
 +
 +  qsub hello.pbs
 +  
 +Check its status with **qstat**:
 +
 +  qstat | grep student00
 +
 +> Replace the ''00'' above with your student account number!
 +
 +Once your job status has changed from ''R'' to ''F'' or ''E'' then look for the output:
 +
 +  ls
 +
 +The file you want to look at will be called something like //Hello.o99999// where the number at the end will be the job ID number:
 +
 +  cat Hello.o12345
 +
 +> Replace 12345 with the job number!
 +
 +=====Carry On=====
 +
 +Attempt the exercises in the {{:workshops:epcc-mpi-course-slides.pdf|slides}}.
 +
 +
  
/app/dokuwiki/data/attic/workshops/hpcprac3.1499241125.txt.gz · Last modified: 2021/12/09 16:42 (external edit)