Chapter 4 Message-Passing Programming. Learning Objectives Understanding how MPI programs execute Understanding how MPI programs execute Familiarity with.

Slides:



Advertisements
Similar presentations
Practical techniques & Examples
Advertisements

Its.unc.edu 1 Collective Communication University of North Carolina - Chapel Hill ITS - Research Computing Instructor: Mark Reed
MPI Basics Introduction to Parallel Programming and Cluster Computing University of Washington/Idaho State University MPI Basics Charlie Peck Earlham College.
Chapter 3. MPI MPI = Message Passing Interface Specification of message passing libraries for developers and users –Not a library by itself, but specifies.
Parallel Programming in C with MPI and OpenMP
Reference: / MPI Program Structure.
Chapter 4 Message-Passing Programming. 2 Outline Message-passing model Message Passing Interface (MPI) Coding MPI programs Compiling MPI programs Running.
Introduction to MPI. What is Message Passing Interface (MPI)?  Portable standard for communication  Processes can communicate through messages.  Each.
1 Parallel Computing—Higher-level concepts of MPI.
Distributed Memory Programming with MPI. What is MPI? Message Passing Interface (MPI) is an industry standard message passing system designed to be both.
1 CS 668: Lecture 2 An Introduction to MPI Fred Annexstein University of Cincinnati CS668: Parallel Computing Fall 2007 CC Some.
Parallel Programming in C with MPI and OpenMP
EECC756 - Shaaban #1 lec # 7 Spring Message Passing Interface (MPI) MPI, the Message Passing Interface, is a library, and a software standard.
Collective Communication.  Collective communication is defined as communication that involves a group of processes  More restrictive than point to point.
Message Passing Interface. Message Passing Interface (MPI) Message Passing Interface (MPI) is a specification designed for parallel applications. The.
Jonathan Carroll-Nellenback CIRC Summer School MESSAGE PASSING INTERFACE (MPI)
Parallel Programming with Java
Parallel Processing1 Parallel Processing (CS 676) Lecture 7: Message Passing using MPI * Jeremy R. Johnson *Parts of this lecture was derived from chapters.
Director of Contra Costa College High Performance Computing Center
Parallel Programming and Algorithms – MPI Collective Operations David Monismith CS599 Feb. 10, 2015 Based upon MPI: A Message-Passing Interface Standard.
1 Collective Communications. 2 Overview  All processes in a group participate in communication, by calling the same function with matching arguments.
1 MPI: Message-Passing Interface Chapter 2. 2 MPI - (Message Passing Interface) Message passing library standard (MPI) is developed by group of academics.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
Parallel Programming with MPI Prof. Sivarama Dandamudi School of Computer Science Carleton University.
Message Passing Programming with MPI Introduction to MPI Basic MPI functions Most of the MPI materials are obtained from William Gropp and Rusty Lusk’s.
Hybrid MPI and OpenMP Parallel Programming
CS 838: Pervasive Parallelism Introduction to MPI Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from an online tutorial.
Message Passing Programming Model AMANO, Hideharu Textbook pp. 140-147.
Summary of MPI commands Luis Basurto. Large scale systems Shared Memory systems – Memory is shared among processors Distributed memory systems – Each.
MPI Introduction to MPI Commands. Basics – Send and Receive MPI is a message passing environment. The processors’ method of sharing information is NOT.
Parallel Programming with MPI By, Santosh K Jena..
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd Edition, by B. Wilkinson & M. Allen, ©
Chapter 4 Message-Passing Programming. The Message-Passing Model.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
Oct. 23, 2002Parallel Processing1 Parallel Processing (CS 730) Lecture 6: Message Passing using MPI * Jeremy R. Johnson *Parts of this lecture was derived.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Message-passing Model.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
Task/ChannelMessage-passing TaskProcess Explicit channelsMessage communication.
Introduction to MPI CDP 1. Shared Memory vs. Message Passing Shared Memory Implicit communication via memory operations (load/store/lock) Global address.
MPI and OpenMP.
Programming distributed memory systems: Message Passing Interface (MPI) Distributed memory systems: multiple processing units working on one task (e.g.
An Introduction to MPI (message passing interface)
MPI - A User level Message-passing Interface K. Ramakrishna Shenai.
3/12/2013Computer Engg, IIT(BHU)1 MPI-1. MESSAGE PASSING INTERFACE A message passing library specification Extended message-passing model Not a language.
-1.1- MPI Lectured by: Nguyễn Đức Thái Prepared by: Thoại Nam.
Message Passing Interface Using resources from
Lecture 3: Today’s topics MPI Broadcast (Quinn Chapter 5) –Sieve of Eratosthenes MPI Send and Receive calls (Quinn Chapter 6) –Floyd’s algorithm Other.
MPI-Message Passing Interface. What is MPI?  MPI is a specification for the developers and users of message passing libraries. By itself, it is NOT a.
Computer Science Department
Introduction to MPI Programming Ganesh C.N.
Collectives Reduce Scatter Gather Many more.
MPI Basics.
CS4402 – Parallel Computing
MPI Message Passing Interface
CS 668: Lecture 3 An Introduction to MPI
Computer Science Department
Send and Receive.
Collective Communication with MPI
CS 584.
An Introduction to Parallel Programming with MPI
Programming with MPI.
Send and Receive.
Introduction to Message Passing Interface (MPI)
Lecture 14: Inter-process Communication
MPI: Message Passing Interface
CSCE569 Parallel Computing
MPI MPI = Message Passing Interface
Hardware Environment VIA cluster - 8 nodes Blade Server – 5 nodes
Computer Science Department
CS 584 Lecture 8 Assignment?.
Presentation transcript:

Chapter 4 Message-Passing Programming

Learning Objectives Understanding how MPI programs execute Understanding how MPI programs execute Familiarity with fundamental MPI functions Familiarity with fundamental MPI functions

Outline Message-passing model Message-passing model Message Passing Interface (MPI) Message Passing Interface (MPI) Coding MPI programs Coding MPI programs Compiling MPI programs Compiling MPI programs Running MPI programs Running MPI programs Benchmarking MPI programs Benchmarking MPI programs

Message-passing Model

Task/Channel vs. Message-passing Task/ChannelMessage-passing TaskProcess Explicit channelsMessage communication

Processes Number is specified at start-up time Number is specified at start-up time Remains constant throughout execution of program Remains constant throughout execution of program All execute same program All execute same program Each has unique ID number Each has unique ID number Alternately performs computations and communications Alternately performs computations and communications

Advantages of Message-passing Model Portability to many architectures Portability to many architectures Gives programmer ability to manage the memory hierarchy Gives programmer ability to manage the memory hierarchy

The Message Passing Interface Late 1980s: vendors had unique libraries Late 1980s: vendors had unique libraries 1989: Parallel Virtual Machine (PVM) developed at Oak Ridge National Lab 1989: Parallel Virtual Machine (PVM) developed at Oak Ridge National Lab 1992: Work on MPI standard begun 1992: Work on MPI standard begun 1994: Version 1.0 of MPI standard 1994: Version 1.0 of MPI standard 1997: Version 2.0 of MPI standard 1997: Version 2.0 of MPI standard Today: MPI (and PVM) are dominant message passing library standards Today: MPI (and PVM) are dominant message passing library standards

Circuit Satisfiability Not satisfied 0

Solution Method Circuit satisfiability is NP-complete Circuit satisfiability is NP-complete No known algorithms to solve in polynomial time No known algorithms to solve in polynomial time We seek all solutions We seek all solutions We find through exhaustive search We find through exhaustive search 16 inputs  65,536 combinations to test 16 inputs  65,536 combinations to test

Partitioning: Functional Decomposition Embarrassingly parallel: No channels between tasks Embarrassingly parallel: No channels between tasks

Agglomeration and Mapping Properties of parallel algorithm Properties of parallel algorithm  Fixed number of tasks  No communications between tasks  Time needed per task is variable Consult mapping strategy decision tree Consult mapping strategy decision tree  Map tasks to processors in a cyclic fashion

Cyclic (interleaved) Allocation Assume p processes Assume p processes Each process gets every p th piece of work Each process gets every p th piece of work Example: 5 processes and 12 pieces of work Example: 5 processes and 12 pieces of work  P 0 : 0, 5, 10  P 1 : 1, 6, 11  P 2 : 2, 7  P 3 : 3, 8  P 4 : 4, 9

Pop Quiz Assume n pieces of work, p processes, and cyclic allocation Assume n pieces of work, p processes, and cyclic allocation What is the most pieces of work any process has? What is the most pieces of work any process has? What is the least pieces of work any process has? What is the least pieces of work any process has? How many processes have the most pieces of work? How many processes have the most pieces of work?

Summary of Program Design Program will consider all 65,536 combinations of 16 boolean inputs Program will consider all 65,536 combinations of 16 boolean inputs Combinations allocated in cyclic fashion to processes Combinations allocated in cyclic fashion to processes Each process examines each of its combinations Each process examines each of its combinations If it finds a satisfiable combination, it will print it If it finds a satisfiable combination, it will print it

Include Files MPI header file MPI header file #include Standard I/O header file Standard I/O header file #include

Local 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 Include argc and argv : they are needed to initialize MPI One copy of every variable for each process running this program One copy of every variable for each process running this program

Initialize MPI First MPI function called by each process First MPI function called by each process Not necessarily first executable statement Not necessarily first executable statement Allows system to do any necessary setup Allows system to do any necessary setup MPI_Init (&argc, &argv);

Communicators Communicator: Group of processes Communicator: Group of processes  opaque object that provides message-passing environment for processes MPI_COMM_WORLD MPI_COMM_WORLD  Default communicator  Includes all processes Possible to create new communicators Possible to create new communicators  Will do this in Chapters 8 and 9

Communicator MPI_COMM_WORLD Communicator Processes Ranks Communicator Name

Determine Number of Processes First argument is communicator First argument is communicator Number of processes returned through second argument Number of processes returned through second argument MPI_Comm_size (MPI_COMM_WORLD, &p);

Determine Process Rank First argument is communicator First argument is communicator Process rank (in range 0, 1, …, p-1) returned through second argument Process rank (in range 0, 1, …, p-1) returned through second argument MPI_Comm_rank (MPI_COMM_WORLD, &id);

Replication of Automatic Variables 0 id 6 p 4 6 p 2 6 p 1 6 p 5 6 p 3 6 p

What about External Variables? int total; int main (int argc, char *argv[]) { int i; int id; int p; … Where is variable total stored? Where is variable total stored?

Cyclic Allocation of Work for (i = id; i < 65536; i += p) check_circuit (id, i); Parallelism is outside function check_circuit Parallelism is outside function check_circuit It can be an ordinary, sequential function It can be an ordinary, sequential function

Shutting Down MPI Call after all other MPI library calls Call after all other MPI library calls Allows system to free up MPI resources Allows system to free up MPI resources MPI_Finalize();

#include #include int main (int argc, char *argv[]) { int i; int id; int p; void check_circuit (int, int); MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &id); MPI_Comm_size (MPI_COMM_WORLD, &p); for (i = id; i < 65536; i += p) check_circuit (id, i); printf ("Process %d is done\n", id); fflush (stdout); MPI_Finalize(); return 0; } Put fflush() after every printf()

/* Return 1 if 'i'th bit of 'n' is 1; 0 otherwise */ #define EXTRACT_BIT(n,i) ((n&(1<<i))?1:0) void check_circuit (int id, int z) { int v[16]; /* Each element is a bit of z */ int i; for (i = 0; i < 16; i++) v[i] = EXTRACT_BIT(z,i); if ((v[0] || v[1]) && (!v[1] || !v[3]) && (v[2] || v[3]) && (!v[3] || !v[4]) && (v[4] || !v[5]) && (v[5] || !v[6]) && (v[5] || v[6]) && (v[6] || !v[15]) && (v[7] || !v[8]) && (!v[7] || !v[13]) && (v[8] || v[9]) && (v[8] || !v[9]) && (!v[9] || !v[10]) && (v[9] || v[11]) && (v[10] || v[11]) && (v[12] || v[13]) && (v[13] || !v[14]) && (v[14] || v[15])) { printf ("%d) %d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d\n", id, v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9], v[10],v[11],v[12],v[13],v[14],v[15]); fflush (stdout); }

Compiling MPI Programs mpicc: script to compile and link C+MPI programs mpicc: script to compile and link C+MPI programs Flags: same meaning as C compiler Flags: same meaning as C compiler  -lmpi link with mpi library  -O  optimize  See ‘man cc’ for O1, O2, and O3 levels  -o  where to put executable cc -O -lmpi -o foo foo.c (hydra) mpicc -O -o foo foo.c

Running MPI Programs mpirun foo … (hydra) mpirun foo … (hydra) mpirun -np … mpirun -np …  -np  number of processes   executable  …  command-line arguments

Specifying Host Processors File.mpi-machines in home directory lists host processors in order of their use File.mpi-machines in home directory lists host processors in order of their use Example.mpi_machines file contents Example.mpi_machines file contentsband01.cs.ppu.eduband02.cs.ppu.eduband03.cs.ppu.eduband04.cs.ppu.edu

Enabling Remote Logins MPI needs to be able to initiate processes on other processors without supplying a password MPI needs to be able to initiate processes on other processors without supplying a password Each processor in group must list all other processors in its.rhosts file; e.g., Each processor in group must list all other processors in its.rhosts file; e.g., band01.cs.ppu.edu student band02.cs.ppu.edu student band03.cs.ppu.edu student band04.cs.ppu.edu student

Execution on 1 CPU % mpirun -np 1 sat 0) ) ) ) ) ) ) ) ) Process 0 is done

Execution on 2 CPUs % mpirun -np 2 sat 0) ) ) ) ) ) ) ) ) Process 0 is done Process 1 is done

Execution on 3 CPUs % mpirun -np 3 sat 0) ) ) ) ) ) ) ) ) Process 1 is done Process 2 is done Process 0 is done

Deciphering Output Output order only partially reflects order of output events inside parallel computer Output order only partially reflects order of output events inside parallel computer If process A prints two messages, first message will appear before second If process A prints two messages, first message will appear before second If process A calls printf before process B, there is no guarantee process A’s message will appear before process B’s message If process A calls printf before process B, there is no guarantee process A’s message will appear before process B’s message

Enhancing the Program We want to find total number of solutions We want to find total number of solutions Incorporate sum-reduction into program Incorporate sum-reduction into program Reduction is a collective communication Reduction is a collective communication

Modifications Modify function check_circuit Modify function check_circuit  Return 1 if circuit satisfiable with input combination  Return 0 otherwise Each process keeps local count of satisfiable circuits it has found Each process keeps local count of satisfiable circuits it has found Perform reduction after for loop Perform reduction after for loop

New Declarations and Code int count; /* Local sum */ int global_count; /* Global sum */ int check_circuit (int, int); count = 0; for (i = id; i < 65536; i += p) count += check_circuit (id, i); count += check_circuit (id, i);

Prototype of MPI_Reduce() int MPI_Reduce ( void *operand, /* addr of 1st reduction element - this is an array */ void *result, /* addr of 1st reduction result - element-wise reduction of array (*operand)..(*operand+count-1) */ int count, /* reductions to perform */ MPI_Datatype type, /* type of elements */ MPI_Op operator, /* reduction operator */ int root, /* process getting result(s) */ MPI_Comm comm /* communicator */ )

MPI_Datatype Options MPI_CHAR MPI_CHAR MPI_DOUBLE MPI_DOUBLE MPI_FLOAT MPI_FLOAT MPI_INT MPI_INT MPI_LONG MPI_LONG MPI_LONG_DOUBLE MPI_LONG_DOUBLE MPI_SHORT MPI_SHORT MPI_UNSIGNED_CHAR MPI_UNSIGNED_CHAR MPI_UNSIGNED MPI_UNSIGNED MPI_UNSIGNED_LONG MPI_UNSIGNED_LONG MPI_UNSIGNED_SHORT MPI_UNSIGNED_SHORT

MPI_Op Options MPI_BAND MPI_BAND MPI_BOR MPI_BOR MPI_BXOR MPI_BXOR MPI_LAND MPI_LAND MPI_LOR MPI_LOR MPI_LXOR MPI_LXOR MPI_MAX MPI_MAX MPI_MAXLOC MPI_MAXLOC MPI_MIN MPI_MIN MPI_MINLOC MPI_MINLOC MPI_PROD MPI_PROD MPI_SUM MPI_SUM

Our Call to MPI_Reduce() MPI_Reduce (&count, &global_count, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); Only process 0 will get the result if (!id) printf ("There are %d different solutions\n", global_count);

Execution of Second Program % mpirun -np 3 seq2 0) ) ) ) ) ) ) ) ) Process 1 is done Process 2 is done Process 0 is done There are 9 different solutions

Benchmarking the Program MPI_Barrier  barrier synchronization MPI_Barrier  barrier synchronization MPI_Wtick  timer resolution MPI_Wtick  timer resolution MPI_Wtime  current time MPI_Wtime  current time

Benchmarking Code double elapsed_time; … MPI_Init (&argc, &argv); MPI_Barrier (MPI_COMM_WORLD); elapsed_time = - MPI_Wtime(); … MPI_Reduce (…); elapsed_time += MPI_Wtime(); /* better, remove barrier, and take the max of individual processes’ execution times */

Benchmarking Results Processors Time (sec)

Benchmarking Results

Summary (1/2) Message-passing programming follows naturally from task/channel model Message-passing programming follows naturally from task/channel model Portability of message-passing programs Portability of message-passing programs MPI most widely adopted standard MPI most widely adopted standard

Summary (2/2) MPI functions introduced MPI functions introduced  MPI_Init  MPI_Comm_rank  MPI_Comm_size  MPI_Reduce  MPI_Finalize  MPI_Barrier  MPI_Wtime  MPI_Wtick