SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
Parallel Programming using
                            MPI
                Collective Communications
                                      Claudio Gheller
                                         CINECA
                                    c.gheller@cineca.it




Collective Communications




   Collective Communications

     !"#$$%&'()*'#&+,'&-#.-'&/,),/0#%1,#2,10#(3++
     !")..34,56,).. 10#(3++3+,'&,),(#$$%&'()*#0
   Barrier Synchronization
   Broadcast
   Gather/Scatter
   Reduction (sum, max, prod, … )




                                                          2




                                                              1
Collective Communications




     Characteristics



     All processes must call the collective routine
     No non-blocking collective communication
     No tags



                  7)23+*,)&4,$#+*,322'('3&*,
                    (#$$%&'()*'#&,$#43



                                                                         3




Collective Communications



    MPI_Barrier
    Stop processes until all processes within a communicator reach the
       barrier

    Fortran:
    CALL MPI_BARRIER(comm, ierr)


    C:
    int MPI_Barrier(MPI_Comm comm)




                                                                         4




                                                                             2
Collective Communications



  Barrier
                        *:                                  *;                                  *<
                         8;
              89
                                   8=
                   8:         8<                  89   8:    8;   8<   8=




                                        barrier                             barrier
                                                                                      89   8:   8;   8<   8=




         *



                                                                                                               5




Collective Communications

               Broadcast (MPI_BCAST)
    One-to-all communication: same data sent from root process to all others in the
       communicator

    Fortran:
             INTEGER count, type, root, comm, ierr
             CALL MPI_BCAST(buf, count, type, root, comm, ierr)
             Buf array of type type


    C:
             int MPI_Bcast(void *buf, int count, MPI_Datatype, datatypem int root,
                MPI_Comm comm)


    All processes must specify same root, rank and comm




                                                                                                               6




                                                                                                                   3
Collective Communications

              Broadcast
 PROGRAM broad_cast
  INCLUDE 'mpif.h'
  INTEGER ierr, myid, nproc, root
  INTEGER status(MPI_STATUS_SIZE)
  REAL A(2)                                                                                        89
  CALL MPI_INIT(ierr)
  CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
  CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)                                            ):
  root = 0                                                                                         8:
  IF( myid .EQ. 0 ) THEN                         89                                         ):
    a(1) = 2.0
    a(2) = 4.0                                                                              ):
  END IF                                                                                           8;
  CALL MPI_BCAST(a, 2, MPI_REAL, 0,
                                                                                            ):
                 MPI_COMM_WORLD, ierr)
  WRITE(6,*) myid, ': a(1)=', a(1), 'a(2)=', a(2)
  CALL MPI_FINALIZE(ierr)                                                                           8<
  END




                                                                                                              7




Collective Communications

                          Scatter / Gather



     7()**30                                           >)*?30

    sndbuf                                             sndbuf       sndbuf       sndbuf           sndbuf

   89
    89        ):    );   )<   )=                       89
                                                        89   ):     8:
                                                                     8:    );        8;
                                                                                      8;    )<    8<
                                                                                                   8<    )=




   89    ):        8:    );        8;   )<   8<   )=
                                                                  89
                                                                   89      ):   );     )<    )=
  rcvbuf           rcvbuf      rcvbuf        rcvbuf
                                                                  rcvbuf




                                                                                                              8




                                                                                                                  4
Collective Communications



   MPI_Scatter
   One-to-all communication: different data sent from root process to all others in the
      communicator



   Fortran:
        CALL MPI_SCATTER(sndbuf, sndcount, sndtype, rcvbuf, rcvcount, rcvtype,
           root, comm, ierr)


   Arguments definition are like other MPI subroutine
   sndcount is the number of elements sent to each process, not the size of sndbuf, that
      should be sndcount times the number of process in the communicator
   The sender arguments are meaningful only for root




                                                                                           9




Collective Communications




                                                                                           10




                                                                                                5
Collective Communications


   MPI_SCATTERV
   Usage
       –   int MPI_Scatterv( void* sendbuf,               /* in */
                             int* sendcounts,             /* in */
                             int* displs,                 /* in */
                             MPI_Datatype sendtype,       /* in */
                             void* recvbuf,               /* in */
                             int recvcount,               /* in */
                             MPI_Datatype recvtype,       /* in */
                             int root,                               /* in */
                             MPI_Comm comm);              /* in */
   Description
       –   Distributes individual messages from root to each process in communicator
       –   Messages can have different sizes and displacements




                                                                                       11




Collective Communications




                                                                                       12




                                                                                            6
Collective Communications



   MPI_Gather
   One-to-all communication: different data collected by the root process, from all others
      processes in the communicator. Is the opposite of Scatter
   Fortran:
   CALL MPI_GATHER(sndbuf, sndcount, sndtype, rcvbuf, rcvcount,
      rcvtype, root, comm, ierr)




   Arguments definition are like other MPI subroutine
   rcvcount is the number of elements collected from each process, not the size of rcvbuf,
       that should be rcvcount times the number of process in the communicator
   The receiver arguments are meaningful only for root




                                                                                             13




Collective Communications




                                                                                             14




                                                                                                  7
Collective Communications


   MPI_GATHERV
   Usage
       –   int MPI_Gatherv( void* sendbuf,                /* in */
                          int sendcount,                  /* in */
                          MPI_Datatype sendtype,          /* in */
                          void* recvbuf,                  /* out */
                          int* recvcount,                 /* in */
                          int* displs,                                /* in */
                          MPI_Datatype recvtype,          /* in */
                          int root,                       /* in */
                          MPI_Comm comm );                /* in */
   Description
       –   Collects individual messages from each process in communicator to the root process and
           store them in rank order
       –   Messages can have different sizes and displacements




                                                                                                    15




Collective Communications




                                                                                                    16




                                                                                                         8
Collective Communications

  Scatter example
    PROGRAM scatter
    INCLUDE 'mpif.h'
    INTEGER ierr, myid, nproc, nsnd, I, root
    INTEGER status(MPI_STATUS_SIZE)
    REAL A(16), B(2)
    CALL MPI_INIT(ierr)
    CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
    CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)
    root = 0
    IF( myid .eq. root ) THEN
      DO i = 1, 16
        a(i) = REAL(i)
      END DO
    END IF
    nsnd = 2
    CALL MPI_SCATTER(a, nsnd, MPI_REAL, b, nsnd,
   & MPI_REAL, root, MPI_COMM_WORLD, ierr)
    WRITE(6,*) myid, ': b(1)=', b(1), 'b(2)=', b(2)
    CALL MPI_FINALIZE(ierr)


                                                        17




Collective Communications
    Gather example
      PROGRAM gather
      INCLUDE 'mpif.h'
      INTEGER ierr, myid, nproc, nsnd, I, root
      INTEGER status(MPI_STATUS_SIZE)
      REAL A(16), B(2)
      CALL MPI_INIT(ierr)
      CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
      CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)
      root = 0
      b(1) = REAL( myid )
      b(2) = REAL( myid )
      nsnd = 2
      CALL MPI_GATHER(b, nsnd, MPI_REAL, a, nsnd,
     & MPI_REAL, root MPI_COMM_WORLD, ierr)
      IF( myid .eq. root ) THEN
        DO i = 1, (nsnd*nproc)
          WRITE(6,*) myid, ': a(i)=', a(i)
        END DO
      END IF
      CALL MPI_FINALIZE(ierr)

                                                        18




                                                             9
Collective Communications

                    MPI_Alltoall
            @#0*0)&A
            CALL MPI_ALLTOALL(sndbuf, sndcount, sndtype, rcvbuf, rcvcount,
            rcvtype, comm, ierr)


               89      ):   );   )<   )=              89   ):   5:   (:   4:




               89                                     89




                                                                               rcvbuf
   sndbuf




                       5:   5;   5<   5=                   );   5;   (;   4;




               89      (:   (;   (<   (=              89   )<   5<   (<   4<




               89      4:   4;   4<   4=              89   )=   5=   (=   4=




                B306,%+32%.,*#,'$1.3$3&*,4)*),*0)&+1#+'*'#&

                                                                                 19




Collective Communications



     Reduction
     The reduction operation allow to:
     •       Collect data from each process
     •       Reduce the data to a single value
     •       Store the result on the root processes
     •       Store the result on all processes
     •       Overlap of communication and computing




                                                                                 20




                                                                                        10
Collective Communications

               Reduce, Parallel Sum

          89    ):   5:

                                                                           89    7) 75
          8:    );   5;
                                                                            8:    7) 75
                                         7)C):D);D)<D)=
          8;    )<   5<                  75C5:D5;D5<D5=
                                                                            8;    7) 75

          8<    )=    5=                                                   8<    7) 75


                     E34%(*'#&,2%&(*'#&,F#0G+,F'*?,)00)6+
                     #*?30,#130)*'#&A,10#4%(*H,$'&H,$)IH,)&4H,JK,




                                                                                          21




Collective Communications



    MPI_REDUCE and MPI_ALLREDUCE
    Fortran:
    MPI_REDUCE( snd_buf, rcv_buf, count, type, op, root, comm, ierr)

    snd_buf      input array of type type containing local values.
    rcv_buf      output array of type type containing global results
    Count       (INTEGER) number of element of snd_buf and rcv_buf
    type        (INTEGER) MPI type of snd_buf and rcv_buf
    op          (INTEGER) parallel operation to be performed
    root        (INTEGER) MPI id of the process storing the result
    comm        (INTEGER) communicator of processes involved in the operation
    ierr        (INTEGER) output, error code (if ierr=0 no error occours)



    MPI_ALLREDUCE( snd_buf, rcv_buf, count, type, op, comm, ierr)

    The argument root is missing, the result is stored to all processes.




                                                                                          22




                                                                                               11
Collective Communications


         Predefined Reduction Operations
                   MPI op           Function

                   MPI_MAX          Maximum

                   MPI_MIN          Minimum

                   MPI_SUM          Sum

                   MPI_PROD         Product

                   MPI_LAND         Logical AND

                   MPI_BAND         Bitwise AND

                   MPI_LOR          Logical OR

                   MPI_BOR          Bitwise OR

                   MPI_LXOR         Logical exclusive OR

                   MPI_BXOR         Bitwise exclusive OR

                   MPI_MAXLOC       Maximum and location

                   MPI_MINLOC       Minimum and location




                                                                     23




Collective Communications

    Reduce / 1

    C:
         int MPI_Reduce(void * snd_buf, void * rcv_buf, int count,
         MPI_Datatype type, MPI_Op op, int root, MPI_Comm comm)

         int MPI_Allreduce(void * snd_buf, void * rcv_buf, int
         count, MPI_Datatype type, MPI_Op op, MPI_Comm comm)




                                                                     24




                                                                          12
Collective Communications

       Reduce, example
       PROGRAM reduce
         INCLUDE 'mpif.h'
         INTEGER ierr, myid, nproc, root
         INTEGER status(MPI_STATUS_SIZE)
         REAL A(2), res(2)
         CALL MPI_INIT(ierr)
         CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
         CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)
         root = 0
         a(1) = 2.0*myid
         a(2) = 4.0+myid
         CALL MPI_REDUCE(a, res, 2, MPI_REAL, MPI_SUM, root,
        & MPI_COMM_WORLD, ierr)
         IF( myid .EQ. 0 ) THEN
           WRITE(6,*) myid, ': res(1)=', res(1), 'res(2)=', res(2)
         END IF
         CALL MPI_FINALIZE(ierr)
         END


                                                                     25




                                                                          13

Contenu connexe

Tendances

Networking and Go: An Epic Journey
Networking and Go: An Epic JourneyNetworking and Go: An Epic Journey
Networking and Go: An Epic JourneySneha Inguva
 
MessagePack(msgpack): Compact and Fast Serialization Library
MessagePack(msgpack): Compact and Fast Serialization LibraryMessagePack(msgpack): Compact and Fast Serialization Library
MessagePack(msgpack): Compact and Fast Serialization LibraryTakatoshi Kondo
 
Go concurrency
Go concurrencyGo concurrency
Go concurrencysiuyin
 
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in GolangOliver N
 
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's index
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's indexFOSDEM 2020: Querying over millions and billions of metrics with M3DB's index
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's indexRob Skillington
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetupsource{d}
 
Tuga IT 2017 - Redis
Tuga IT 2017 - RedisTuga IT 2017 - Redis
Tuga IT 2017 - RedisNuno Caneco
 
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...Rob Skillington
 
最近作ったN個のCPANモジュール Yokohama.pm #10
最近作ったN個のCPANモジュール Yokohama.pm #10最近作ったN個のCPANモジュール Yokohama.pm #10
最近作ったN個のCPANモジュール Yokohama.pm #10Masahiro Nagano
 
LCDS - State Presentation
LCDS - State PresentationLCDS - State Presentation
LCDS - State PresentationRuochun Tzeng
 
ゼロから作るパケット転送用OS (Internet Week 2014)
ゼロから作るパケット転送用OS (Internet Week 2014)ゼロから作るパケット転送用OS (Internet Week 2014)
ゼロから作るパケット転送用OS (Internet Week 2014)Hirochika Asai
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating languagejgrahamc
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright Andrei Alexandrescu
 
Specializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network StackSpecializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network StackKernel TLV
 

Tendances (19)

Networking and Go: An Epic Journey
Networking and Go: An Epic JourneyNetworking and Go: An Epic Journey
Networking and Go: An Epic Journey
 
MessagePack(msgpack): Compact and Fast Serialization Library
MessagePack(msgpack): Compact and Fast Serialization LibraryMessagePack(msgpack): Compact and Fast Serialization Library
MessagePack(msgpack): Compact and Fast Serialization Library
 
Go concurrency
Go concurrencyGo concurrency
Go concurrency
 
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in Golang
 
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's index
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's indexFOSDEM 2020: Querying over millions and billions of metrics with M3DB's index
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's index
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetup
 
Tuga IT 2017 - Redis
Tuga IT 2017 - RedisTuga IT 2017 - Redis
Tuga IT 2017 - Redis
 
Dafunctor
DafunctorDafunctor
Dafunctor
 
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
 
Golang design4concurrency
Golang design4concurrencyGolang design4concurrency
Golang design4concurrency
 
最近作ったN個のCPANモジュール Yokohama.pm #10
最近作ったN個のCPANモジュール Yokohama.pm #10最近作ったN個のCPANモジュール Yokohama.pm #10
最近作ったN個のCPANモジュール Yokohama.pm #10
 
Scapy
ScapyScapy
Scapy
 
LCDS - State Presentation
LCDS - State PresentationLCDS - State Presentation
LCDS - State Presentation
 
libpcap
libpcaplibpcap
libpcap
 
ゼロから作るパケット転送用OS (Internet Week 2014)
ゼロから作るパケット転送用OS (Internet Week 2014)ゼロから作るパケット転送用OS (Internet Week 2014)
ゼロから作るパケット転送用OS (Internet Week 2014)
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating language
 
Go on!
Go on!Go on!
Go on!
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 
Specializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network StackSpecializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network Stack
 

En vedette

MPI Introduction
MPI IntroductionMPI Introduction
MPI IntroductionRohit Banga
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interfaceMohit Raghuvanshi
 
Introduction to MPI
Introduction to MPI Introduction to MPI
Introduction to MPI Hanif Durad
 
Converged solutions for HPC and Big Data Analytics using Clusters and Clouds
Converged solutions for HPC and Big Data Analytics using Clusters and CloudsConverged solutions for HPC and Big Data Analytics using Clusters and Clouds
Converged solutions for HPC and Big Data Analytics using Clusters and Cloudsinside-BigData.com
 
Introduction to Linux #1
Introduction to Linux #1Introduction to Linux #1
Introduction to Linux #1UNIST
 
High Performance Computing using MPI
High Performance Computing using MPIHigh Performance Computing using MPI
High Performance Computing using MPIAnkit Mahato
 
The Business of Social Media
The Business of Social Media The Business of Social Media
The Business of Social Media Dave Kerpen
 
The hottest analysis tools for startups
The hottest analysis tools for startupsThe hottest analysis tools for startups
The hottest analysis tools for startupsLiane Siebenhaar
 
10 Steps of Project Management in Digital Agencies
10 Steps of Project Management in Digital Agencies 10 Steps of Project Management in Digital Agencies
10 Steps of Project Management in Digital Agencies Alemsah Ozturk
 
Lost in Cultural Translation
Lost in Cultural TranslationLost in Cultural Translation
Lost in Cultural TranslationVanessa Vela
 
All About Beer
All About Beer All About Beer
All About Beer Ethos3
 

En vedette (20)

Using MPI
Using MPIUsing MPI
Using MPI
 
MPI Introduction
MPI IntroductionMPI Introduction
MPI Introduction
 
MPI
MPIMPI
MPI
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interface
 
Introduction to MPI
Introduction to MPI Introduction to MPI
Introduction to MPI
 
Converged solutions for HPC and Big Data Analytics using Clusters and Clouds
Converged solutions for HPC and Big Data Analytics using Clusters and CloudsConverged solutions for HPC and Big Data Analytics using Clusters and Clouds
Converged solutions for HPC and Big Data Analytics using Clusters and Clouds
 
Amax Gpu Hpc
Amax Gpu HpcAmax Gpu Hpc
Amax Gpu Hpc
 
Mpi
Mpi Mpi
Mpi
 
Message passing interface
Message passing interfaceMessage passing interface
Message passing interface
 
Introduction to Linux #1
Introduction to Linux #1Introduction to Linux #1
Introduction to Linux #1
 
Open MPI 2
Open MPI 2Open MPI 2
Open MPI 2
 
High Performance Computing using MPI
High Performance Computing using MPIHigh Performance Computing using MPI
High Performance Computing using MPI
 
The Business of Social Media
The Business of Social Media The Business of Social Media
The Business of Social Media
 
The hottest analysis tools for startups
The hottest analysis tools for startupsThe hottest analysis tools for startups
The hottest analysis tools for startups
 
10 Steps of Project Management in Digital Agencies
10 Steps of Project Management in Digital Agencies 10 Steps of Project Management in Digital Agencies
10 Steps of Project Management in Digital Agencies
 
Lost in Cultural Translation
Lost in Cultural TranslationLost in Cultural Translation
Lost in Cultural Translation
 
Flyer
FlyerFlyer
Flyer
 
What is Big Data?
What is Big Data?What is Big Data?
What is Big Data?
 
Big data ppt
Big  data pptBig  data ppt
Big data ppt
 
All About Beer
All About Beer All About Beer
All About Beer
 

Similaire à Parallel programming using MPI

Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPIyaman dua
 
Lisandro dalcin-mpi4py
Lisandro dalcin-mpi4pyLisandro dalcin-mpi4py
Lisandro dalcin-mpi4pyA Jorge Garcia
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docxeugeniadean34240
 
Intro to MPI
Intro to MPIIntro to MPI
Intro to MPIjbp4444
 
"Используем MetricKit в бою" / Марина Звягина (Vivid Money)
"Используем MetricKit в бою" / Марина Звягина (Vivid Money)"Используем MetricKit в бою" / Марина Звягина (Vivid Money)
"Используем MetricKit в бою" / Марина Звягина (Vivid Money)Egor Petrov
 
Mote Mote Radio Communication
Mote Mote Radio CommunicationMote Mote Radio Communication
Mote Mote Radio CommunicationAnkit Singh
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On RandomnessRanel Padon
 
A nice 64-bit error in C
A  nice 64-bit error in CA  nice 64-bit error in C
A nice 64-bit error in CPVS-Studio
 
Parallel programming using MPI
Parallel programming using MPIParallel programming using MPI
Parallel programming using MPIAjit Nayak
 
TinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on SessionTinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on SessionRazvan Musaloiu-E.
 
Lecture no 3
Lecture no 3Lecture no 3
Lecture no 3hasi071
 
Directive-based approach to Heterogeneous Computing
Directive-based approach to Heterogeneous ComputingDirective-based approach to Heterogeneous Computing
Directive-based approach to Heterogeneous ComputingRuymán Reyes
 

Similaire à Parallel programming using MPI (20)

Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
mpi4py.pdf
mpi4py.pdfmpi4py.pdf
mpi4py.pdf
 
Parallel computing(2)
Parallel computing(2)Parallel computing(2)
Parallel computing(2)
 
Lisandro dalcin-mpi4py
Lisandro dalcin-mpi4pyLisandro dalcin-mpi4py
Lisandro dalcin-mpi4py
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
Intro to MPI
Intro to MPIIntro to MPI
Intro to MPI
 
"Используем MetricKit в бою" / Марина Звягина (Vivid Money)
"Используем MetricKit в бою" / Марина Звягина (Vivid Money)"Используем MetricKit в бою" / Марина Звягина (Vivid Money)
"Используем MetricKit в бою" / Марина Звягина (Vivid Money)
 
25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx
 
Mote Mote Radio Communication
Mote Mote Radio CommunicationMote Mote Radio Communication
Mote Mote Radio Communication
 
TinyOS 2.1 Tutorial: TOSSIM
TinyOS 2.1 Tutorial: TOSSIMTinyOS 2.1 Tutorial: TOSSIM
TinyOS 2.1 Tutorial: TOSSIM
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On Randomness
 
A nice 64-bit error in C
A  nice 64-bit error in CA  nice 64-bit error in C
A nice 64-bit error in C
 
Parallel programming using MPI
Parallel programming using MPIParallel programming using MPI
Parallel programming using MPI
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
6. TinyOS_2.pdf
6. TinyOS_2.pdf6. TinyOS_2.pdf
6. TinyOS_2.pdf
 
TinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on SessionTinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on Session
 
Lecture no 3
Lecture no 3Lecture no 3
Lecture no 3
 
Directive-based approach to Heterogeneous Computing
Directive-based approach to Heterogeneous ComputingDirective-based approach to Heterogeneous Computing
Directive-based approach to Heterogeneous Computing
 
DSP_Assign_1
DSP_Assign_1DSP_Assign_1
DSP_Assign_1
 
BASIC_MPI.ppt
BASIC_MPI.pptBASIC_MPI.ppt
BASIC_MPI.ppt
 

Plus de Majong DevJfu

9 - Architetture Software - SOA Cloud
9 - Architetture Software - SOA Cloud9 - Architetture Software - SOA Cloud
9 - Architetture Software - SOA CloudMajong DevJfu
 
8 - Architetture Software - Architecture centric processes
8 - Architetture Software - Architecture centric processes8 - Architetture Software - Architecture centric processes
8 - Architetture Software - Architecture centric processesMajong DevJfu
 
7 - Architetture Software - Software product line
7 - Architetture Software - Software product line7 - Architetture Software - Software product line
7 - Architetture Software - Software product lineMajong DevJfu
 
6 - Architetture Software - Model transformation
6 - Architetture Software - Model transformation6 - Architetture Software - Model transformation
6 - Architetture Software - Model transformationMajong DevJfu
 
5 - Architetture Software - Metamodelling and the Model Driven Architecture
5 - Architetture Software - Metamodelling and the Model Driven Architecture5 - Architetture Software - Metamodelling and the Model Driven Architecture
5 - Architetture Software - Metamodelling and the Model Driven ArchitectureMajong DevJfu
 
4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture PortfolioMajong DevJfu
 
3 - Architetture Software - Architectural styles
3 - Architetture Software - Architectural styles3 - Architetture Software - Architectural styles
3 - Architetture Software - Architectural stylesMajong DevJfu
 
2 - Architetture Software - Software architecture
2 - Architetture Software - Software architecture2 - Architetture Software - Software architecture
2 - Architetture Software - Software architectureMajong DevJfu
 
1 - Architetture Software - Software as a product
1 - Architetture Software - Software as a product1 - Architetture Software - Software as a product
1 - Architetture Software - Software as a productMajong DevJfu
 
10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural stylesMajong DevJfu
 

Plus de Majong DevJfu (20)

9 - Architetture Software - SOA Cloud
9 - Architetture Software - SOA Cloud9 - Architetture Software - SOA Cloud
9 - Architetture Software - SOA Cloud
 
8 - Architetture Software - Architecture centric processes
8 - Architetture Software - Architecture centric processes8 - Architetture Software - Architecture centric processes
8 - Architetture Software - Architecture centric processes
 
7 - Architetture Software - Software product line
7 - Architetture Software - Software product line7 - Architetture Software - Software product line
7 - Architetture Software - Software product line
 
6 - Architetture Software - Model transformation
6 - Architetture Software - Model transformation6 - Architetture Software - Model transformation
6 - Architetture Software - Model transformation
 
5 - Architetture Software - Metamodelling and the Model Driven Architecture
5 - Architetture Software - Metamodelling and the Model Driven Architecture5 - Architetture Software - Metamodelling and the Model Driven Architecture
5 - Architetture Software - Metamodelling and the Model Driven Architecture
 
4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio
 
3 - Architetture Software - Architectural styles
3 - Architetture Software - Architectural styles3 - Architetture Software - Architectural styles
3 - Architetture Software - Architectural styles
 
2 - Architetture Software - Software architecture
2 - Architetture Software - Software architecture2 - Architetture Software - Software architecture
2 - Architetture Software - Software architecture
 
1 - Architetture Software - Software as a product
1 - Architetture Software - Software as a product1 - Architetture Software - Software as a product
1 - Architetture Software - Software as a product
 
10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles
 
Uml3
Uml3Uml3
Uml3
 
Uml2
Uml2Uml2
Uml2
 
6
66
6
 
5
55
5
 
4 (uml basic)
4 (uml basic)4 (uml basic)
4 (uml basic)
 
3
33
3
 
2
22
2
 
1
11
1
 
Tmd template-sand
Tmd template-sandTmd template-sand
Tmd template-sand
 
26 standards
26 standards26 standards
26 standards
 

Parallel programming using MPI

  • 1. Parallel Programming using MPI Collective Communications Claudio Gheller CINECA c.gheller@cineca.it Collective Communications Collective Communications !"#$$%&'()*'#&+,'&-#.-'&/,),/0#%1,#2,10#(3++ !")..34,56,).. 10#(3++3+,'&,),(#$$%&'()*#0 Barrier Synchronization Broadcast Gather/Scatter Reduction (sum, max, prod, … ) 2 1
  • 2. Collective Communications Characteristics All processes must call the collective routine No non-blocking collective communication No tags 7)23+*,)&4,$#+*,322'('3&*, (#$$%&'()*'#&,$#43 3 Collective Communications MPI_Barrier Stop processes until all processes within a communicator reach the barrier Fortran: CALL MPI_BARRIER(comm, ierr) C: int MPI_Barrier(MPI_Comm comm) 4 2
  • 3. Collective Communications Barrier *: *; *< 8; 89 8= 8: 8< 89 8: 8; 8< 8= barrier barrier 89 8: 8; 8< 8= * 5 Collective Communications Broadcast (MPI_BCAST) One-to-all communication: same data sent from root process to all others in the communicator Fortran: INTEGER count, type, root, comm, ierr CALL MPI_BCAST(buf, count, type, root, comm, ierr) Buf array of type type C: int MPI_Bcast(void *buf, int count, MPI_Datatype, datatypem int root, MPI_Comm comm) All processes must specify same root, rank and comm 6 3
  • 4. Collective Communications Broadcast PROGRAM broad_cast INCLUDE 'mpif.h' INTEGER ierr, myid, nproc, root INTEGER status(MPI_STATUS_SIZE) REAL A(2) 89 CALL MPI_INIT(ierr) CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr) CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) ): root = 0 8: IF( myid .EQ. 0 ) THEN 89 ): a(1) = 2.0 a(2) = 4.0 ): END IF 8; CALL MPI_BCAST(a, 2, MPI_REAL, 0, ): MPI_COMM_WORLD, ierr) WRITE(6,*) myid, ': a(1)=', a(1), 'a(2)=', a(2) CALL MPI_FINALIZE(ierr) 8< END 7 Collective Communications Scatter / Gather 7()**30 >)*?30 sndbuf sndbuf sndbuf sndbuf sndbuf 89 89 ): ); )< )= 89 89 ): 8: 8: ); 8; 8; )< 8< 8< )= 89 ): 8: ); 8; )< 8< )= 89 89 ): ); )< )= rcvbuf rcvbuf rcvbuf rcvbuf rcvbuf 8 4
  • 5. Collective Communications MPI_Scatter One-to-all communication: different data sent from root process to all others in the communicator Fortran: CALL MPI_SCATTER(sndbuf, sndcount, sndtype, rcvbuf, rcvcount, rcvtype, root, comm, ierr) Arguments definition are like other MPI subroutine sndcount is the number of elements sent to each process, not the size of sndbuf, that should be sndcount times the number of process in the communicator The sender arguments are meaningful only for root 9 Collective Communications 10 5
  • 6. Collective Communications MPI_SCATTERV Usage – int MPI_Scatterv( void* sendbuf, /* in */ int* sendcounts, /* in */ int* displs, /* in */ MPI_Datatype sendtype, /* in */ void* recvbuf, /* in */ int recvcount, /* in */ MPI_Datatype recvtype, /* in */ int root, /* in */ MPI_Comm comm); /* in */ Description – Distributes individual messages from root to each process in communicator – Messages can have different sizes and displacements 11 Collective Communications 12 6
  • 7. Collective Communications MPI_Gather One-to-all communication: different data collected by the root process, from all others processes in the communicator. Is the opposite of Scatter Fortran: CALL MPI_GATHER(sndbuf, sndcount, sndtype, rcvbuf, rcvcount, rcvtype, root, comm, ierr) Arguments definition are like other MPI subroutine rcvcount is the number of elements collected from each process, not the size of rcvbuf, that should be rcvcount times the number of process in the communicator The receiver arguments are meaningful only for root 13 Collective Communications 14 7
  • 8. Collective Communications MPI_GATHERV Usage – int MPI_Gatherv( void* sendbuf, /* in */ int sendcount, /* in */ MPI_Datatype sendtype, /* in */ void* recvbuf, /* out */ int* recvcount, /* in */ int* displs, /* in */ MPI_Datatype recvtype, /* in */ int root, /* in */ MPI_Comm comm ); /* in */ Description – Collects individual messages from each process in communicator to the root process and store them in rank order – Messages can have different sizes and displacements 15 Collective Communications 16 8
  • 9. Collective Communications Scatter example PROGRAM scatter INCLUDE 'mpif.h' INTEGER ierr, myid, nproc, nsnd, I, root INTEGER status(MPI_STATUS_SIZE) REAL A(16), B(2) CALL MPI_INIT(ierr) CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr) CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) root = 0 IF( myid .eq. root ) THEN DO i = 1, 16 a(i) = REAL(i) END DO END IF nsnd = 2 CALL MPI_SCATTER(a, nsnd, MPI_REAL, b, nsnd, & MPI_REAL, root, MPI_COMM_WORLD, ierr) WRITE(6,*) myid, ': b(1)=', b(1), 'b(2)=', b(2) CALL MPI_FINALIZE(ierr) 17 Collective Communications Gather example PROGRAM gather INCLUDE 'mpif.h' INTEGER ierr, myid, nproc, nsnd, I, root INTEGER status(MPI_STATUS_SIZE) REAL A(16), B(2) CALL MPI_INIT(ierr) CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr) CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) root = 0 b(1) = REAL( myid ) b(2) = REAL( myid ) nsnd = 2 CALL MPI_GATHER(b, nsnd, MPI_REAL, a, nsnd, & MPI_REAL, root MPI_COMM_WORLD, ierr) IF( myid .eq. root ) THEN DO i = 1, (nsnd*nproc) WRITE(6,*) myid, ': a(i)=', a(i) END DO END IF CALL MPI_FINALIZE(ierr) 18 9
  • 10. Collective Communications MPI_Alltoall @#0*0)&A CALL MPI_ALLTOALL(sndbuf, sndcount, sndtype, rcvbuf, rcvcount, rcvtype, comm, ierr) 89 ): ); )< )= 89 ): 5: (: 4: 89 89 rcvbuf sndbuf 5: 5; 5< 5= ); 5; (; 4; 89 (: (; (< (= 89 )< 5< (< 4< 89 4: 4; 4< 4= 89 )= 5= (= 4= B306,%+32%.,*#,'$1.3$3&*,4)*),*0)&+1#+'*'#& 19 Collective Communications Reduction The reduction operation allow to: • Collect data from each process • Reduce the data to a single value • Store the result on the root processes • Store the result on all processes • Overlap of communication and computing 20 10
  • 11. Collective Communications Reduce, Parallel Sum 89 ): 5: 89 7) 75 8: ); 5; 8: 7) 75 7)C):D);D)<D)= 8; )< 5< 75C5:D5;D5<D5= 8; 7) 75 8< )= 5= 8< 7) 75 E34%(*'#&,2%&(*'#&,F#0G+,F'*?,)00)6+ #*?30,#130)*'#&A,10#4%(*H,$'&H,$)IH,)&4H,JK, 21 Collective Communications MPI_REDUCE and MPI_ALLREDUCE Fortran: MPI_REDUCE( snd_buf, rcv_buf, count, type, op, root, comm, ierr) snd_buf input array of type type containing local values. rcv_buf output array of type type containing global results Count (INTEGER) number of element of snd_buf and rcv_buf type (INTEGER) MPI type of snd_buf and rcv_buf op (INTEGER) parallel operation to be performed root (INTEGER) MPI id of the process storing the result comm (INTEGER) communicator of processes involved in the operation ierr (INTEGER) output, error code (if ierr=0 no error occours) MPI_ALLREDUCE( snd_buf, rcv_buf, count, type, op, comm, ierr) The argument root is missing, the result is stored to all processes. 22 11
  • 12. Collective Communications Predefined Reduction Operations MPI op Function MPI_MAX Maximum MPI_MIN Minimum MPI_SUM Sum MPI_PROD Product MPI_LAND Logical AND MPI_BAND Bitwise AND MPI_LOR Logical OR MPI_BOR Bitwise OR MPI_LXOR Logical exclusive OR MPI_BXOR Bitwise exclusive OR MPI_MAXLOC Maximum and location MPI_MINLOC Minimum and location 23 Collective Communications Reduce / 1 C: int MPI_Reduce(void * snd_buf, void * rcv_buf, int count, MPI_Datatype type, MPI_Op op, int root, MPI_Comm comm) int MPI_Allreduce(void * snd_buf, void * rcv_buf, int count, MPI_Datatype type, MPI_Op op, MPI_Comm comm) 24 12
  • 13. Collective Communications Reduce, example PROGRAM reduce INCLUDE 'mpif.h' INTEGER ierr, myid, nproc, root INTEGER status(MPI_STATUS_SIZE) REAL A(2), res(2) CALL MPI_INIT(ierr) CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr) CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) root = 0 a(1) = 2.0*myid a(2) = 4.0+myid CALL MPI_REDUCE(a, res, 2, MPI_REAL, MPI_SUM, root, & MPI_COMM_WORLD, ierr) IF( myid .EQ. 0 ) THEN WRITE(6,*) myid, ': res(1)=', res(1), 'res(2)=', res(2) END IF CALL MPI_FINALIZE(ierr) END 25 13