SlideShare une entreprise Scribd logo
1  sur  15
WELCOM
E
TO OUR PRESENTATION
Presentation Topic is :Programming Using the Message-Passing Paradigm
Course Title :Parallel and Distributed Computing
Course Intructor : Sir Sadaqat Hussain
Message passing Programing
The message-passing programming paradigm is one of the oldest and most widely used approaches for
programming parallel computers. Its roots can be traced back in the early days of parallel processing and its wide-
spread adoption can be attributed to the fact that it imposes minimal requirements on the underlying hardware.
Principles of Message-Passing Programming
There are two key attributes that characterize the message-passing
programming paradigm.
1 Partitioned address
Explicit parallelization
2
Message passing Programing
The message-passing programming paradigm requires that the parallelism is coded explicitly by the programmer.
That is, the programmer is responsible for analyzing the underlying serial algorithm/application and identifying ways
by which he or she can decompose the computations and extract concurrency. As a result, programming using the
message-passing paradigm tends to be hard and intellectually demanding. However, on the other hand, properly
written message-passing programs can often achieve very high performance and scale to a very large number of
processes
The logical view of a machine supporting the message-
passing paradigm consists of p processes, each with its
own exclusive address space
Instances of such a view come naturally from clustered
workstations and non-shared address space
multicomputer.
Message Structure of Message Passing Programs
Message-passing programs are often written using the:
1 Asynchronous Paradigm
Loosely Synchronous
2
In the asynchronous paradigm, all concurrent tasks execute asynchronously.
This makes it possible to implement any parallel algorithm.
Loosely synchronous programs are a good compromise between these two
extremes. In such programs, tasks or subsets of tasks synchronize to perform
interactions. However, between these interactions, tasks execute completely
asynchronously. Since the interaction happens synchronously.
i
ii
The Building Blocks: Send and Receive Operations
Since interactions are accomplished by sending and receiving messages, the
basic operations in the message-passing programming paradigm
are send and receive.
In their simplest form, the prototypes of these operations are defined as
follows:
send(void *sendbuf, int nelems, int dest)
receive(void *recvbuf, int nelems, int source)
Received buffer
recvbuf points to a buffer that
stores the data to be received.
Source source is the identifier of the
process that sends the data.
Send buffer The sendbuf points to a buffer
that stores the data to be sent.
Parameter
Destination
dest is the identifier of the
process that receives the data.
The Building Blocks: Send and Receive Operations
1 P0 P1
2
3 a = 100; receive(&a, 1, 0)
4 send(&a, 1, 1); printf("%dn", a);
5 a=0;
The important thing to note is that process P0 changes the
value of a to 0 immediately following the send.
The semantics of the send operation require that the value
received by process P1 must be 100 as opposed to 0.
The Building Blocks: Send and Receive Operations
They may support DMA (direct memory
access)
1 DMA
2 Mnetwork interface
hardware
Most message passing platforms have additional hardware
support for sending and receiving messages.
asynchronous message transfer using
network interface hardware.
Network interfaces allow the transfer of messages from buffer memory to
desired location without CPU intervention.
Similarly, DMA allows copying of data from one memory location to another (e.g.,
communication buffers) without CPU support (once they have been programmed). As
a result, if the send operation programs the communication hardware and returns
before the communication operation has been accomplished, process P1 might receive
the value 0 in a instead of 100!
01
02
Blocking Non-Buffered
Send/Receive
Blocking Buffered
Send/Receive
Blocking Message Passing Operations
A simple solution to the dilemma presented in the code fragment
above is for the send operation to return only when it is semantically
safe to do so.
There are two mechanisms by which this can be achieved.
Blocking Message Passing Operations
In the first case, the send operation does not return until the
matching receive has been encountered at the receiving process.
1
2
When this happens, the message is sent and the send operation
returns upon completion of the communication operation.
3
Typically, this process involves a handshake between the
sending and receiving processes. The sending process sends a
request to communicate to the receiving process.
Blocking Non-Buffered Send/Receive
Blocking Message Passing Operations
Blocking Non-Buffered Send/Receive
In cases (a) and (c), we notice that there is considerable idling at the
sending and receiving process.
It is also clear from the figures that a blocking non-buffered protocol is
suitable when the send and receive are posted at roughly the same time.
Blocking Message Passing Operations
A simple solution to the idling and deadlocking problem outlined
above is to rely on buffers at the sending and receiving ends.
1
2
We start with a simple case in which the sender has a buffer pre-
allocated for communicating messages.
3
On encountering a send operation, the sender simply copies
the data into the designated buffer and returns after the copy
operation has been completed.
Blocking Buffered Send/Receive
3
The sender process can now continue with the program
knowing that any changes to the data will not impact program
semantics.
Blocking Message Passing Operations
Blocking Buffered Send/Receive
MPI: Message Passing Interface
01
02
03
04
Vendor implementations of MPI are available on
almost all commercial parallel computers.
Vendor implementations of MPI are available on almost
all commercial parallel computers.
it is possible to write fully-functional message-passing
programs by using only the six routines
MPI defines a standard library for message-passing that
can be used to develop portable message-passing programs
using either C or Fortran.
MPI: Message Passing Interface
The minimal set of MPI routines.
MPI_Init Initializes MPI.
MPI_Finalize Terminates MPI.
MPI_Comm_size Determines the number of processes.
MPI_Comm_rank Determines the label of the calling process.
MPI_Send Sends a message.
MPI_Recv Receives a message.
Example Our first program print “Hello World”
We can use the four MPI functions just described to write a program that prints out a "Hello World" message
from each processor.
1 #include <mpi.h>
2
3 main(int argc, char *argv[])
4
{ 5 int npes, myrank;
6
7 MPI_Init(&argc, &argv);
8 MPI_Comm_size(MPI_COMM_WORLD, &npes);
9 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
10 printf("From process %d out of %d, Hello World!n",
11 myrank, npes);
12 MPI_Finalize();
13 }
THANK YOU

Contenu connexe

Similaire à Message passing Programing and MPI.

Intro to MPI
Intro to MPIIntro to MPI
Intro to MPIjbp4444
 
Task communication
Task communicationTask communication
Task communication1jayanti
 
cs556-2nd-tutorial.pdf
cs556-2nd-tutorial.pdfcs556-2nd-tutorial.pdf
cs556-2nd-tutorial.pdfssuserada6a9
 
Arun prjct dox
Arun prjct doxArun prjct dox
Arun prjct doxBaig Mirza
 
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...Sehrish Asif
 
1 messagepassing-121015032028-phpapp01
1 messagepassing-121015032028-phpapp011 messagepassing-121015032028-phpapp01
1 messagepassing-121015032028-phpapp01Zaigham Abbas
 
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptModule-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptKAnurag2
 
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...Dhivyaa C.R
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSKathirvel Ayyaswamy
 
5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptxMohamedBilal73
 
Intranet Messaging Project Report -phpapp02
Intranet Messaging Project Report -phpapp02Intranet Messaging Project Report -phpapp02
Intranet Messaging Project Report -phpapp02dvicky12
 
Point-to-Point Communicationsin MPI
Point-to-Point Communicationsin MPIPoint-to-Point Communicationsin MPI
Point-to-Point Communicationsin MPIHanif Durad
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKXMike Willbanks
 

Similaire à Message passing Programing and MPI. (20)

Process
ProcessProcess
Process
 
OSCh4
OSCh4OSCh4
OSCh4
 
Chapter 3 - Processes
Chapter 3 - ProcessesChapter 3 - Processes
Chapter 3 - Processes
 
Ch03
Ch03Ch03
Ch03
 
Intro to MPI
Intro to MPIIntro to MPI
Intro to MPI
 
Task communication
Task communicationTask communication
Task communication
 
Thesis11
Thesis11Thesis11
Thesis11
 
cs556-2nd-tutorial.pdf
cs556-2nd-tutorial.pdfcs556-2nd-tutorial.pdf
cs556-2nd-tutorial.pdf
 
Arun prjct dox
Arun prjct doxArun prjct dox
Arun prjct dox
 
Ipc
IpcIpc
Ipc
 
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
 
1 messagepassing-121015032028-phpapp01
1 messagepassing-121015032028-phpapp011 messagepassing-121015032028-phpapp01
1 messagepassing-121015032028-phpapp01
 
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptModule-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
 
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...
Inter process communication by Dr.C.R.Dhivyaa, Assistant Professor,Kongu Engi...
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx
 
Intranet Messaging Project Report -phpapp02
Intranet Messaging Project Report -phpapp02Intranet Messaging Project Report -phpapp02
Intranet Messaging Project Report -phpapp02
 
Point-to-Point Communicationsin MPI
Point-to-Point Communicationsin MPIPoint-to-Point Communicationsin MPI
Point-to-Point Communicationsin MPI
 
Open MPI 2
Open MPI 2Open MPI 2
Open MPI 2
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKX
 

Dernier

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Dernier (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Message passing Programing and MPI.

  • 1. WELCOM E TO OUR PRESENTATION Presentation Topic is :Programming Using the Message-Passing Paradigm Course Title :Parallel and Distributed Computing Course Intructor : Sir Sadaqat Hussain
  • 2. Message passing Programing The message-passing programming paradigm is one of the oldest and most widely used approaches for programming parallel computers. Its roots can be traced back in the early days of parallel processing and its wide- spread adoption can be attributed to the fact that it imposes minimal requirements on the underlying hardware. Principles of Message-Passing Programming There are two key attributes that characterize the message-passing programming paradigm. 1 Partitioned address Explicit parallelization 2
  • 3. Message passing Programing The message-passing programming paradigm requires that the parallelism is coded explicitly by the programmer. That is, the programmer is responsible for analyzing the underlying serial algorithm/application and identifying ways by which he or she can decompose the computations and extract concurrency. As a result, programming using the message-passing paradigm tends to be hard and intellectually demanding. However, on the other hand, properly written message-passing programs can often achieve very high performance and scale to a very large number of processes The logical view of a machine supporting the message- passing paradigm consists of p processes, each with its own exclusive address space Instances of such a view come naturally from clustered workstations and non-shared address space multicomputer.
  • 4. Message Structure of Message Passing Programs Message-passing programs are often written using the: 1 Asynchronous Paradigm Loosely Synchronous 2 In the asynchronous paradigm, all concurrent tasks execute asynchronously. This makes it possible to implement any parallel algorithm. Loosely synchronous programs are a good compromise between these two extremes. In such programs, tasks or subsets of tasks synchronize to perform interactions. However, between these interactions, tasks execute completely asynchronously. Since the interaction happens synchronously. i ii
  • 5. The Building Blocks: Send and Receive Operations Since interactions are accomplished by sending and receiving messages, the basic operations in the message-passing programming paradigm are send and receive. In their simplest form, the prototypes of these operations are defined as follows: send(void *sendbuf, int nelems, int dest) receive(void *recvbuf, int nelems, int source) Received buffer recvbuf points to a buffer that stores the data to be received. Source source is the identifier of the process that sends the data. Send buffer The sendbuf points to a buffer that stores the data to be sent. Parameter Destination dest is the identifier of the process that receives the data.
  • 6. The Building Blocks: Send and Receive Operations 1 P0 P1 2 3 a = 100; receive(&a, 1, 0) 4 send(&a, 1, 1); printf("%dn", a); 5 a=0; The important thing to note is that process P0 changes the value of a to 0 immediately following the send. The semantics of the send operation require that the value received by process P1 must be 100 as opposed to 0.
  • 7. The Building Blocks: Send and Receive Operations They may support DMA (direct memory access) 1 DMA 2 Mnetwork interface hardware Most message passing platforms have additional hardware support for sending and receiving messages. asynchronous message transfer using network interface hardware. Network interfaces allow the transfer of messages from buffer memory to desired location without CPU intervention. Similarly, DMA allows copying of data from one memory location to another (e.g., communication buffers) without CPU support (once they have been programmed). As a result, if the send operation programs the communication hardware and returns before the communication operation has been accomplished, process P1 might receive the value 0 in a instead of 100!
  • 8. 01 02 Blocking Non-Buffered Send/Receive Blocking Buffered Send/Receive Blocking Message Passing Operations A simple solution to the dilemma presented in the code fragment above is for the send operation to return only when it is semantically safe to do so. There are two mechanisms by which this can be achieved.
  • 9. Blocking Message Passing Operations In the first case, the send operation does not return until the matching receive has been encountered at the receiving process. 1 2 When this happens, the message is sent and the send operation returns upon completion of the communication operation. 3 Typically, this process involves a handshake between the sending and receiving processes. The sending process sends a request to communicate to the receiving process. Blocking Non-Buffered Send/Receive
  • 10. Blocking Message Passing Operations Blocking Non-Buffered Send/Receive In cases (a) and (c), we notice that there is considerable idling at the sending and receiving process. It is also clear from the figures that a blocking non-buffered protocol is suitable when the send and receive are posted at roughly the same time.
  • 11. Blocking Message Passing Operations A simple solution to the idling and deadlocking problem outlined above is to rely on buffers at the sending and receiving ends. 1 2 We start with a simple case in which the sender has a buffer pre- allocated for communicating messages. 3 On encountering a send operation, the sender simply copies the data into the designated buffer and returns after the copy operation has been completed. Blocking Buffered Send/Receive 3 The sender process can now continue with the program knowing that any changes to the data will not impact program semantics.
  • 12. Blocking Message Passing Operations Blocking Buffered Send/Receive
  • 13. MPI: Message Passing Interface 01 02 03 04 Vendor implementations of MPI are available on almost all commercial parallel computers. Vendor implementations of MPI are available on almost all commercial parallel computers. it is possible to write fully-functional message-passing programs by using only the six routines MPI defines a standard library for message-passing that can be used to develop portable message-passing programs using either C or Fortran.
  • 14. MPI: Message Passing Interface The minimal set of MPI routines. MPI_Init Initializes MPI. MPI_Finalize Terminates MPI. MPI_Comm_size Determines the number of processes. MPI_Comm_rank Determines the label of the calling process. MPI_Send Sends a message. MPI_Recv Receives a message. Example Our first program print “Hello World” We can use the four MPI functions just described to write a program that prints out a "Hello World" message from each processor. 1 #include <mpi.h> 2 3 main(int argc, char *argv[]) 4 { 5 int npes, myrank; 6 7 MPI_Init(&argc, &argv); 8 MPI_Comm_size(MPI_COMM_WORLD, &npes); 9 MPI_Comm_rank(MPI_COMM_WORLD, &myrank); 10 printf("From process %d out of %d, Hello World!n", 11 myrank, npes); 12 MPI_Finalize(); 13 }