Mpi Openmp Examples
Mpi Openmp Examples
" These are mature programming models and standards have been developed.!
" OpenMP! " MPI !
SAN DIEGO SUPERCOMPUTER CENTER at the UNIVERSITY OF CALIFORNIA, SAN DIEGO
OpenMP !
" Application Program Interface (API) which allows multi-threaded, shared memory parallelism.! " Implemented by all C/C++, Fortran compilers. Also available on most major platforms: Unix/ Linux/Windows.! " Three parts:!
" Compiler Directives! " Runtime library routines ! " Environment variables!
" Several very large shared memory resources on TeraGrid: Blacklight (PSC), Nautilus (NICS), Ember (NCSA), Dash (SDSC).!
SAN DIEGO SUPERCOMPUTER CENTER at the UNIVERSITY OF CALIFORNIA, SAN DIEGO
OpenMP !
" OpenMP enables parallelism by use of multiple threads in the shared memory programming paradigm.! " Uses fork-join model of parallel execution.! " All OpenMP codes begin as a single process (master thread) until the rst parallel region => FORK multiple threads.! " Once parallel section is complete, threads synchronize and leave only master thread (JOIN).! " You can have thread private and shared variables.! " Compiling OpenMP codes is easy: one compiler ag!!
" Intel: ifort openmp, icc openmp ! " PGI: pgf90 mp, pgcc mp !
"
Examples !
" Today"s examples available in train01 account on Pople. Copy them into your directory:!
cp -r ~train01/workshop/PR_EXAMPLES .!
" Next: We look at the job submission script included in the directory: pople_pi_omp.sub!
SAN DIEGO SUPERCOMPUTER CENTER at the UNIVERSITY OF CALIFORNIA, SAN DIEGO
MPI Programming !
" Extensive set of routines (115 in MPI-1) to provide range of functionality. ! " Don"t worry you can write parallel codes with far fewer !.! " Communication routines!
" Point to point! " Collective!
" Synchronization! " Data movement! " Collective computation reduction operations (collecting data from every task and summing for example).!
" "
"
printf("Number of MPI tasks = %d\n", numprocs);! }! INTLOC=INTERVALS/numprocs;! piloc=0.0;! n_1=1.0/(double)INTERVALS;! for (i = 0; i < INTLOC; i++)! {! iglob = INTLOC*rank+i;! x = n_1 * ((double)iglob - 0.5);! piloc += 4.0 / (1.0 + x * x);! }! MPI_Reduce(&piloc,&pi,1,MPI_DOUBLE,MPI_SUM, 0,MPI_COMM_WORLD);! if (rank == 0)! {! pi *= n_1; ! printf ("Pi = %.12lf\n", pi); ! }! MPI_Finalize();! } !
" Output le tagged with jobid. For example I have pi_mpi.o7171148.! " Sample output:!
Hello from MPI task= 0! Hello from MPI task= 1! Hello from MPI task= 2! Number of MPI tasks = 4! Hello from MPI task= 3! Pi = 3.141608278534!
SAN DIEGO SUPERCOMPUTER CENTER at the UNIVERSITY OF CALIFORNIA, SAN DIEGO
Break!!
" Questions!
5
Processor 1
10
5
Processor 1
10
Processor 0: Value at 0 known; Get 4 from processor 1; Solve the equation at (1,2,3); Send 3 to processor 1 Local Data Index : ilocal = 0 , 1, 2, 3, 4 Global Data Index: iglobal = 0, 1, 2, 3, 4 Processor 1: Get 3 from processor 0; Get 7 from processor 2; Solve the equation at (4,5,6); Send 4 to processor 0 and send 6 to processor 2 Local Data Index : ilocal = 0, 1, 2, 3, 4 Global Data Index : iglobal = 3, 4, 5, 6, 7 Processor 2: Get 6 from processor 1; Solve the equation at (7,8,9); Value at 10 known; Send 7 to processor 1 Local Data Index : ilocal = 0, 1, 2, 3, 4 Global Data Index : iglobal = 6, 7, 8, 9, 10
5
Processor 1
10
"Compilation of MPI Version (on Steele):! "module load mpich2-intel! "mpif90 -o heat_mpi xed heat_mpi.f90! "Run script (on Steele):! "Script name : heat.sub! "Submit using:! qsub q R7160158 heat.sub!
5
Processor 1
10
Process 0 of 3 has started! Processor 0 has nished setting initial conditions! Process 1 of 3 has started! Processor 1 has nished setting initial conditions! Process 2 of 3 has started! Processor 2 has nished setting initial conditions! Running Iteration Number 1! Sending and receiving overlap points! Running Iteration Number 2! Sending and receiving overlap points! Running Iteration Number 3! Sending and receiving overlap points! SOLUTION SENT TO FILE AFTER 3 TIMESTEPS:!
5
Processor 1
10
ds100 % more data0.dat ! Processor 0! ilocal= 0 ;iglobal= 0 ;T= 0.000000000000000000E+00! ilocal= 1 ;iglobal= 1 ;T= 0.307205621017284991! ilocal= 2 ;iglobal= 2 ;T= 0.584339815421976549! ilocal= 3 ;iglobal= 3 ;T= 0.804274757358271253! ilocal= 4 ;iglobal= 4 ;T= 0.945481682332597884!
ds100 % more data2.dat! Processor 2! ilocal= 0 ;iglobal= 6 ;T= 0.945481682332597995! ilocal= 1 ;iglobal= 7 ;T= 0.804274757358271253! ilocal= 2 ;iglobal= 8 ;T= 0.584339815421976660! ilocal= 3 ;iglobal= 9 ;T= 0.307205621017285102! ilocal= 4 ;iglobal= 10 ;T= 0.000000000000000000E+00!
ds100 % more data1.dat! Processor 1! ilocal= 0 ;iglobal= 3 ;T= 0.804274757358271253! ilocal= 1 ;iglobal= 4 ;T= 0.945481682332597884! ilocal= 2 ;iglobal= 5 ;T= 0.994138272681972301! ilocal= 3 ;iglobal= 6 ;T= 0.945481682332597995! ilocal= 4 ;iglobal= 7 ;T= 0.804274757358271253!
SAN DIEGO SUPERCOMPUTER CENTER at the UNIVERSITY OF CALIFORNIA, SAN DIEGO
References !
" TeraGrid user support website!
" https://www.teragrid.org/web/user-support/home!