SlideShare a Scribd company logo
1 of 29
Download to read offline
Parallel Computing
Mohamed Zahran (aka Z)
mzahran@cs.nyu.edu
http://www.mzahran.com
CSCI-UA.0480-003
MPI - I
Many slides of this
lecture are adopted
and slightly modified from:
• Gerassimos Barlas
• Peter S. Pacheco
This is What We Target With MPI
Copyright © 2010, Elsevier Inc.
All rights Reserved
We will talk about processes
We Will Study OpenMP for This
Copyright © 2010, Elsevier Inc.
All rights Reserved
We will talk about Threads
MPI processes
• Identify processes by non-negative
integer ranks.
• p processes are numbered 0, 1, 2, .. p-1
Copyright © 2010, Elsevier Inc.
All rights Reserved
Compilation
Copyright © 2010, Elsevier Inc.
All rights Reserved
mpicc -g -Wall –std=c99 -o mpi_hello mpi_hello.c
wrapper script to compile
turns on all warnings
source file
create this executable file name
(as opposed to default a.out)
produce
debugging
information
MPI is NOT a language.
Just libraries called from
C/C++, Fortran, and any
language that can call libraries from those.
use C lang. updated standard
Execution
Copyright © 2010, Elsevier Inc.
All rights Reserved
mpiexec -n <number of processes> <executable>
mpiexec -n 1 ./mpi_hello
mpiexec -n 4 ./mpi_hello
run with 1 process
run with 4 processes
You can use mpirun instead of mpiexec
and -np instead of -n.
Our first MPI program
Our first MPI program
Execution
Copyright © 2010, Elsevier Inc.
All rights Reserved
mpiexec -n 1 ./mpi_hello
mpiexec -n 4 ./mpi_hello
Greetings from process 0 of 1 !
Greetings from process 0 of 4 !
Greetings from process 1 of 4 !
Greetings from process 2 of 4 !
Greetings from process 3 of 4 !
MPI Programs
• Used mainly with C/C++ and Fortran
– With some efforts with other languages going
on and off.
– But any language that can call libraries from
the above can use MPI capabilities.
• Need to add mpi.h header file.
• Identifiers defined by MPI start with
“MPI_”.
– First letter following underscore is uppercase.
• For function names and MPI-defined types.
• Helps to avoid confusion.
– All letters following underscore are uppercase.
• MPI defined macros
• MPI defined constants
MPI Components
Tells MPI to do all the necessary setup.
No MPI functions should be called before this.
Pointers to
the two arguments
of main()
MPI Components
Copyright © 2010, Elsevier Inc.
All rights Reserved
•Tells MPI we’re done, so clean up anything allocated for
this program.
• No MPI function should be called after this.
Basic Outline
Copyright © 2010, Elsevier Inc.
All rights Reserved
Communicators
• A collection of processes that can send
messages to each other.
• MPI_Init defines a communicator that
consists of all the processes created
when the program started.
• Called MPI_COMM_WORLD.
Copyright © 2010, Elsevier Inc.
All rights Reserved
Communicators
Copyright © 2010, Elsevier Inc.
All rights Reserved
number of processes in the communicator
my rank
(rank of the process making this call)
MPI_COMM_WORLD for now
Communication
Copyright © 2010, Elsevier Inc.
All rights Reserved
rank of the receiving process
To distinguish messages
Message sent by a process using one communicator cannot be
received by a process in another communicator.
num of elements in
msg_buf
type of each
element in
msg_buf
Data types
Copyright © 2010, Elsevier Inc.
All rights Reserved
Communication
Copyright © 2010, Elsevier Inc.
All rights Reserved
Message matching
Copyright © 2010, Elsevier Inc.
All rights Reserved
MPI_Send
src = q
MPI_Recv
dest = r
r
q
recv_buf_sz
>=
send_buf_sz
Scenario 1
What if process 2 message
arrives before process 1?
Scenario 1
Wildcard: MPI_ANY_SOURCE
The loop will then be:
for(q = 1; q < comm_sz; q++) {
MPI_Recv(result, result_sz, result_type,
MPI_ANY_SOURCE,
tag, comm, MPI_STATUS_IGNORE);
}
Scenario 2
What if process 1 sends to process 0
several messages but they arrive out of
order.
– Process 0 is waiting for a message with tag
= 0 but tag = 1 message arrives instead!
Scenario 2
Wildcard: MPI_ANY_TAG
The loop will then be:
for(q = 1; q < comm_sz; q++) {
MPI_Recv(result, result_sz, result_type,
q,
MPI_ANY_TAG, comm,
MPI_STATUS_IGNORE);
}
Receiving messages
• A receiver can get a message without
knowing:
– the amount of data in the message,
– the sender of the message,
– or the tag of the message.
Copyright © 2010, Elsevier Inc.
All rights Reserved
How will the output be different if ..
•use MPI_ANY_SOURCE
•MPI_ANY_TAG
status argument
Copyright © 2010, Elsevier Inc.
All rights Reserved
MPI_SOURCE
MPI_TAG
MPI_ERROR
Pointer to
MPI_Status struct
MPI_Status* status;
status.MPI_SOURCE
status.MPI_TAG
How much data am I receiving?
Copyright © 2010, Elsevier Inc.
All rights Reserved
Issues
• MPI_Send() is implementation
dependent: can buffer or block .. or
both!
• MPI_Recv() always blocks
– So, if it returns we are sure the message
has been received.
– Be careful: don’t make it block forever!
Conclusions
• MPI is the choice when we have
distributed memory organization.
• It depends on messages.
• Your goal: How to reduce messages yet
increase concurrency?
Powered by TCPDF (www.tcpdf.org)Powered by TCPDF (www.tcpdf.org)

More Related Content

What's hot

Intro to MPI
Intro to MPIIntro to MPI
Intro to MPIjbp4444
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux Mohammad Golyani
 
What is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaWhat is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaEdureka!
 
MPI Presentation
MPI PresentationMPI Presentation
MPI PresentationTayfun Sen
 
vishal_sharma: python email sending software
vishal_sharma: python email sending software  vishal_sharma: python email sending software
vishal_sharma: python email sending software vishal sharma
 
Python session.11 By Shanmugam
Python session.11 By ShanmugamPython session.11 By Shanmugam
Python session.11 By ShanmugamNavaneethan Naveen
 
Network programming Using Python
Network programming Using PythonNetwork programming Using Python
Network programming Using PythonKarim Sonbol
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Pythondidip
 
Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
PYTHON NOTES
PYTHON NOTESPYTHON NOTES
PYTHON NOTESNi
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkESUG
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CMahendra Yadav
 
Planet of the AOPs
Planet of the AOPsPlanet of the AOPs
Planet of the AOPsJames Ward
 
Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475Max Kleiner
 
Introduction to Python for Bioinformatics
Introduction to Python for BioinformaticsIntroduction to Python for Bioinformatics
Introduction to Python for BioinformaticsJosé Héctor Gálvez
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingAkhil Kaushik
 

What's hot (20)

Intro to MPI
Intro to MPIIntro to MPI
Intro to MPI
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux
 
What is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaWhat is Socket Programming in Python | Edureka
What is Socket Programming in Python | Edureka
 
MPI Presentation
MPI PresentationMPI Presentation
MPI Presentation
 
vishal_sharma: python email sending software
vishal_sharma: python email sending software  vishal_sharma: python email sending software
vishal_sharma: python email sending software
 
Python session.11 By Shanmugam
Python session.11 By ShanmugamPython session.11 By Shanmugam
Python session.11 By Shanmugam
 
Network programming Using Python
Network programming Using PythonNetwork programming Using Python
Network programming Using Python
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
PYTHON NOTES
PYTHON NOTESPYTHON NOTES
PYTHON NOTES
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Planet of the AOPs
Planet of the AOPsPlanet of the AOPs
Planet of the AOPs
 
Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Introduction to Python for Bioinformatics
Introduction to Python for BioinformaticsIntroduction to Python for Bioinformatics
Introduction to Python for Bioinformatics
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 

Similar to MPI - 1

Similar to MPI - 1 (20)

My ppt hpc u4
My ppt hpc u4My ppt hpc u4
My ppt hpc u4
 
High Performance Computing using MPI
High Performance Computing using MPIHigh Performance Computing using MPI
High Performance Computing using MPI
 
Distributed Memory Programming with MPI
Distributed Memory Programming with MPIDistributed Memory Programming with MPI
Distributed Memory Programming with MPI
 
25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
Open MPI
Open MPIOpen MPI
Open MPI
 
MPI - 2
MPI - 2MPI - 2
MPI - 2
 
More mpi4py
More mpi4pyMore mpi4py
More mpi4py
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Message Passing Interface (MPI)-A means of machine communication
Message Passing Interface (MPI)-A means of machine communicationMessage Passing Interface (MPI)-A means of machine communication
Message Passing Interface (MPI)-A means of machine communication
 
Lecture9
Lecture9Lecture9
Lecture9
 
MPI Introduction
MPI IntroductionMPI Introduction
MPI Introduction
 
MPI
MPIMPI
MPI
 
Introduction to MPI
Introduction to MPI Introduction to MPI
Introduction to MPI
 
Multicore
MulticoreMulticore
Multicore
 
MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
 
Programming using MPI and OpenMP
Programming using MPI and OpenMPProgramming using MPI and OpenMP
Programming using MPI and OpenMP
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interface
 
cs556-2nd-tutorial.pdf
cs556-2nd-tutorial.pdfcs556-2nd-tutorial.pdf
cs556-2nd-tutorial.pdf
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
 

More from Shah Zaib

Parallel Programming for Multi- Core and Cluster Systems - Performance Analysis
Parallel Programming for Multi- Core and Cluster Systems - Performance AnalysisParallel Programming for Multi- Core and Cluster Systems - Performance Analysis
Parallel Programming for Multi- Core and Cluster Systems - Performance AnalysisShah Zaib
 
Parallel Computing - Lec 6
Parallel Computing - Lec 6Parallel Computing - Lec 6
Parallel Computing - Lec 6Shah Zaib
 
Parallel Computing - Lec 5
Parallel Computing - Lec 5Parallel Computing - Lec 5
Parallel Computing - Lec 5Shah Zaib
 
Parallel Computing - Lec 4
Parallel Computing - Lec 4Parallel Computing - Lec 4
Parallel Computing - Lec 4Shah Zaib
 
Parallel Computing - Lec 3
Parallel Computing - Lec 3Parallel Computing - Lec 3
Parallel Computing - Lec 3Shah Zaib
 
Parallel Computing - Lec 2
Parallel Computing - Lec 2Parallel Computing - Lec 2
Parallel Computing - Lec 2Shah Zaib
 
Mpi collective communication operations
Mpi collective communication operationsMpi collective communication operations
Mpi collective communication operationsShah Zaib
 

More from Shah Zaib (8)

Parallel Programming for Multi- Core and Cluster Systems - Performance Analysis
Parallel Programming for Multi- Core and Cluster Systems - Performance AnalysisParallel Programming for Multi- Core and Cluster Systems - Performance Analysis
Parallel Programming for Multi- Core and Cluster Systems - Performance Analysis
 
MPI - 3
MPI - 3MPI - 3
MPI - 3
 
Parallel Computing - Lec 6
Parallel Computing - Lec 6Parallel Computing - Lec 6
Parallel Computing - Lec 6
 
Parallel Computing - Lec 5
Parallel Computing - Lec 5Parallel Computing - Lec 5
Parallel Computing - Lec 5
 
Parallel Computing - Lec 4
Parallel Computing - Lec 4Parallel Computing - Lec 4
Parallel Computing - Lec 4
 
Parallel Computing - Lec 3
Parallel Computing - Lec 3Parallel Computing - Lec 3
Parallel Computing - Lec 3
 
Parallel Computing - Lec 2
Parallel Computing - Lec 2Parallel Computing - Lec 2
Parallel Computing - Lec 2
 
Mpi collective communication operations
Mpi collective communication operationsMpi collective communication operations
Mpi collective communication operations
 

Recently uploaded

Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...Amil baba
 
9892124323 Pooja Nehwal Call Girls Services Call Girls service in Santacruz A...
9892124323 Pooja Nehwal Call Girls Services Call Girls service in Santacruz A...9892124323 Pooja Nehwal Call Girls Services Call Girls service in Santacruz A...
9892124323 Pooja Nehwal Call Girls Services Call Girls service in Santacruz A...Pooja Nehwal
 
CALL GIRLS IN Saket 83778-77756 | Escort Service In DELHI NcR
CALL GIRLS IN Saket 83778-77756 | Escort Service In DELHI NcRCALL GIRLS IN Saket 83778-77756 | Escort Service In DELHI NcR
CALL GIRLS IN Saket 83778-77756 | Escort Service In DELHI NcRdollysharma2066
 
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样qaffana
 
Shikrapur Call Girls Most Awaited Fun 6297143586 High Profiles young Beautie...
Shikrapur Call Girls Most Awaited Fun  6297143586 High Profiles young Beautie...Shikrapur Call Girls Most Awaited Fun  6297143586 High Profiles young Beautie...
Shikrapur Call Girls Most Awaited Fun 6297143586 High Profiles young Beautie...tanu pandey
 
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...amitlee9823
 
9004554577, Get Adorable Call Girls service. Book call girls & escort service...
9004554577, Get Adorable Call Girls service. Book call girls & escort service...9004554577, Get Adorable Call Girls service. Book call girls & escort service...
9004554577, Get Adorable Call Girls service. Book call girls & escort service...Pooja Nehwal
 
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service NashikLow Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort GirlsDeira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort GirlsEscorts Call Girls
 
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...amitlee9823
 
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)kojalkojal131
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Pooja Nehwal
 

Recently uploaded (20)

Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
 
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
 
9892124323 Pooja Nehwal Call Girls Services Call Girls service in Santacruz A...
9892124323 Pooja Nehwal Call Girls Services Call Girls service in Santacruz A...9892124323 Pooja Nehwal Call Girls Services Call Girls service in Santacruz A...
9892124323 Pooja Nehwal Call Girls Services Call Girls service in Santacruz A...
 
CALL GIRLS IN Saket 83778-77756 | Escort Service In DELHI NcR
CALL GIRLS IN Saket 83778-77756 | Escort Service In DELHI NcRCALL GIRLS IN Saket 83778-77756 | Escort Service In DELHI NcR
CALL GIRLS IN Saket 83778-77756 | Escort Service In DELHI NcR
 
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
 
Shikrapur Call Girls Most Awaited Fun 6297143586 High Profiles young Beautie...
Shikrapur Call Girls Most Awaited Fun  6297143586 High Profiles young Beautie...Shikrapur Call Girls Most Awaited Fun  6297143586 High Profiles young Beautie...
Shikrapur Call Girls Most Awaited Fun 6297143586 High Profiles young Beautie...
 
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
CHEAP Call Girls in Hauz Quazi (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Hauz Quazi  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Hauz Quazi  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Hauz Quazi (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
 
9004554577, Get Adorable Call Girls service. Book call girls & escort service...
9004554577, Get Adorable Call Girls service. Book call girls & escort service...9004554577, Get Adorable Call Girls service. Book call girls & escort service...
9004554577, Get Adorable Call Girls service. Book call girls & escort service...
 
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service NashikLow Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
 
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
@Delhi ! CAll GIRLS IN Defence Colony 🦋 9999965857 🤩 Dwarka Call Girls
@Delhi ! CAll GIRLS IN Defence Colony 🦋 9999965857 🤩 Dwarka Call Girls@Delhi ! CAll GIRLS IN Defence Colony 🦋 9999965857 🤩 Dwarka Call Girls
@Delhi ! CAll GIRLS IN Defence Colony 🦋 9999965857 🤩 Dwarka Call Girls
 
young call girls in Sainik Farm 🔝 9953056974 🔝 Delhi escort Service
young call girls in Sainik Farm 🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Sainik Farm 🔝 9953056974 🔝 Delhi escort Service
young call girls in Sainik Farm 🔝 9953056974 🔝 Delhi escort Service
 
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort GirlsDeira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
 
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
 
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006
 

MPI - 1

  • 1. Parallel Computing Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com CSCI-UA.0480-003 MPI - I Many slides of this lecture are adopted and slightly modified from: • Gerassimos Barlas • Peter S. Pacheco
  • 2. This is What We Target With MPI Copyright © 2010, Elsevier Inc. All rights Reserved We will talk about processes
  • 3. We Will Study OpenMP for This Copyright © 2010, Elsevier Inc. All rights Reserved We will talk about Threads
  • 4. MPI processes • Identify processes by non-negative integer ranks. • p processes are numbered 0, 1, 2, .. p-1 Copyright © 2010, Elsevier Inc. All rights Reserved
  • 5. Compilation Copyright © 2010, Elsevier Inc. All rights Reserved mpicc -g -Wall –std=c99 -o mpi_hello mpi_hello.c wrapper script to compile turns on all warnings source file create this executable file name (as opposed to default a.out) produce debugging information MPI is NOT a language. Just libraries called from C/C++, Fortran, and any language that can call libraries from those. use C lang. updated standard
  • 6. Execution Copyright © 2010, Elsevier Inc. All rights Reserved mpiexec -n <number of processes> <executable> mpiexec -n 1 ./mpi_hello mpiexec -n 4 ./mpi_hello run with 1 process run with 4 processes You can use mpirun instead of mpiexec and -np instead of -n.
  • 7. Our first MPI program
  • 8. Our first MPI program
  • 9. Execution Copyright © 2010, Elsevier Inc. All rights Reserved mpiexec -n 1 ./mpi_hello mpiexec -n 4 ./mpi_hello Greetings from process 0 of 1 ! Greetings from process 0 of 4 ! Greetings from process 1 of 4 ! Greetings from process 2 of 4 ! Greetings from process 3 of 4 !
  • 10. MPI Programs • Used mainly with C/C++ and Fortran – With some efforts with other languages going on and off. – But any language that can call libraries from the above can use MPI capabilities. • Need to add mpi.h header file. • Identifiers defined by MPI start with “MPI_”. – First letter following underscore is uppercase. • For function names and MPI-defined types. • Helps to avoid confusion. – All letters following underscore are uppercase. • MPI defined macros • MPI defined constants
  • 11. MPI Components Tells MPI to do all the necessary setup. No MPI functions should be called before this. Pointers to the two arguments of main()
  • 12. MPI Components Copyright © 2010, Elsevier Inc. All rights Reserved •Tells MPI we’re done, so clean up anything allocated for this program. • No MPI function should be called after this.
  • 13. Basic Outline Copyright © 2010, Elsevier Inc. All rights Reserved
  • 14. Communicators • A collection of processes that can send messages to each other. • MPI_Init defines a communicator that consists of all the processes created when the program started. • Called MPI_COMM_WORLD. Copyright © 2010, Elsevier Inc. All rights Reserved
  • 15. Communicators Copyright © 2010, Elsevier Inc. All rights Reserved number of processes in the communicator my rank (rank of the process making this call) MPI_COMM_WORLD for now
  • 16. Communication Copyright © 2010, Elsevier Inc. All rights Reserved rank of the receiving process To distinguish messages Message sent by a process using one communicator cannot be received by a process in another communicator. num of elements in msg_buf type of each element in msg_buf
  • 17. Data types Copyright © 2010, Elsevier Inc. All rights Reserved
  • 18. Communication Copyright © 2010, Elsevier Inc. All rights Reserved
  • 19. Message matching Copyright © 2010, Elsevier Inc. All rights Reserved MPI_Send src = q MPI_Recv dest = r r q recv_buf_sz >= send_buf_sz
  • 20. Scenario 1 What if process 2 message arrives before process 1?
  • 21. Scenario 1 Wildcard: MPI_ANY_SOURCE The loop will then be: for(q = 1; q < comm_sz; q++) { MPI_Recv(result, result_sz, result_type, MPI_ANY_SOURCE, tag, comm, MPI_STATUS_IGNORE); }
  • 22. Scenario 2 What if process 1 sends to process 0 several messages but they arrive out of order. – Process 0 is waiting for a message with tag = 0 but tag = 1 message arrives instead!
  • 23. Scenario 2 Wildcard: MPI_ANY_TAG The loop will then be: for(q = 1; q < comm_sz; q++) { MPI_Recv(result, result_sz, result_type, q, MPI_ANY_TAG, comm, MPI_STATUS_IGNORE); }
  • 24. Receiving messages • A receiver can get a message without knowing: – the amount of data in the message, – the sender of the message, – or the tag of the message. Copyright © 2010, Elsevier Inc. All rights Reserved
  • 25. How will the output be different if .. •use MPI_ANY_SOURCE •MPI_ANY_TAG
  • 26. status argument Copyright © 2010, Elsevier Inc. All rights Reserved MPI_SOURCE MPI_TAG MPI_ERROR Pointer to MPI_Status struct MPI_Status* status; status.MPI_SOURCE status.MPI_TAG
  • 27. How much data am I receiving? Copyright © 2010, Elsevier Inc. All rights Reserved
  • 28. Issues • MPI_Send() is implementation dependent: can buffer or block .. or both! • MPI_Recv() always blocks – So, if it returns we are sure the message has been received. – Be careful: don’t make it block forever!
  • 29. Conclusions • MPI is the choice when we have distributed memory organization. • It depends on messages. • Your goal: How to reduce messages yet increase concurrency? Powered by TCPDF (www.tcpdf.org)Powered by TCPDF (www.tcpdf.org)