0% found this document useful (0 votes)
64 views42 pages

3 Mpi

Uploaded by

spareyash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views42 pages

3 Mpi

Uploaded by

spareyash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 42

MPI-1

Lecture 3
January 15, 2024
Adapted from Neha Karanjkar’s slides

2
Parallel Execution – Single Node

Core
Process
Memory

$ ps
Instruction 1 Instruction 1 Instruction 1 Instruction 1
Instruction 2 Instruction 2 Instruction 2 Instruction 2 parallel.x
… … … … parallel.x
parallel.x parallel.x parallel.x parallel.x parallel.x
parallel.x

mpirun -np 4 ./parallel.x

3
Access Latency (Intel KNL)

Simulating the Network Activity of


Modern Manycores, IEEE Access 2019 4
Cores

Simulating the Network Activity of


Modern Manycores, IEEE Access 2019 5
Parallel Execution – Multiple
Nodes

Core
Process
Memory

Instruction 1 Instruction 1 Instruction 1 Instruction 1


Instruction 2 Instruction 2 Instruction 2 Instruction 2
… … … …

parallel.x parallel.x parallel.x parallel.x SIMD


parallel.x parallel.x parallel.x parallel.x

mpirun -np 8 ./parallel.x

6
MPI Code On Multiple Nodes
• mpirun -np 8 –f hostfile ./program.x
• Round robin process placement
• mpirun -np 8 –hosts h1,h2,h3,h4 ./program.x
• Host-wise placement
• mpirun -np 8 –hosts h1:2,h2:2,h3:2,h4:2 ./program.x

7
Parallel Execution – Multiple
Nodes

Core
Process
Memory

Instruction 1 Instruction 1 Instruction 1 Instruction 1


Instruction 2 Instruction 2 Instruction 2 Instruction 2
… … … …

parallel.x parallel.x parallel.x parallel.x


parallel.x parallel.x parallel.x parallel.x

mpirun -np 8 -hosts h1,h2,h3,h4 ./program.x


mpirun -np 8 -hosts h1:2,h2:2,h3:2,h4:2 ./program.x
8
Parallel Sum (Optimized)

Source: GGKK Chapter 5 9


Getting Started

• gather information about the


parallel job
• set up internal library state
• prepare for communication

Initialization

Finalization

10
MPI Process Identification
Global
communicator

Total number
of processes

Rank of a
process

11
Entities
Communicator (communication handle)
• Defines the scope
• Specifies communication context

Process
• Belongs to a group
• Identified by a rank within a group

Identification
• MPI_Comm_size – total number of processes in communicator
• MPI_Comm_rank – rank in the communicator
12
MPI_COMM_WORLD

• Required in every MPI communication


• Process identified by rank/id

3
2

0 4

13
Communicator
• Communication handle among a group/collection of processes
• Representative of communication domain
• Associated with a context ID (in MPICH)
• Predefined:
• MPI_COMM_WORLD
• MPI_COMM_SELF

14
Output
// get number of tasks
MPI_Comm_size (MPI_COMM_WORLD, &numtasks);

// get my rank
MPI_Comm_rank (MPI_COMM_WORLD, &rank);

printf (“Hello I’m rank %d of %d processes\n”, rank, numtasks);

mpiexec –n 4 –hosts host1,host2,host3,host4 ./exe


mpiexec –n 4 –hosts host1:2,host2:2,host3:2,host4:2 ./exe
mpiexec –n 8 –hosts host1,host2,host3,host4 ./exe
mpiexec –n 8 –hosts host1:1,host2:2,host3:3,host4:4 ./exe
15
Host

16
Process Launch
Memory

MPI MPI MPI MPI


process process process process
Launch node

Reading (optional):
A Scalable Process-Management Environment for Parallel Programs
17
Parallel Environment
• Job scheduler
• Resources to run the parallel job
• Process manager
• Starts and stops the processes
• Parallel library
• Application calls for communication

18
Multiprocess Daemon

Butler et al., EuroPVM/MPI2000

19
Process Management Setup
Parallel program
library (e.g. MPI)
Process
management
interface (PMI)

Resource manager/
Job scheduler/
Process Manager

Reading (optional):
PMI: A Scalable Parallel Process-Management Interface for Extreme-Scale Systems 20
Process Manager

• Start and stop processes in a scalable way


• Setup communication channels for parallel processes
• stdin/stdout/stderr forwarding
• ./a.out 2>efile

21
Process Management Interface

• Interface between process manager and MPI library


• Processes can exchange information about peers by
querying PMI
• Uses key-value store for process-related data

22
Process Launch
Memory

MPI MPI MPI MPI


process process process process

PMI PMI PMI PMI

23
Process Launch
Memory

PMI PMI PMI PMI


KVS $ KVS $ KVS $ KVS $

24
Hydra Process Manager
• A process management system for starting parallel jobs
• Uses existing daemons (viz. ssh) to start MPI processes
• Automatically detects resource managers if any and interacts
with them
• $ mpiexec ./app
• Hydra gets information about allocated resources and
launches processes
• Passes environment variables from the shell on which
mpiexec is launched to the launched processes

There are others – gforker, slurm, etc.


25
mpiexec
Memory

host1 host2 host3 host4

Launch node
Proxy Proxy Proxy Proxy

mpiexec –n 4 –hosts host1,host2,host3,host4 ./exe

26
Launch Node
mpiexec -np 8 -hosts host1:3,host2:3,host3:3 ./exe

27
Compute Node Processes

28
Hydra and mpiexec

Source: wiki.mpich.org
29
MPI Process Management
Initializes
and queries
PMI

30
csews*
lscpu

31
Multiple Tasks Core ID

Get the
core ID

32
Process Placement

33
Process Placement

34
Executing MPI programs
• Check `which mpicc` and `which mpiexec`
• Update PATH environment variable
• Compile
• mpicc –o filename filename.c
• Run
• mpiexec –np 4 –f hostfile filename [Often “No such file” error]
• mpiexec –np 4 –f hostfile ./filename

35
Resources for MPI

• Marc Snir, Steve W. Otto, Steven Huss-Lederman, David W.


Walker and Jack Dongarra,
MPI - The Complete Reference, Second Edition, Volume 1, The
MPI Core.
• William Gropp, Ewing Lusk, Anthony Skjellum,
Using MPI: portable parallel programming with the message-
passing interface, 3rd Ed., Cambridge MIT Press, 2014.
• https://www.mpi-forum.org/docs/mpi-4.0/mpi40-report.pdf

36
Message Passing Paradigm
• Message sends and receives
• Explicit communication

Communication patterns
• Point-to-point
• Collective

37
Communication – Message Passing

Process 0 Process 1

38
Message Passing

Process 0 Process 1 Process 2 Process 3

39
MPI Basics
• Process is identified by rank
• Communicator specifies communication context

Message Envelope

Source
Destination
Communicator
Tag (0:MPI_TAG_UB)

40
MPI Data Types
• MPI_BYTE
• MPI_CHAR
• MPI_INT
• MPI_FLOAT
• MPI_DOUBLE

41
Point-to-point Communication
MPI_Send Blocking send and receive
int MPI_Send (const void *buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm)
SENDER

Tags should match


MPI_Recv
int MPI_Recv (void *buf, int count,
MPI_Datatype datatype, int source, int tag,
MPI_Comm comm, MPI_Status *status)
RECEIVER
42

You might also like