SlideShare a Scribd company logo
1 of 31
2a.1
Message-Passing Computing
More MPI routines:
Collective routines
Synchronous routines
Non-blocking routines
ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, 2009.
2a.2
Collective message-passing routines
Have routines that send message(s) to a group
of processes or receive message(s) from a
group of processes
Higher efficiency than separate point-to-point
routines although routines not absolutely
necessary.
2a.3
Collective Communication
Involves set of processes, defined by an intra-communicator.
Message tags not present. Principal collective operations:
• MPI_Bcast() - Broadcast from root to all other processes
• MPI_Gather() - Gather values for group of processes
• MPI_Scatter() - Scatters buffer in parts to group of processes
• MPI_Alltoall() - Sends data from all processes to all processes
• MPI_Reduce() - Combine values on all processes to single value
• MPI_Reduce_scatter() - Combine values and scatter results
• MPI_Scan()- Compute prefix reductions of data on processes
• MPI_Barrier() - A means of synchronizing processes by stopping
each one until they all have reached a specific “barrier” call.
MPI broadcast operation
2a.4
Sending same message to all processes in communicator.
Multicast - sending same message to defined group of
processes.
MPI_Bcast parameters
2a.5
Basic MPI scatter operation
2a.6
Sending each element of an array in root process to a
separate process. Contents of ith location of array sent to ith
process.
MPI scatter parameters
2a.7
• Simplest scatter would be as illustrated
which one element of an array is sent to
different processes.
• Extension provided in the MPI_Scatter()
routine is to send a fixed number of
contiguous elements to each process.
2a.8
Scattering contiguous groups of
elements to each process
2a.9
Example
In the following code, size of send buffer is given by 100 *
<number of processes> and 100 contiguous elements are
send to each process:
main (int argc, char *argv[]) {
int size, *sendbuf, recvbuf[100]; /* for each process */
MPI_Init(&argc, &argv); /* initialize MPI */
MPI_Comm_size(MPI_COMM_WORLD, &size);
sendbuf = (int *)malloc(size*100*sizeof(int));
.
MPI_Scatter(sendbuf,100,MPI_INT,recvbuf,100,MPI_INT,0,
MPI_COMM_WORLD);
.
MPI_Finalize(); /* terminate MPI */
}
2a.10
Gather
2.11
Having one process collect individual values
from set of processes.
Gather parameters
2a.12
2a.13
Gather Example
To gather items from group of processes into process 0, using
dynamically allocated memory in root process:
int data[10]; /*data to be gathered from
processes*/
MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* find rank */
if (myrank == 0) {
MPI_Comm_size(MPI_COMM_WORLD, &grp_size); /*find group
size*/
buf = (int *)malloc(grp_size*10*sizeof (int)); /*alloc.
mem*/
}
MPI_Gather(data,10,MPI_INT,buf,grp_size*10,MPI_INT,0,MPI_COMM_
WORLD) ;
…
MPI_Gather() gathers from all processes, including root.
2a.14
Reduce
Gather operation combined with specified arithmetic/logical
operation.
Example: Values could be gathered and then added together by
root:
Reduce parameters
2a.15
2a.16
Reduce - operations
MPI_Reduce(*sendbuf,*recvbuf,count,datatype,op,root,comm)
Parameters:
*sendbuf send buffer address
*recvbuf receive buffer address
count number of send buffer elements
datatype data type of send elements
op reduce operation.
Several operations, including
MPI_MAX Maximum
MPI_MIN Minimum
MPI_SUM Sum
MPI_PROD Product
root root process rank for result
comm communicator
2a.17
Sample MPI program with
collective routines
#include “mpi.h”
#include <stdio.h>
#include <math.h>
#define MAXSIZE 1000
void main(int argc, char *argv) {
int myid, numprocs, data[MAXSIZE], i, x, low, high, myresult, result;
char fn[255];
char *fp;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
if (myid == 0) { /* Open input file and initialize data */
strcpy(fn,getenv(“HOME”));
strcat(fn,”/MPI/rand_data.txt”);
if ((fp = fopen(fn,”r”)) == NULL) {
printf(“Can’t open the input file: %snn”, fn);
exit(1);
}
for(i = 0; i < MAXSIZE; i++) fscanf(fp,”%d”, &data[i]);
}
MPI_Bcast(data, MAXSIZE, MPI_INT, 0, MPI_COMM_WORLD); /* broadcast data */
x = n/nproc; /* Add my portion Of data */
low = myid * x;
high = low + x;
for(i = low; i < high; i++)
myresult += data[i];
printf(“I got %d from %dn”, myresult, myid); /* Compute global sum */
MPI_Reduce(&myresult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
if (myid == 0) printf(“The sum is %d.n”, result);
MPI_Finalize();
}
Collective routines
General features
• Performed on a group of processes, identified by a
communicator
• Substitute for a sequence of point-to-point calls
• Communications are locally blocking
• Synchronization is not guaranteed (implementation
dependent)
• Some routines use a root process to originate or receive all
data
• Data amounts must exactly match
• Many variations to basic categories
• No message tags are needed
2a.18
2a.19
Barrier
Block process until all processes have called it.
Synchronous operation.
MPI_Barrier(comm)
Communicator
2a.20
Synchronous Message Passing
Routines that return when message transfer completed.
Synchronous send routine
• Waits until complete message can be accepted by the
receiving process before sending the message.
In MPI, MPI_SSend() routine.
Synchronous receive routine
• Waits until the message it is expecting arrives.
In MPI, actually the regular MPI_recv() routine.
2a.21
Synchronous Message Passing
Synchronous message-passing routines intrinsically
perform two actions:
• They transfer data and
• They synchronize processes.
2a.22
Synchronous Ssend() and recv() using 3-way
protocol
Process 1 Process 2
Ssend();
recv();
Suspend
Time
process
Acknowledgment
MessageBoth processes
continue
(a) When send() occurs before recv()
Process 1 Process 2
recv();
Ssend();
Suspend
Time
process
Acknowledgment
MessageBoth processes
continue
(b) When recv() occurs before send()
Request to send
Request to send
2a.23
Parameters of synchronous send
(same as blocking send)
MPI_Ssend(buf, count, datatype, dest, tag, comm)
Address of
Number of items
Datatype of
Rank of destination
Message tag
Communicator
send buffer
to send
each item
process
2a.24
Asynchronous Message Passing
• Routines that do not wait for actions to complete before
returning. Usually require local storage for messages.
• More than one version depending upon the actual
semantics for returning.
• In general, they do not synchronize processes but allow
processes to move forward sooner.
• Must be used with care.
2a.25
MPI Definitions of Blocking and Non-
Blocking
• Blocking - return after their local actions complete, though
the message transfer may not have been completed.
Sometimes called locally blocking.
• Non-blocking - return immediately (asynchronous)
Non-blocking assumes that data storage used for transfer
not modified by subsequent statements prior to being
used for transfer, and it is left to the programmer to
ensure this.
Blocking/non-blocking terms may have different
interpretations in other systems.
2a.26
MPI Nonblocking Routines
• Non-blocking send - MPI_Isend() - will return
“immediately” even before source location is
safe to be altered.
• Non-blocking receive - MPI_Irecv() - will
return even if no message to accept.
2a.27
Nonblocking Routine Formats
MPI_Isend(buf,count,datatype,dest,tag,comm,request)
MPI_Irecv(buf,count,datatype,source,tag,comm, request)
Completion detected by MPI_Wait() and MPI_Test().
MPI_Wait() waits until operation completed and returns then.
MPI_Test() returns with flag set indicating whether operation completed
at that time.
Need to know whether particular operation completed.
Determined by accessing request parameter.
2a.28
Example
To send an integer x from process 0 to process 1
and allow process 0 to continue:
MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* find rank */
if (myrank == 0) {
int x;
MPI_Isend(&x,1,MPI_INT, 1, msgtag, MPI_COMM_WORLD, req1);
compute();
MPI_Wait(req1, status);
} else if (myrank == 1) {
int x;
MPI_Recv(&x,1,MPI_INT,0,msgtag, MPI_COMM_WORLD, status);
}
2a.29
How message-passing routines return
before message transfer completed
Process 1 Process 2
send();
recv();
Message buffer
Read
message buffer
Continue
process
Time
Message buffer needed between source and
destination to hold message:
2a.30
Asynchronous (blocking) routines
changing to synchronous routines
• Message buffers only of finite length
• A point could be reached when send routine held
up because all available buffer space exhausted.
• Then, send routine will wait until storage becomes
re-available - i.e. routine will behave as a
synchronous routine.
2a.31
Next topic
• Parallel Algorithms
Other MPI features will be introduced as we
need them.

More Related Content

What's hot

Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Neena R Krishna
 
process management
 process management process management
process managementAshish Kumar
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationGift Kaliza
 
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...Antonio Garrote Hernández
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interfaceMohit Raghuvanshi
 
(Slides) Task scheduling algorithm for multicore processor system for minimiz...
(Slides) Task scheduling algorithm for multicore processor system for minimiz...(Slides) Task scheduling algorithm for multicore processor system for minimiz...
(Slides) Task scheduling algorithm for multicore processor system for minimiz...Naoki Shibata
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationMohd Tousif
 
4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architecturesIslam Samir
 
Move Message Passing Interface Applications to the Next Level
Move Message Passing Interface Applications to the Next LevelMove Message Passing Interface Applications to the Next Level
Move Message Passing Interface Applications to the Next LevelIntel® Software
 
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time SystemsSara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systemsknowdiff
 
Linux kernel development ch4
Linux kernel development   ch4Linux kernel development   ch4
Linux kernel development ch4huangachou
 
MPI Presentation
MPI PresentationMPI Presentation
MPI PresentationTayfun Sen
 
Processes and Thread OS_Tanenbaum_3e
Processes and Thread OS_Tanenbaum_3eProcesses and Thread OS_Tanenbaum_3e
Processes and Thread OS_Tanenbaum_3eLe Gia Hoang
 

What's hot (20)

MPI Tutorial
MPI TutorialMPI Tutorial
MPI Tutorial
 
Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...
 
process management
 process management process management
process management
 
Chapter 6 pc
Chapter 6 pcChapter 6 pc
Chapter 6 pc
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
 
3 process management
3 process management3 process management
3 process management
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interface
 
Ch4
Ch4Ch4
Ch4
 
(Slides) Task scheduling algorithm for multicore processor system for minimiz...
(Slides) Task scheduling algorithm for multicore processor system for minimiz...(Slides) Task scheduling algorithm for multicore processor system for minimiz...
(Slides) Task scheduling algorithm for multicore processor system for minimiz...
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures
 
Move Message Passing Interface Applications to the Next Level
Move Message Passing Interface Applications to the Next LevelMove Message Passing Interface Applications to the Next Level
Move Message Passing Interface Applications to the Next Level
 
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time SystemsSara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
 
Linux kernel development ch4
Linux kernel development   ch4Linux kernel development   ch4
Linux kernel development ch4
 
MPI Presentation
MPI PresentationMPI Presentation
MPI Presentation
 
Processes and Thread OS_Tanenbaum_3e
Processes and Thread OS_Tanenbaum_3eProcesses and Thread OS_Tanenbaum_3e
Processes and Thread OS_Tanenbaum_3e
 
Ch5 process synchronization
Ch5   process synchronizationCh5   process synchronization
Ch5 process synchronization
 
Chapter 6 synchronization
Chapter 6 synchronizationChapter 6 synchronization
Chapter 6 synchronization
 
1844 1849
1844 18491844 1849
1844 1849
 

Viewers also liked

Introduction to Parallel Programming
Introduction to Parallel ProgrammingIntroduction to Parallel Programming
Introduction to Parallel ProgrammingUNIST
 
병렬처리와 성능향상
병렬처리와 성능향상병렬처리와 성능향상
병렬처리와 성능향상shaderx
 
MPI Introduction
MPI IntroductionMPI Introduction
MPI IntroductionRohit Banga
 
Parallel programming using MPI
Parallel programming using MPIParallel programming using MPI
Parallel programming using MPIMajong DevJfu
 
Himti uin jakarta
Himti uin jakartaHimti uin jakarta
Himti uin jakartaAzka Faridy
 
第3回twitter研究会「閉会の挨拶」
第3回twitter研究会「閉会の挨拶」第3回twitter研究会「閉会の挨拶」
第3回twitter研究会「閉会の挨拶」Tomohiro Nishitani
 
Exposed_ The Secret Life of Roots _ United States Botanic Garden
Exposed_ The Secret Life of Roots _ United States Botanic GardenExposed_ The Secret Life of Roots _ United States Botanic Garden
Exposed_ The Secret Life of Roots _ United States Botanic Gardenjerry_d_glover
 

Viewers also liked (20)

Using MPI
Using MPIUsing MPI
Using MPI
 
Introduction to Parallel Programming
Introduction to Parallel ProgrammingIntroduction to Parallel Programming
Introduction to Parallel Programming
 
병렬처리와 성능향상
병렬처리와 성능향상병렬처리와 성능향상
병렬처리와 성능향상
 
MPI Introduction
MPI IntroductionMPI Introduction
MPI Introduction
 
Parallel programming using MPI
Parallel programming using MPIParallel programming using MPI
Parallel programming using MPI
 
Mpi
Mpi Mpi
Mpi
 
December 2012 announcements
December 2012 announcementsDecember 2012 announcements
December 2012 announcements
 
February 2013 announcements
February 2013 announcementsFebruary 2013 announcements
February 2013 announcements
 
Announcements for Feb 19 2012
Announcements for Feb 19 2012Announcements for Feb 19 2012
Announcements for Feb 19 2012
 
November 2012 announcements
November 2012 announcementsNovember 2012 announcements
November 2012 announcements
 
Himti uin jakarta
Himti uin jakartaHimti uin jakarta
Himti uin jakarta
 
September 2012 announcements
September 2012 announcementsSeptember 2012 announcements
September 2012 announcements
 
Announcements for june 2013
Announcements for june 2013Announcements for june 2013
Announcements for june 2013
 
September 2012 announcements
September 2012 announcementsSeptember 2012 announcements
September 2012 announcements
 
第3回twitter研究会「閉会の挨拶」
第3回twitter研究会「閉会の挨拶」第3回twitter研究会「閉会の挨拶」
第3回twitter研究会「閉会の挨拶」
 
Announcements for june 2014
Announcements for june 2014Announcements for june 2014
Announcements for june 2014
 
Announcements for june 2013
Announcements for june 2013Announcements for june 2013
Announcements for june 2013
 
November 2012 announcements
November 2012 announcementsNovember 2012 announcements
November 2012 announcements
 
Exposed_ The Secret Life of Roots _ United States Botanic Garden
Exposed_ The Secret Life of Roots _ United States Botanic GardenExposed_ The Secret Life of Roots _ United States Botanic Garden
Exposed_ The Secret Life of Roots _ United States Botanic Garden
 
Announcements for june 2013
Announcements for june 2013Announcements for june 2013
Announcements for june 2013
 

Similar to Open MPI 2 (20)

Programming using MPI and OpenMP
Programming using MPI and OpenMPProgramming using MPI and OpenMP
Programming using MPI and OpenMP
 
Chapter 3 - Processes
Chapter 3 - ProcessesChapter 3 - Processes
Chapter 3 - Processes
 
Open MPI
Open MPIOpen MPI
Open MPI
 
3 processes
3 processes3 processes
3 processes
 
Ch4 OS
Ch4 OSCh4 OS
Ch4 OS
 
OS_Ch4
OS_Ch4OS_Ch4
OS_Ch4
 
Process
ProcessProcess
Process
 
OSCh4
OSCh4OSCh4
OSCh4
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
MPI
MPIMPI
MPI
 
Intro to MPI
Intro to MPIIntro to MPI
Intro to MPI
 
25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx
 
More mpi4py
More mpi4pyMore mpi4py
More mpi4py
 
Parallel computing(2)
Parallel computing(2)Parallel computing(2)
Parallel computing(2)
 
Message passing Programing and MPI.
Message passing Programing and MPI.Message passing Programing and MPI.
Message passing Programing and MPI.
 
slides8 SharedMemory.ppt
slides8 SharedMemory.pptslides8 SharedMemory.ppt
slides8 SharedMemory.ppt
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
OSLec 4& 5(Processesinoperatingsystem).ppt
OSLec 4& 5(Processesinoperatingsystem).pptOSLec 4& 5(Processesinoperatingsystem).ppt
OSLec 4& 5(Processesinoperatingsystem).ppt
 
Ch3
Ch3Ch3
Ch3
 
MPI
MPIMPI
MPI
 

More from Anshul Sharma

More from Anshul Sharma (11)

Understanding concurrency
Understanding concurrencyUnderstanding concurrency
Understanding concurrency
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Programming using Open Mp
Programming using Open MpProgramming using Open Mp
Programming using Open Mp
 
Paralle programming 2
Paralle programming 2Paralle programming 2
Paralle programming 2
 
Parallel programming
Parallel programmingParallel programming
Parallel programming
 
Cuda 3
Cuda 3Cuda 3
Cuda 3
 
Cuda 2
Cuda 2Cuda 2
Cuda 2
 
Cuda intro
Cuda introCuda intro
Cuda intro
 
Des
DesDes
Des
 
Intoduction to Linux
Intoduction to LinuxIntoduction to Linux
Intoduction to Linux
 
GCC
GCCGCC
GCC
 

Recently uploaded

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

Open MPI 2

  • 1. 2a.1 Message-Passing Computing More MPI routines: Collective routines Synchronous routines Non-blocking routines ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, 2009.
  • 2. 2a.2 Collective message-passing routines Have routines that send message(s) to a group of processes or receive message(s) from a group of processes Higher efficiency than separate point-to-point routines although routines not absolutely necessary.
  • 3. 2a.3 Collective Communication Involves set of processes, defined by an intra-communicator. Message tags not present. Principal collective operations: • MPI_Bcast() - Broadcast from root to all other processes • MPI_Gather() - Gather values for group of processes • MPI_Scatter() - Scatters buffer in parts to group of processes • MPI_Alltoall() - Sends data from all processes to all processes • MPI_Reduce() - Combine values on all processes to single value • MPI_Reduce_scatter() - Combine values and scatter results • MPI_Scan()- Compute prefix reductions of data on processes • MPI_Barrier() - A means of synchronizing processes by stopping each one until they all have reached a specific “barrier” call.
  • 4. MPI broadcast operation 2a.4 Sending same message to all processes in communicator. Multicast - sending same message to defined group of processes.
  • 6. Basic MPI scatter operation 2a.6 Sending each element of an array in root process to a separate process. Contents of ith location of array sent to ith process.
  • 8. • Simplest scatter would be as illustrated which one element of an array is sent to different processes. • Extension provided in the MPI_Scatter() routine is to send a fixed number of contiguous elements to each process. 2a.8
  • 9. Scattering contiguous groups of elements to each process 2a.9
  • 10. Example In the following code, size of send buffer is given by 100 * <number of processes> and 100 contiguous elements are send to each process: main (int argc, char *argv[]) { int size, *sendbuf, recvbuf[100]; /* for each process */ MPI_Init(&argc, &argv); /* initialize MPI */ MPI_Comm_size(MPI_COMM_WORLD, &size); sendbuf = (int *)malloc(size*100*sizeof(int)); . MPI_Scatter(sendbuf,100,MPI_INT,recvbuf,100,MPI_INT,0, MPI_COMM_WORLD); . MPI_Finalize(); /* terminate MPI */ } 2a.10
  • 11. Gather 2.11 Having one process collect individual values from set of processes.
  • 13. 2a.13 Gather Example To gather items from group of processes into process 0, using dynamically allocated memory in root process: int data[10]; /*data to be gathered from processes*/ MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* find rank */ if (myrank == 0) { MPI_Comm_size(MPI_COMM_WORLD, &grp_size); /*find group size*/ buf = (int *)malloc(grp_size*10*sizeof (int)); /*alloc. mem*/ } MPI_Gather(data,10,MPI_INT,buf,grp_size*10,MPI_INT,0,MPI_COMM_ WORLD) ; … MPI_Gather() gathers from all processes, including root.
  • 14. 2a.14 Reduce Gather operation combined with specified arithmetic/logical operation. Example: Values could be gathered and then added together by root:
  • 16. 2a.16 Reduce - operations MPI_Reduce(*sendbuf,*recvbuf,count,datatype,op,root,comm) Parameters: *sendbuf send buffer address *recvbuf receive buffer address count number of send buffer elements datatype data type of send elements op reduce operation. Several operations, including MPI_MAX Maximum MPI_MIN Minimum MPI_SUM Sum MPI_PROD Product root root process rank for result comm communicator
  • 17. 2a.17 Sample MPI program with collective routines #include “mpi.h” #include <stdio.h> #include <math.h> #define MAXSIZE 1000 void main(int argc, char *argv) { int myid, numprocs, data[MAXSIZE], i, x, low, high, myresult, result; char fn[255]; char *fp; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); if (myid == 0) { /* Open input file and initialize data */ strcpy(fn,getenv(“HOME”)); strcat(fn,”/MPI/rand_data.txt”); if ((fp = fopen(fn,”r”)) == NULL) { printf(“Can’t open the input file: %snn”, fn); exit(1); } for(i = 0; i < MAXSIZE; i++) fscanf(fp,”%d”, &data[i]); } MPI_Bcast(data, MAXSIZE, MPI_INT, 0, MPI_COMM_WORLD); /* broadcast data */ x = n/nproc; /* Add my portion Of data */ low = myid * x; high = low + x; for(i = low; i < high; i++) myresult += data[i]; printf(“I got %d from %dn”, myresult, myid); /* Compute global sum */ MPI_Reduce(&myresult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); if (myid == 0) printf(“The sum is %d.n”, result); MPI_Finalize(); }
  • 18. Collective routines General features • Performed on a group of processes, identified by a communicator • Substitute for a sequence of point-to-point calls • Communications are locally blocking • Synchronization is not guaranteed (implementation dependent) • Some routines use a root process to originate or receive all data • Data amounts must exactly match • Many variations to basic categories • No message tags are needed 2a.18
  • 19. 2a.19 Barrier Block process until all processes have called it. Synchronous operation. MPI_Barrier(comm) Communicator
  • 20. 2a.20 Synchronous Message Passing Routines that return when message transfer completed. Synchronous send routine • Waits until complete message can be accepted by the receiving process before sending the message. In MPI, MPI_SSend() routine. Synchronous receive routine • Waits until the message it is expecting arrives. In MPI, actually the regular MPI_recv() routine.
  • 21. 2a.21 Synchronous Message Passing Synchronous message-passing routines intrinsically perform two actions: • They transfer data and • They synchronize processes.
  • 22. 2a.22 Synchronous Ssend() and recv() using 3-way protocol Process 1 Process 2 Ssend(); recv(); Suspend Time process Acknowledgment MessageBoth processes continue (a) When send() occurs before recv() Process 1 Process 2 recv(); Ssend(); Suspend Time process Acknowledgment MessageBoth processes continue (b) When recv() occurs before send() Request to send Request to send
  • 23. 2a.23 Parameters of synchronous send (same as blocking send) MPI_Ssend(buf, count, datatype, dest, tag, comm) Address of Number of items Datatype of Rank of destination Message tag Communicator send buffer to send each item process
  • 24. 2a.24 Asynchronous Message Passing • Routines that do not wait for actions to complete before returning. Usually require local storage for messages. • More than one version depending upon the actual semantics for returning. • In general, they do not synchronize processes but allow processes to move forward sooner. • Must be used with care.
  • 25. 2a.25 MPI Definitions of Blocking and Non- Blocking • Blocking - return after their local actions complete, though the message transfer may not have been completed. Sometimes called locally blocking. • Non-blocking - return immediately (asynchronous) Non-blocking assumes that data storage used for transfer not modified by subsequent statements prior to being used for transfer, and it is left to the programmer to ensure this. Blocking/non-blocking terms may have different interpretations in other systems.
  • 26. 2a.26 MPI Nonblocking Routines • Non-blocking send - MPI_Isend() - will return “immediately” even before source location is safe to be altered. • Non-blocking receive - MPI_Irecv() - will return even if no message to accept.
  • 27. 2a.27 Nonblocking Routine Formats MPI_Isend(buf,count,datatype,dest,tag,comm,request) MPI_Irecv(buf,count,datatype,source,tag,comm, request) Completion detected by MPI_Wait() and MPI_Test(). MPI_Wait() waits until operation completed and returns then. MPI_Test() returns with flag set indicating whether operation completed at that time. Need to know whether particular operation completed. Determined by accessing request parameter.
  • 28. 2a.28 Example To send an integer x from process 0 to process 1 and allow process 0 to continue: MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* find rank */ if (myrank == 0) { int x; MPI_Isend(&x,1,MPI_INT, 1, msgtag, MPI_COMM_WORLD, req1); compute(); MPI_Wait(req1, status); } else if (myrank == 1) { int x; MPI_Recv(&x,1,MPI_INT,0,msgtag, MPI_COMM_WORLD, status); }
  • 29. 2a.29 How message-passing routines return before message transfer completed Process 1 Process 2 send(); recv(); Message buffer Read message buffer Continue process Time Message buffer needed between source and destination to hold message:
  • 30. 2a.30 Asynchronous (blocking) routines changing to synchronous routines • Message buffers only of finite length • A point could be reached when send routine held up because all available buffer space exhausted. • Then, send routine will wait until storage becomes re-available - i.e. routine will behave as a synchronous routine.
  • 31. 2a.31 Next topic • Parallel Algorithms Other MPI features will be introduced as we need them.