1 / 32

GWDG – Kurs Parallelrechner-Programmierung mit MPI MPI Kollektive Operationen

GWDG – Kurs Parallelrechner-Programmierung mit MPI MPI Kollektive Operationen. Oswald Haan ohaan@gwdg.de. Kollektive Operationen - Überblick. Kollektive Operationen werden von allen Tasks eines Kommunikators (z.B. MPI_COMM_WORLD) aufgerufen

Download Presentation

GWDG – Kurs Parallelrechner-Programmierung mit MPI MPI Kollektive Operationen

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GWDG – KursParallelrechner-Programmierung mit MPIMPIKollektive Operationen Oswald Haan ohaan@gwdg.de

  2. Kollektive Operationen - Überblick Kollektive Operationen werden von allen Tasks eines Kommunikators (z.B. MPI_COMM_WORLD) aufgerufen Intra-Kommunikator: alle Tasks gehören zu einer Gruppe Inter-Kommunikator: die Tasks bilden zwei getrennte Gruppen MPI_COMM_WORLD ist ein Intra-Kommunikator Kollektive Operationen können blockierend sein (z.B. MPI_BARRIER) oder je nach Implementierung blockierend oder nichtblockierend Parallelrechner-Programmierung mit MPI

  3. Klassifizierung der Kollektive Operationen MPI_BARRIER:Synchronisation MPI_BCAST: Senden von einer Task zuallenanderen Tasks (Broadcast) MPI_GATHER, MPI_GATHERV: Sammeln von Daten von allen Tasks auf einer Task MPI_SCATTER, MPI_SCATTERV: Verteilen von Dateneiner Task auf alle Tasks MPI_ALLGATHER, MPI_ALLGATHERV: Sammelnvon Daten von allen Tasks auf allen Tasks MPI_ALLTOALL, MPI_ALLTOALLV, MPI_ALLTOALLW:Austauschen von Datenzwischenallen Tasks MPI_ALLREDUCE, MPI_REDUCE:GlobaleReduktions-Operation wie SUM, MAX überalle Tasks, das Resultatgeht an alle Tasks oder nur eine Task MPI_REDUCE_SCATTER: Kombination von Reduktion und Verteilen MPI_SCAN, MPI_EXSCAN: Task ierhält das Ergebnis der Reduktion der Datenaller Tasks j mit jbzw. i einer → allealle → einenalle → alle Parallelrechner-Programmierung mit MPI

  4. Kollektive Operationen: Datenfluss Parallelrechner-Programmierung mit MPI

  5. Kollektive Operationen: Datenfluss alltoall Parallelrechner-Programmierung mit MPI

  6. MPI_BARRIER: Synchronisation MPI_BARRIER( comm ) IN commcommunicator(handle) MPI_BARRIER muss von allenTasksdesKommunikatorscommaufgerufenwerden. DerAufruf von MPI_BARRIER endeterst, wenn alle TasksdenAufrufabgesetzthaben. Parallelrechner-Programmierung mit MPI

  7. Synchronisation mit mpi4py comm.Barrier( ) IN commcommunicatore.g. MPI.COMM_WORLD MPI_BARRIER muss von allenTasksdesKommunikatorscommaufgerufenwerden. DerAufruf von MPI_BARRIER endeterst, wenn alle TasksdenAufrufabgesetzthaben. Parallelrechner-Programmierung mit MPI

  8. MPI_BCAST: Broadcast • MPI_BCAST( buffer, count, datatype, root, comm) • INOUT buffer startingaddress of buffer (choice) • IN countnumberof entries in buffer (non-negative integer) • IN datatype data type of buffer (handle) • IN rootrankof broadcast root (integer) • IN commcommunicator(handle) • Alle Tasksmüssen die gleichenWertefürroot und commangeben, • die durchcount und datatypefestgelegteDatenmengemuss bei allenTasksübereinstimmen Parallelrechner-Programmierung mit MPI

  9. Broadcast mit mpi4py robj = comm.bcast(sobj, root= 0) OUT robjpythonobject to be received on alltasks IN commcommunicatore.g MPI:COMM_WORLD IN sobjpythonobject to be sent from root IN rootrankof broadcast root (integer) comm.Bcast(ar, root= 0) IN commcommunicatore.g MPI:COMM_WORLD INOUT arnumpy array to be sent from root and to be received on alltasks IN rootrank of broadcast root (integer) Parallelrechner-Programmierung mit MPI

  10. MPI_GATHER: Sammeln auf root MPI_GATHER( sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) IN sendbufstartingaddressof send buffer(choice) IN sendcountnumberofelements in send buffer(non-negative integer) IN sendtypedatatype of send bufferelements (handle) OUT recvbufaddressofreceivebuffer (choice, significantonlyatroot) IN recvcountnumberofelementsforanysinglereceive (non-negative integer, significantonlyatroot) IN recvtypedatatype ofrecvbufferelements (handle,significantonlyatroot) IN root rank ofreceivingprocess (integer) IN commcommunicator(handle) Parallelrechner-Programmierung mit MPI

  11. Sammeln auf root mit mpi4py • robj = comm.gather(sendobj= sobj, recvobj=None, root= 0) • IN commcommunicator e.g. MPI:COMM_WORLD • IN sobjpythonobjecttobesent • OUT robjpythonobjectforgatheredelements(significantonly at root) • IN root rank ofreceivingprocess (integer) • comm.Gather(sar, rar, root= 0) • IN commcommunicator e.g. MPI:COMM_WORLD • IN sarnumpyarraytobesent • OUT rar numpyarrayforgatheredelements (significantonlyat root) • IN root rank ofreceivingprocess (integer) Parallelrechner-Programmierung mit MPI

  12. MPI_GATHER: Sammeln auf root • Alle Tasks müssen die gleichen Werte für root und commangeben • die durch sendcountund sendypefestgelegte Datenmenge muss bei allen Tasks mit der auf dem root-Task durch recvcount und recvtype festgelegten Datenmenge übereinstimmen • Der recv-Buffer wird auf allen nicht-root Tasks ignoriert Vor MPI_GATHER Nach MPI_GATHER recvbufbuf sendbuf recvbufbuf sendbuf Task 0 Task 1 (root) Task 2 Parallelrechner-Programmierung mit MPI

  13. MPI_GATHER: mit MPI_IN_PLACE auf root nicht-root-Task MPI_GATHER( sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) root-Task MPI_GATHER(MPI_IN_PLACE, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) Vor MPI_GATHER Nach MPI_GATHER recvbufbuf sendbuf recvbufbuf sendbuf Task 0 Task 1 (root) Task 2 Parallelrechner-Programmierung mit MPI

  14. MPI_GATHERV: Sammeln auf root MPI_GATHERV( sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root,comm) IN sendbuf starting address of send buffer (choice) IN sendcount number of elements in send buffer (non-negative integer) IN sendtype data type of send buffer elements (handle) OUT recvbuf address of receive buffer (choice, significant only at root) IN recvcounts non-negative integer array (of length group size) containing the number of elements that are received from each process (significant only at root) IN displs integer array (of length group size). Entry ispecifies the displacement relative to recvbuf at which to place the incoming data from process i (significant only at root) IN recvtype data type of recvbuffer elements (handle,significantonly at root) IN root rank of receiving process (integer) IN comm communicator (handle) Parallelrechner-Programmierung mit MPI

  15. MPI_GATHERV : Sammeln auf root • die durch sendcountund sendypefestgelegte Datenmenge auf Task i muss mit der auf dem root-Task durch recvcounts(i) und recvtype festgelegten Datenmenge übereinstimmen • Die Daten von Task i werden mit dem Abstand displs(i) Elemente vom Typ recvtype von der Adresse recvbuf gespeichert • Der recv-Buffer wird auf allen nicht-root Tasks ignoriert Vor MPI_GATHERV Nach MPI_GATHERV recvbufbuf sendbuf recvbufbuf sendbuf Task 0 Task 1 (root) Task 2 Parallelrechner-Programmierung mit MPI

  16. MPI_SCATTER: Verteilen von root MPI_SCATTER( sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) IN sendbufaddressof send buffer(choice, significantonlyatroot) IN sendcountnumberofelementssenttoeachprocess (non-negative integer, significantonlyatroot) IN sendtypedatatype of send bufferelements (handle, significantonlyatroot) OUT recvbufaddressofreceivebuffer(choice) IN recvcountnumberofelements in receivebuffer (non-negative integer) IN recvtypedatatype ofreceivebufferelements (handle) IN root rank ofsendingprocess (integer) IN commcommunicator(handle) Parallelrechner-Programmierung mit MPI

  17. Verteilen von root mit mpi4py • robj = comm.scatter(sendobj= sobj, recvobj=None, root= 0) • IN commcommunicator e.g. MPI:COMM_WORLD • IN sobjpythonobjecttobescatteredfromroot • (significantonly at root) • OUT robjpythonobjectforscatteredpartsofsobj • IN root rank ofreceivingprocess (integer) • comm.Scatter(sar, rar, root= 0) • IN commcommunicator e.g. MPI:COMM_WORLD • IN sarnumpyarraytobescatteredfromroot • (significantonly at root) • OUT rar numpyarrayforreceivingscatteredpartsofsar • IN root rank ofreceivingprocess (integer) Parallelrechner-Programmierung mit MPI

  18. MPI_SCATTER: Verteilen von root • Alle Tasks müssen die gleichen Werte für root und commangeben • die durch recvcountund recvtypefestgelegte Datenmenge muss bei allen Tasks mit der auf dem root-Task durch sendcount und sendtype festgelegten Datenmenge übereinstimmen • Der send-Buffer wird auf allen nicht-root Tasks ignoriert Vor MPI_SCATTER Nach MPI_SCATTER sendbuf recvbufbuf sendbuf recvbufbuf Task 0 Task 1 (root) Task 2 Parallelrechner-Programmierung mit MPI

  19. MPI_ALLGATHER: Sammeln auf alle Tasks MPI_ALLGATHER( sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) IN sendbufstartingaddress of sendbuffer (choice) IN sendcountnumberof elements in sendbuffer (non-negative integer) IN sendtype data type of sendbuffer elements (handle) OUT recvbufaddressof receivebuffer (choice) IN recvcountnumberof elementsreceived from anyprocess (nonnegativeinteger) IN recvtype data type of receivebuffer elements (handle) IN commcommunicator(handle) Parallelrechner-Programmierung mit MPI

  20. MPI_ALLGATHER: Sammeln auf root • Alle Tasks müssen die gleichen Werte für commangeben • die durch sendcountund sendypefestgelegte Datenmenge muss bei allen Tasks mit der durch recvcount und recvtype festgelegten Datenmenge übereinstimmen Vor MPI_ALLGATHER Nach MPI_ALLGATHER recvbufbuf sendbuf recvbufbuf sendbuf Task 0 Task 1 Task 2 Parallelrechner-Programmierung mit MPI

  21. MPI_ALLGATHER mit MPI_IN_PLACE MPI_ALLGATHER(MPI_IN_PLACE, sendcount, sendtype, recvbuf, recvcount,recvtype, comm) Vor MPI_ALLGATHER Nach MPI_ALLGATHER recvbufbuf sendbuf recvbufbuf sendbuf Task 0 Task 1 Task 2 Parallelrechner-Programmierung mit MPI

  22. MPI_ALLGATHERV: Sammeln auf alle Tasks MPI_ALLGATHERV( sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs,recvtype, comm) IN sendbufstartingaddress of sendbuffer (choice) IN sendcountnumberof elements in sendbuffer (non-negative integer) IN sendtype data type of sendbuffer elements (handle) OUT recvbufaddressof receivebuffer (choice) IN recvcounts non-negative integer array (of length group size) containing the number of elements that are received from each process (significant only at root) IN displs integer array (of length group size). Entry ispecifies the displacement relative to recvbufat which to place the incoming data from process i IN recvtype data type of receivebuffer elements (handle) IN commcommunicator(handle) Parallelrechner-Programmierung mit MPI

  23. MPI_ALLTOALL: Sammeln und Verteilen MPI_ALLTOALL(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) IN sendbufstartingaddressof send buffer(choice) IN sendcountnumberofelementssenttoeachprocess (non-negative integer) IN sendtypedatatype of send bufferelements (handle) OUT recvbufaddressofreceivebuffer(choice) IN recvcountnumberofelementsreceivedfromanyprocess (nonnegative integer) IN recvtypedatatype ofreceivebufferelements (handle) IN commcommunicator(handle) Parallelrechner-Programmierung mit MPI

  24. MPI_ALLTOALL: Sammeln und Verteilen • Alle Tasks müssen die gleichen Werte für comm angeben • die durch sendcount und sendype festgelegte Datenmenge muss bei allen Tasks gleich sein und mit der durch recvcount und recvtype festgelegten Datenmenge übereinstimmen Vor MPI_ALLTOALL Nach MPI_ALLTOALL recvbufbuf sendbuf 0 0 0 Task 0 0 1 2 1 1 1 Task 1 0 1 2 Task 2 2 2 2 0 1 2 Parallelrechner-Programmierung mit MPI

  25. Reduktions-Operationen Operationen, die Daten von allen Tasks zu einem einzigen Ergebnis verarbeiten, wie Summe, Minimum etc. Vordefinierte oder eigene Operationen möglich MPI_REDUCE: Ergebnis wird auf root gespeichert MPI_ALLREDUCE: Ergebnis wird auf allen Tasks gespeichert MPI_REDUCE_SCATTER, MPI_REDUCE_SCATTER_BLOCK: n Ergebnisse werden auf n Tasks verteilt MPI_SCAN, MPI_EXSCAN: Partielle Ergebnisse werden auf die Tasks verteilt Parallelrechner-Programmierung mit MPI

  26. Vordefinierte Reduktions-Operationen Name Meaning (fortran,c) (mpi4py) MPI_MAX MPI.MAX maximum MPI_MIN MPI.MIN minimum MPI_SUM MPI.SUM sum MPI_PROD MPI.PROD product MPI_LAND MPI.LAND logicaland MPI_BAND MPI.BAND bit-wiseand MPI_LOR MPI.LOR logicalor MPI_BOR MPI.BOR bit-wiseor MPI_LXOR MPI.LXOR logicalexclusiveor (xor) MPI_BXOR MPI.BXOR bit-wiseexclusiveor (xor) MPI_MAXLOC MPI.MAXLOC maxvalueandlocation MPI_MINLOC MPI.MINLOC min valueandlocation Parallelrechner-Programmierung mit MPI

  27. Reduktions-Operationen MPI_REDUCE( sendbuf, recvbuf, count, datatype, op, root, comm) IN sendbufaddressof sendbuffer (choice) OUT recvbufaddressof receivebuffer (choice, significantonlyatroot) IN countnumberof elements in sendbuffer (non-negative integer) IN datatype data type of elements of sendbuffer (handle) IN op reduce operation (handle) IN rootrankof rootprocess (integer) IN commcommunicator(handle) recvbufbuf sendbuf A0 A1 Task 0 A0opA0opA0 A1 opA1opA1 Task 1 (root) A0 A1 Task 2 A0 A1 Parallelrechner-Programmierung mit MPI

  28. Reduktions-Operationen mit mpi4py • robj = comm.reduce(sendobj= sobj, recvobj=None, op=oper,root= 0) • IN commcommunicator e.g. MPI.COMM_WORLD • IN sobjpythonobjecttobereduced • OUT robjpythonobjectforresultofreduction • (significantonly at root) • IN operreductionoperation, e.g. MPI.SUM • IN root rank ofreceivingprocess (integer) • comm.Reduce(sar, rar,op=operroot= 0) • IN commcommunicator e.g. MPI.COMM_WORLD • IN sarnumpyarraytobereduced • OUT rar numpyarrayforresultofreduction • (significantonly at root) • IN operreductionoperation, e.g. MPI.SUM • IN root rank ofreceivingprocess (integer) Parallelrechner-Programmierung mit MPI

  29. Reduktions-Operationen MPI_ALLREDUCE( sendbuf, recvbuf, count, datatype, op, comm) recvbufbuf sendbuf A0opA0opA0 A1 opA1opA1 A0 A1 Task 0 A0opA0opA0 A1 opA1opA1 Task 1 A0 A1 Task 2 A0opA0opA0 A1 opA1opA1 A0 A1 Parallelrechner-Programmierung mit MPI

  30. Reduktions-Operationen MPI_REDUCE_SCATTER( sendbuf, recvbuf, recvcounts, datatype, op, comm) IN sendbuf starting address of send buffer (choice) OUT recvbuf starting address of receive buffer (choice) IN recvcounts non-negative integer array (of length group size) specifying the number of elements of the result distributed to each process. IN datatype data type of elements of send and receive buffers (handle) IN op operation (handle) IN comm communicator (handle) Parallelrechner-Programmierung mit MPI

  31. Reduktions-Operationen MPI_REDUCE_SCATTER_BLOCK( sendbuf, recvbuf, recvcount, datatype, op, comm) z.B. recvcount = 2, op = MPI_MAX recvbufbuf sendbuf Max(A0, A0,A0) Max(A1,A1,A1) A0 A1 A2 A3 A4 A5 Task 0 Max(A2, A2,A2 ) Max(A3, A3,A3) A0 A1 A2 A3 A4 A5 Task 1 Task 2 A0 A1 A2 A3 A4 A5 Max(A4, A4,A4) Max(A5, A5,A5) Parallelrechner-Programmierung mit MPI

  32. Reduktions-Operationen MPI_SCAN( sendbuf, recvbuf, count, datatype, op, comm) recvbufbuf sendbuf A0 A1 A0 A1 Task 0 A0opA0 A1 opA1 Task 1 A0 A1 Task 2 A0opA0opA0 A1 opA1opA1 A0 A1 Parallelrechner-Programmierung mit MPI

More Related