SlideShare a Scribd company logo
Message Passing
Interface(MPI)
Himanshi Kathuria
Content
MPI
1. Definition
2. Reason For Using MPI
3. History And Evolution
4. General MPI Program Structure
5. Writing MPI PROGRAMS
6. Compiling MPI Programs
7. Running MPI Programs
8. Environment Management Routines
MPI Message Passing Interface
A means of machine communication
DEFINITION
• The Message passing interface Standard is a message passing library
industry standard for parallel programming based on the consensus of the
MPI forum which has over 40 participating organization, including vendors,
researchers software library developers, and users
• MPI provides widely used standard for writing message passing programs.
Motivation
Motivated by high computational complexity and memory requirements of
large applications.
HISTORY AND EVOLUTION
• Late 1980s: vendors had unique libraries
• 1989: ParallelVirtual Machine (PVM) developed at Oak Ridge National Lab
• 1992:Work on MPI standard begun
• 1994:Version 1.0 of MPI standard
• June 1995 MPI 1.1 published (clarifications)
• July 1996 MPI 1.2 published (clarifications)
• April 1995 MPI 2.0 committee formed
• July 1997 MPI 2.0 published
MPI CONCEPT
•MPI uses objects called communicators and groups to define which collection of
processes may communicate with each other.
•Most MPI routines require you to specify a communicator as an argument.
•Communicators and groups will be covered in more detail later. For now, simply use
MPI_COMM_WORLD whenever a communicator is required - it is the predefined
communicator that includes all of your MPI processes.
Rank:
• Within a communicator, every process has its own unique, integer identifier
assigned by the system when the process initializes.
• A rank is sometimes also called a "task ID".
• Ranks are contiguous and begin at zero.
• Used by the programmer to specify the source and destination of messages.
Size :
• Within a communicator, no of processes is defined as size.
General MPI Program Structure:
MPI include file
Initialize MPI Environment
Do work and make messaging passing calls
Terminate MPI Environment
Variables declaration
Parallel code begins
Include Files
#include <mpi.h>
• MPI header file
#include <stdio.h>
• Standard I/O header file
Variables
int main (int argc, char *argv[]) {
int i;
int id; /* Process rank */
int p; /* Number of processes */
void check_circuit (int, int);
• Include argc and argv: they are needed to initialize MPI
• One copy of every variable for each process running this program
argc=argument count ie. Gives the total number argument given
argv[]= pointer the argument value
Initialize MPI ENVIRONMENT
MPI_Init (&argc, &argv);
• First MPI function called by each process
• Not necessarily first executable statement
• Allows system to do any necessary setup
Parameters
argc [in] Pointer to the number of arguments .
argv [in] Pointer to the argument vector
Terminate MPI ENVIRONMENT
MPI_Finalize();
• Call after all other MPI library calls
• Allows system to free up MPI resources
WRITING MPI PROGRAMS
#include "mpi.h" // Gives basic MPI types, definitions
#include <stdio.h>
int main( argc, argv )
int argc;
char **argv;
{
MPI_Init( &argc, &argv ); // Starts MPI
::
Actual code including normal ‘C’ calls and MPI calls
::
MPI_Finalize(); // Ends MPI
return 0;
}
Compiling MPI Programs
Compile step:
mpicc -o <object file> <source code>.c ( By default the output file is a. out)
Compilation commands
• – mpicc -o hello_world hello-world.c
Running MPI Programs
Execution steps:
mpiexec/mpirun -np <i> <object file>
• To run hello_world on two machines:
mpirun -np 2 hello_world
Must specify full path of ‘executable’
• To know the commands executed by mpirun
mpirun –t
• To get all the mpirun options
mpirun –help
Environment Management Routines
MPI environment management routines are used for initializing and terminating the MPI
environment, querying the environment etc. Most of the commonly used ones are:
• MPI_Init
• MPI_Comm_size
• MPI_Comm_rank
• MPI_Get_processor_name
• MPI_Finalize
MPI_Comm_size
Determines the number of processes in the group associated with a communicator.
int MPI_Comm_size( MPI_Comm comm, int *size);
Parameters
• comm [in] communicator (handle)
• size [out] number of processes in the group of comm (integer).
MPI_Comm_size(MPI_COMM_WORLD, &size)
MPI_Comm_rank
Determines the rank of the calling process in the communicator.
int MPI_Comm_rank( MPI_Comm comm, int *rank);
Parameters
• comm [in] communicator (handle)
• rank [out] rank of the calling process in the group of comm(integer)
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Get_processor_name
Gets the name of the processor.
int MPI_Get_processor_name( char *name, int *resultlen );
Parameters
• name [out] A unique specifier for the actual node.This must be an array
of size at least MPI_MAX_PROCESSOR_NAME.
• resultlen [out] Length (in characters) of the name
MPI_Get_processor_name(&name, &resultlength)
THANKYOU

More Related Content

What's hot

Computer system
Computer systemComputer system
Computer system
fardinahmed8
 
Open MPI
Open MPIOpen MPI
Open MPI
Anshul Sharma
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
Sreenatha Reddy K R
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linux
Siddique Ibrahim
 
Evolution of operating system
Evolution of operating systemEvolution of operating system
Evolution of operating system
Arshad khan
 
Cs1 3-operating systems
Cs1 3-operating systemsCs1 3-operating systems
Cs1 3-operating systems
maria teresa salta
 
PyCharm demo
PyCharm demoPyCharm demo
PyCharm demo
T. Kim Nguyen
 
Operating systems
Operating systemsOperating systems
Operating systems
11mooremichael
 
Apache web server
Apache web serverApache web server
Apache web server
zrstoppe
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
Akhila Prabhakaran
 
Operating systems
Operating systemsOperating systems
Operating systems
Srishti Gupta
 
Windows Architecture
Windows ArchitectureWindows Architecture
Windows Architecture
Amrith Krishna
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
MahakKasliwal
 
Operating system
Operating systemOperating system
Operating system
Tanvirul Islam
 
Introduction and history of linux
Introduction and history of linuxIntroduction and history of linux
Introduction and history of linux
SHUBHA CHATURVEDI
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
Mr SMAK
 
Mainframe
MainframeMainframe
Mainframe
Kanika Kapoor
 
MPI Introduction
MPI IntroductionMPI Introduction
MPI Introduction
Rohit Banga
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
Goutam Sahoo
 
Ipc in linux
Ipc in linuxIpc in linux
Ipc in linux
Dr. C.V. Suresh Babu
 

What's hot (20)

Computer system
Computer systemComputer system
Computer system
 
Open MPI
Open MPIOpen MPI
Open MPI
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linux
 
Evolution of operating system
Evolution of operating systemEvolution of operating system
Evolution of operating system
 
Cs1 3-operating systems
Cs1 3-operating systemsCs1 3-operating systems
Cs1 3-operating systems
 
PyCharm demo
PyCharm demoPyCharm demo
PyCharm demo
 
Operating systems
Operating systemsOperating systems
Operating systems
 
Apache web server
Apache web serverApache web server
Apache web server
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Operating systems
Operating systemsOperating systems
Operating systems
 
Windows Architecture
Windows ArchitectureWindows Architecture
Windows Architecture
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Operating system
Operating systemOperating system
Operating system
 
Introduction and history of linux
Introduction and history of linuxIntroduction and history of linux
Introduction and history of linux
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Mainframe
MainframeMainframe
Mainframe
 
MPI Introduction
MPI IntroductionMPI Introduction
MPI Introduction
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Ipc in linux
Ipc in linuxIpc in linux
Ipc in linux
 

Similar to Message Passing Interface (MPI)-A means of machine communication

Lecture9
Lecture9Lecture9
Lecture9
tt_aljobory
 
Tutorial on Parallel Computing and Message Passing Model - C2
Tutorial on Parallel Computing and Message Passing Model - C2Tutorial on Parallel Computing and Message Passing Model - C2
Tutorial on Parallel Computing and Message Passing Model - C2
Marcirio Chaves
 
High Performance Computing using MPI
High Performance Computing using MPIHigh Performance Computing using MPI
High Performance Computing using MPI
Ankit Mahato
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
Akhila Prabhakaran
 
Presentation - Programming a Heterogeneous Computing Cluster
Presentation - Programming a Heterogeneous Computing ClusterPresentation - Programming a Heterogeneous Computing Cluster
Presentation - Programming a Heterogeneous Computing Cluster
Aashrith Setty
 
Programming using MPI and OpenMP
Programming using MPI and OpenMPProgramming using MPI and OpenMP
Programming using MPI and OpenMP
Divya Tiwari
 
Parallel computing(2)
Parallel computing(2)Parallel computing(2)
Parallel computing(2)
Md. Mahedi Mahfuj
 
Parallel programming using MPI
Parallel programming using MPIParallel programming using MPI
Parallel programming using MPI
Ajit Nayak
 
MPI
MPIMPI
My ppt hpc u4
My ppt hpc u4My ppt hpc u4
Advanced Scalable Decomposition Method with MPICH Environment for HPC
Advanced Scalable Decomposition Method with MPICH Environment for HPCAdvanced Scalable Decomposition Method with MPICH Environment for HPC
Advanced Scalable Decomposition Method with MPICH Environment for HPC
IJSRD
 
25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx
GopalPatidar13
 
Python programming 2nd
Python programming 2ndPython programming 2nd
Python programming 2nd
Aishwarya Deshmukh
 
More mpi4py
More mpi4pyMore mpi4py
More mpi4py
A Jorge Garcia
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
Mugilvannan11
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
Akhil Kaushik
 
MPI Sessions: a proposal to the MPI Forum
MPI Sessions: a proposal to the MPI ForumMPI Sessions: a proposal to the MPI Forum
MPI Sessions: a proposal to the MPI Forum
Jeff Squyres
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
yaman dua
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
marvellous2
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 

Similar to Message Passing Interface (MPI)-A means of machine communication (20)

Lecture9
Lecture9Lecture9
Lecture9
 
Tutorial on Parallel Computing and Message Passing Model - C2
Tutorial on Parallel Computing and Message Passing Model - C2Tutorial on Parallel Computing and Message Passing Model - C2
Tutorial on Parallel Computing and Message Passing Model - C2
 
High Performance Computing using MPI
High Performance Computing using MPIHigh Performance Computing using MPI
High Performance Computing using MPI
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
Presentation - Programming a Heterogeneous Computing Cluster
Presentation - Programming a Heterogeneous Computing ClusterPresentation - Programming a Heterogeneous Computing Cluster
Presentation - Programming a Heterogeneous Computing Cluster
 
Programming using MPI and OpenMP
Programming using MPI and OpenMPProgramming using MPI and OpenMP
Programming using MPI and OpenMP
 
Parallel computing(2)
Parallel computing(2)Parallel computing(2)
Parallel computing(2)
 
Parallel programming using MPI
Parallel programming using MPIParallel programming using MPI
Parallel programming using MPI
 
MPI
MPIMPI
MPI
 
My ppt hpc u4
My ppt hpc u4My ppt hpc u4
My ppt hpc u4
 
Advanced Scalable Decomposition Method with MPICH Environment for HPC
Advanced Scalable Decomposition Method with MPICH Environment for HPCAdvanced Scalable Decomposition Method with MPICH Environment for HPC
Advanced Scalable Decomposition Method with MPICH Environment for HPC
 
25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx
 
Python programming 2nd
Python programming 2ndPython programming 2nd
Python programming 2nd
 
More mpi4py
More mpi4pyMore mpi4py
More mpi4py
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
MPI Sessions: a proposal to the MPI Forum
MPI Sessions: a proposal to the MPI ForumMPI Sessions: a proposal to the MPI Forum
MPI Sessions: a proposal to the MPI Forum
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 

Recently uploaded

AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 

Recently uploaded (20)

AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 

Message Passing Interface (MPI)-A means of machine communication

  • 2. Content MPI 1. Definition 2. Reason For Using MPI 3. History And Evolution 4. General MPI Program Structure 5. Writing MPI PROGRAMS 6. Compiling MPI Programs 7. Running MPI Programs 8. Environment Management Routines
  • 3. MPI Message Passing Interface A means of machine communication DEFINITION • The Message passing interface Standard is a message passing library industry standard for parallel programming based on the consensus of the MPI forum which has over 40 participating organization, including vendors, researchers software library developers, and users • MPI provides widely used standard for writing message passing programs.
  • 4. Motivation Motivated by high computational complexity and memory requirements of large applications.
  • 5. HISTORY AND EVOLUTION • Late 1980s: vendors had unique libraries • 1989: ParallelVirtual Machine (PVM) developed at Oak Ridge National Lab • 1992:Work on MPI standard begun • 1994:Version 1.0 of MPI standard • June 1995 MPI 1.1 published (clarifications) • July 1996 MPI 1.2 published (clarifications) • April 1995 MPI 2.0 committee formed • July 1997 MPI 2.0 published
  • 6. MPI CONCEPT •MPI uses objects called communicators and groups to define which collection of processes may communicate with each other. •Most MPI routines require you to specify a communicator as an argument. •Communicators and groups will be covered in more detail later. For now, simply use MPI_COMM_WORLD whenever a communicator is required - it is the predefined communicator that includes all of your MPI processes.
  • 7. Rank: • Within a communicator, every process has its own unique, integer identifier assigned by the system when the process initializes. • A rank is sometimes also called a "task ID". • Ranks are contiguous and begin at zero. • Used by the programmer to specify the source and destination of messages. Size : • Within a communicator, no of processes is defined as size.
  • 8. General MPI Program Structure: MPI include file Initialize MPI Environment Do work and make messaging passing calls Terminate MPI Environment Variables declaration Parallel code begins
  • 9. Include Files #include <mpi.h> • MPI header file #include <stdio.h> • Standard I/O header file Variables int main (int argc, char *argv[]) { int i; int id; /* Process rank */ int p; /* Number of processes */ void check_circuit (int, int); • Include argc and argv: they are needed to initialize MPI • One copy of every variable for each process running this program argc=argument count ie. Gives the total number argument given argv[]= pointer the argument value
  • 10. Initialize MPI ENVIRONMENT MPI_Init (&argc, &argv); • First MPI function called by each process • Not necessarily first executable statement • Allows system to do any necessary setup Parameters argc [in] Pointer to the number of arguments . argv [in] Pointer to the argument vector Terminate MPI ENVIRONMENT MPI_Finalize(); • Call after all other MPI library calls • Allows system to free up MPI resources
  • 11. WRITING MPI PROGRAMS #include "mpi.h" // Gives basic MPI types, definitions #include <stdio.h> int main( argc, argv ) int argc; char **argv; { MPI_Init( &argc, &argv ); // Starts MPI :: Actual code including normal ‘C’ calls and MPI calls :: MPI_Finalize(); // Ends MPI return 0; }
  • 12. Compiling MPI Programs Compile step: mpicc -o <object file> <source code>.c ( By default the output file is a. out) Compilation commands • – mpicc -o hello_world hello-world.c Running MPI Programs Execution steps: mpiexec/mpirun -np <i> <object file> • To run hello_world on two machines: mpirun -np 2 hello_world Must specify full path of ‘executable’ • To know the commands executed by mpirun mpirun –t • To get all the mpirun options mpirun –help
  • 13. Environment Management Routines MPI environment management routines are used for initializing and terminating the MPI environment, querying the environment etc. Most of the commonly used ones are: • MPI_Init • MPI_Comm_size • MPI_Comm_rank • MPI_Get_processor_name • MPI_Finalize
  • 14. MPI_Comm_size Determines the number of processes in the group associated with a communicator. int MPI_Comm_size( MPI_Comm comm, int *size); Parameters • comm [in] communicator (handle) • size [out] number of processes in the group of comm (integer). MPI_Comm_size(MPI_COMM_WORLD, &size) MPI_Comm_rank Determines the rank of the calling process in the communicator. int MPI_Comm_rank( MPI_Comm comm, int *rank); Parameters • comm [in] communicator (handle) • rank [out] rank of the calling process in the group of comm(integer) MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  • 15. MPI_Get_processor_name Gets the name of the processor. int MPI_Get_processor_name( char *name, int *resultlen ); Parameters • name [out] A unique specifier for the actual node.This must be an array of size at least MPI_MAX_PROCESSOR_NAME. • resultlen [out] Length (in characters) of the name MPI_Get_processor_name(&name, &resultlength)