This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
workshops:hpcprac3 [2017/07/05 09:35] kevin |
workshops:hpcprac3 [2021/12/09 16:42] (current) |
||
|---|---|---|---|
| Line 9: | Line 9: | ||
| **example.sh**: | **example.sh**: | ||
| - | < | + | <code bash> |
| #!/bin/bash | #!/bin/bash | ||
| #PBS -N example01 | #PBS -N example01 | ||
| Line 85: | Line 85: | ||
| Now use **nano** to create a file called hello_mpi.c | Now use **nano** to create a file called hello_mpi.c | ||
| + | <code C> | ||
| + | /* C Example */ | ||
| + | #include < | ||
| + | #include < | ||
| + | int main (int argc, char *argv[]) | ||
| + | { | ||
| + | int rank, size; | ||
| + | |||
| + | MPI_Init (&argc, &argv); | ||
| + | MPI_Comm_rank (MPI_COMM_WORLD, | ||
| + | MPI_Comm_size (MPI_COMM_WORLD, | ||
| + | printf( "Hello world from process %d of %d\n", rank, size ); | ||
| + | MPI_Finalize(); | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Compile this with the **mpicc** MPI C compiler: | ||
| + | |||
| + | mpicc -o hello_mpi.x | ||
| + | |||
| + | > 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 ' | ||
| + | integer rank, size, ierror | ||
| + | |||
| + | call MPI_INIT(ierror) | ||
| + | call MPI_COMM_SIZE(MPI_COMM_WORLD, | ||
| + | call MPI_COMM_RANK(MPI_COMM_WORLD, | ||
| + | print*, ' | ||
| + | call MPI_FINALIZE(ierror) | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | > Compile the Fortran example with: | ||
| + | |||
| + | mpif90 -o hello_mpi.x | ||
| + | |||
| + | |||
| + | |||
| + | If you get an error message complaining that **mpicc** (or **mpif90**) is not found, then you forgot to load the necessary modules: | ||
| + | |||
| + | <code bash> | ||
| + | module unload gcc/6.1.0 | ||
| + | module load chpc/ | ||
| + | module list | ||
| + | </ | ||
| + | |||
| + | The last command should display: | ||
| + | < | ||
| + | Currently Loaded Modulefiles: | ||
| + | 1) gcc/ | ||
| + | </ | ||
| + | |||
| + | Now create a job script file to run your first MPI program, and save it as // | ||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | #PBS -N Hello | ||
| + | #PBS -l select=1: | ||
| + | #PBS -P Wchpc | ||
| + | #PBS -q R522145 | ||
| + | #PBS -W group_list=training | ||
| + | #PBS -l walltime=4: | ||
| + | |||
| + | module load chpc/ | ||
| + | |||
| + | cd / | ||
| + | CWD=`pwd` | ||
| + | echo " | ||
| + | nproc=`cat $PBS_NODEFILE | wc -l` | ||
| + | echo "nproc = $nproc" | ||
| + | echo "Nodes used by this job:" | ||
| + | cat $PBS_NODEFILE | ||
| + | |||
| + | echo " | ||
| + | echo " | ||
| + | |||
| + | mpirun -n $nproc ./ | ||
| + | |||
| + | echo " | ||
| + | echo "... done." | ||
| + | </ | ||
| + | |||
| + | Launch the job script with **qsub**: | ||
| + | |||
| + | qsub hello.pbs | ||
| | | ||
| + | Check its status with **qstat**: | ||
| + | |||
| + | qstat | grep student00 | ||
| + | |||
| + | > Replace the '' | ||
| + | |||
| + | Once your job status has changed from '' | ||
| + | |||
| + | ls | ||
| + | |||
| + | The file you want to look at will be called something like // | ||
| + | |||
| + | cat Hello.o12345 | ||
| + | |||
| + | > Replace 12345 with the job number! | ||
| + | |||
| + | =====Carry On===== | ||
| + | |||
| + | Attempt the exercises in the {{: | ||
| + | |||
| + | |||
| + | |||