a quick introduction to mpi message passing interface
play

A quick introduction to MPI (Message Passing Interface) M1IF - APPD - PowerPoint PPT Presentation

Introduction Point-to-point communication Collective communications Custom communicators A quick introduction to MPI (Message Passing Interface) M1IF - APPD Oguz Kaya Pierre Pradic cole Normale Suprieure de Lyon, France 1 / 34 Oguz


  1. Introduction Point-to-point communication Collective communications Custom communicators A quick introduction to MPI (Message Passing Interface) M1IF - APPD Oguz Kaya Pierre Pradic École Normale Supérieure de Lyon, France 1 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  2. Introduction Point-to-point communication Collective communications Custom communicators Introduction 2 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  3. Introduction Point-to-point communication Collective communications Custom communicators What is MPI ? Standardized and portable message-passing system. Started in the 90’s, still used today in research and industry. Good theoretical model. Good performances on HPC networks (InfiniBand ...). 3 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  4. Introduction Point-to-point communication Collective communications Custom communicators What is MPI ? De facto standard for communications in HPC applications. 4 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  5. Introduction Point-to-point communication Collective communications Custom communicators Programming model APIs: C and Fortran APIs. C++ API deprecated by MPI-3 (2008). Environment: Many implementations of the standard (mainly OpenMPI and MPICH) Compiler (wrappers around gcc) Runtime (mpirun) 5 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  6. Introduction Point-to-point communication Collective communications Custom communicators Programming model Compiling: gcc mpicc → g++ mpic++ / mpicxx → gfortran mpifort → Executing: mpirun -n <nb procs> <executable> <args> ex : mpirun -n 10 ./a.out note: mpiexec and orterun are synonyms of mpirun see man mpirun for more details 6 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  7. Introduction Point-to-point communication Collective communications Custom communicators MPI context Context limits All MPI call must be nested in the MPI context delimited by MPI_Init and MPI_Finalize . 1 #i n c l u d e <mpi . h> 2 3 i n t main ( i n t argc , char ∗ argv [ ] ) 4 { 5 MPI_Init(&argc , &argv ) ; 6 7 // . . . 8 9 MPI_Finalize ( ) ; 10 11 return 0; 12 } 7 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  8. Introduction Point-to-point communication Collective communications Custom communicators MPI context Hello World 1 #i n c l u d e <s t d i o . h> 2 #i n c l u d e <mpi . h> 3 4 i n t main ( i n t argc , char ∗ argv [ ] ) 5 { 6 i n t rank , s i z e ; 7 8 MPI_Init(&argc , &argv ) ; 9 10 MPI_Comm_rank(MPI_COMM_WORLD, &rank ) ; 11 MPI_Comm_size(MPI_COMM_WORLD, &s i z e ) ; 12 13 p r i n t f ( " Hell o ␣from␣ proc ␣%d␣/␣%d\n" , rank , s i z e ) ; 14 15 MPI_Finalize ( ) ; 16 17 0; return 18 } 8 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  9. Introduction Point-to-point communication Collective communications Custom communicators Synchronization Code: p r i n t f ( "[%d ] ␣ step ␣1\n" , rank ) ; MPI_Barrier (MPI_COMM_WORLD) ; p r i n t f ( "[%d ] ␣ step ␣2\n" , rank ) ; Output: [ 0 ] step 1 [ 1 ] step 1 [ 2 ] step 1 [ 3 ] step 1 [ 3 ] step 2 [ 0 ] step 2 [ 2 ] step 2 [ 1 ] step 2 9 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  10. Introduction Point-to-point communication Collective communications Custom communicators Point-to-point communication 10 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  11. Introduction Point-to-point communication Collective communications Custom communicators Send and Receive Sending data: MPI_Send( const void ∗ data , i n t count , i n t MPI_Datatype datatype , d e s t i n a t i o n , i n t tag , i n t MPI_Comm communicator ) ; Receiving data: i n t MPI_Recv( void ∗ data , i n t count , MPI_Datatype datatype , i n t source , i n t tag , MPI_Comm communicator , MPI_Status∗ s t a t u s ) ; 11 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  12. Introduction Point-to-point communication Collective communications Custom communicators Example 1 i n t rank , s i z e ; 2 MPI_Comm_rank(MPI_COMM_WORLD, &rank ) ; 3 MPI_Comm_size(MPI_COMM_WORLD, &s i z e ) ; 4 5 i n t number ; 6 switch ( rank ) 7 { 8 0: case 9 number = − 1; 10 MPI_Send(&number , 1 , MPI_INT , 1 , 0 , MPI_COMM_WORLD) ; 11 break ; 12 1: case 13 MPI_Recv(&number , 1 , MPI_INT , 0 , 0 , MPI_COMM_WORLD, 14 MPI_STATUS_IGNORE) ; 15 p r i n t f ( " r e c e i v e d ␣number : ␣%d\n" , number ) ; 16 break ; 17 } 12 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  13. Introduction Point-to-point communication Collective communications Custom communicators Asynchronious communications Sending data: i n t MPI_Isend ( const void ∗ data , i n t count , MPI_Datatype datatype , i n t d e s t i n a t i o n , i n t tag , MPI_Comm communicator , MPI_Request∗ r e q u e s t ) ; Receiving data: i n t MPI_Irecv ( void ∗ data , i n t count , MPI_Datatype datatype , i n t source , i n t tag , MPI_Comm communicator , MPI_Request∗ r e q u e s t ) ; 13 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  14. Introduction Point-to-point communication Collective communications Custom communicators Other functions MPI_Probe, MPI_Iprobe MPI_Test, MPI_Testany, MPI_Testall MPI_Cancel MPI_Wtime, MPI_Wtick 14 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  15. Introduction Point-to-point communication Collective communications Custom communicators Simple datatypes MPI_SHORT short int MPI_INT int MPI_LONG long int MPI_LONG_LONG long long int MPI_UNSIGNED_CHAR unsigned char MPI_UNSIGNED_SHORT unsigned short int MPI_UNSIGNED unsigned int MPI_UNSIGNED_LONG unsigned long int MPI_UNSIGNED_LONG_LONG unsigned long long int MPI_FLOAT float MPI_DOUBLE double MPI_LONG_DOUBLE long double MPI_BYTE char 15 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  16. Introduction Point-to-point communication Collective communications Custom communicators Composed datatypes Composed structure: Structures; Array. Possibilities are almost limitless ... ... but sometimes difficult to setup. 16 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  17. Introduction Point-to-point communication Collective communications Custom communicators Collective communications 17 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  18. Introduction Point-to-point communication Collective communications Custom communicators One-to-all communication Broadcast 18 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  19. Introduction Point-to-point communication Collective communications Custom communicators One-to-all communication Broadcast MPI_Bcast ( void ∗ data , i n t count , i n t MPI_Datatype datatype , i n t root , MPI_Comm communicator ) ; 19 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  20. Introduction Point-to-point communication Collective communications Custom communicators One-to-all communication Reduce 20 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  21. Introduction Point-to-point communication Collective communications Custom communicators One-to-all communication Reduce i n t MPI_Reduce( const void ∗ sendbuf , void ∗ recvbuf , count , i n t MPI_Datatype datatype , MPI_Op operator , root , i n t MPI_Comm communicator ) ; 21 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  22. Introduction Point-to-point communication Collective communications Custom communicators One-to-all communication Scatter 22 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  23. Introduction Point-to-point communication Collective communications Custom communicators One-to-all communication Scatter i n t MPI_Scatter ( const void ∗ sendbuf , i n t sendcount , MPI_Datatype sendtype , void ∗ recvbuf , i n t recvcount , MPI_Datatype recvtype , i n t root , MPI_Comm communicator ) ; 23 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  24. Introduction Point-to-point communication Collective communications Custom communicators One-to-all communication Gather 24 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  25. Introduction Point-to-point communication Collective communications Custom communicators One-to-all communication Gather i n t MPI_Gather ( const void ∗ sendbuf , i n t sendcount , MPI_Datatype sendtype , void ∗ recvbuf , i n t recvcount , MPI_Datatype recvtype , i n t root , MPI_Comm communicator ) ; 25 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  26. Introduction Point-to-point communication Collective communications Custom communicators All-to-all communication Allreduce 26 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  27. Introduction Point-to-point communication Collective communications Custom communicators All-to-all communication AllReduce i n t MPI_Allreduce ( const void ∗ sendbuf , void ∗ recvbuf , i n t count , MPI_Datatype datatype , MPI_Op operator , MPI_Comm communicator ) ; 27 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

  28. Introduction Point-to-point communication Collective communications Custom communicators All-to-all communication Allgather 28 / 34 Oguz Kaya, Pierre Pradic M1IF - Presentation MPI

Recommend


More recommend