- •Contents
- •List of Figures
- •List of Tables
- •Acknowledgments
- •Introduction to MPI
- •Overview and Goals
- •Background of MPI-1.0
- •Background of MPI-1.1, MPI-1.2, and MPI-2.0
- •Background of MPI-1.3 and MPI-2.1
- •Background of MPI-2.2
- •Who Should Use This Standard?
- •What Platforms Are Targets For Implementation?
- •What Is Included In The Standard?
- •What Is Not Included In The Standard?
- •Organization of this Document
- •MPI Terms and Conventions
- •Document Notation
- •Naming Conventions
- •Semantic Terms
- •Data Types
- •Opaque Objects
- •Array Arguments
- •State
- •Named Constants
- •Choice
- •Addresses
- •Language Binding
- •Deprecated Names and Functions
- •Fortran Binding Issues
- •C Binding Issues
- •C++ Binding Issues
- •Functions and Macros
- •Processes
- •Error Handling
- •Implementation Issues
- •Independence of Basic Runtime Routines
- •Interaction with Signals
- •Examples
- •Point-to-Point Communication
- •Introduction
- •Blocking Send and Receive Operations
- •Blocking Send
- •Message Data
- •Message Envelope
- •Blocking Receive
- •Return Status
- •Passing MPI_STATUS_IGNORE for Status
- •Data Type Matching and Data Conversion
- •Type Matching Rules
- •Type MPI_CHARACTER
- •Data Conversion
- •Communication Modes
- •Semantics of Point-to-Point Communication
- •Buffer Allocation and Usage
- •Nonblocking Communication
- •Communication Request Objects
- •Communication Initiation
- •Communication Completion
- •Semantics of Nonblocking Communications
- •Multiple Completions
- •Non-destructive Test of status
- •Probe and Cancel
- •Persistent Communication Requests
- •Send-Receive
- •Null Processes
- •Datatypes
- •Derived Datatypes
- •Type Constructors with Explicit Addresses
- •Datatype Constructors
- •Subarray Datatype Constructor
- •Distributed Array Datatype Constructor
- •Address and Size Functions
- •Lower-Bound and Upper-Bound Markers
- •Extent and Bounds of Datatypes
- •True Extent of Datatypes
- •Commit and Free
- •Duplicating a Datatype
- •Use of General Datatypes in Communication
- •Correct Use of Addresses
- •Decoding a Datatype
- •Examples
- •Pack and Unpack
- •Canonical MPI_PACK and MPI_UNPACK
- •Collective Communication
- •Introduction and Overview
- •Communicator Argument
- •Applying Collective Operations to Intercommunicators
- •Barrier Synchronization
- •Broadcast
- •Example using MPI_BCAST
- •Gather
- •Examples using MPI_GATHER, MPI_GATHERV
- •Scatter
- •Examples using MPI_SCATTER, MPI_SCATTERV
- •Example using MPI_ALLGATHER
- •All-to-All Scatter/Gather
- •Global Reduction Operations
- •Reduce
- •Signed Characters and Reductions
- •MINLOC and MAXLOC
- •All-Reduce
- •Process-local reduction
- •Reduce-Scatter
- •MPI_REDUCE_SCATTER_BLOCK
- •MPI_REDUCE_SCATTER
- •Scan
- •Inclusive Scan
- •Exclusive Scan
- •Example using MPI_SCAN
- •Correctness
- •Introduction
- •Features Needed to Support Libraries
- •MPI's Support for Libraries
- •Basic Concepts
- •Groups
- •Contexts
- •Intra-Communicators
- •Group Management
- •Group Accessors
- •Group Constructors
- •Group Destructors
- •Communicator Management
- •Communicator Accessors
- •Communicator Constructors
- •Communicator Destructors
- •Motivating Examples
- •Current Practice #1
- •Current Practice #2
- •(Approximate) Current Practice #3
- •Example #4
- •Library Example #1
- •Library Example #2
- •Inter-Communication
- •Inter-communicator Accessors
- •Inter-communicator Operations
- •Inter-Communication Examples
- •Caching
- •Functionality
- •Communicators
- •Windows
- •Datatypes
- •Error Class for Invalid Keyval
- •Attributes Example
- •Naming Objects
- •Formalizing the Loosely Synchronous Model
- •Basic Statements
- •Models of Execution
- •Static communicator allocation
- •Dynamic communicator allocation
- •The General case
- •Process Topologies
- •Introduction
- •Virtual Topologies
- •Embedding in MPI
- •Overview of the Functions
- •Topology Constructors
- •Cartesian Constructor
- •Cartesian Convenience Function: MPI_DIMS_CREATE
- •General (Graph) Constructor
- •Distributed (Graph) Constructor
- •Topology Inquiry Functions
- •Cartesian Shift Coordinates
- •Partitioning of Cartesian structures
- •Low-Level Topology Functions
- •An Application Example
- •MPI Environmental Management
- •Implementation Information
- •Version Inquiries
- •Environmental Inquiries
- •Tag Values
- •Host Rank
- •IO Rank
- •Clock Synchronization
- •Memory Allocation
- •Error Handling
- •Error Handlers for Communicators
- •Error Handlers for Windows
- •Error Handlers for Files
- •Freeing Errorhandlers and Retrieving Error Strings
- •Error Codes and Classes
- •Error Classes, Error Codes, and Error Handlers
- •Timers and Synchronization
- •Startup
- •Allowing User Functions at Process Termination
- •Determining Whether MPI Has Finished
- •Portable MPI Process Startup
- •The Info Object
- •Process Creation and Management
- •Introduction
- •The Dynamic Process Model
- •Starting Processes
- •The Runtime Environment
- •Process Manager Interface
- •Processes in MPI
- •Starting Processes and Establishing Communication
- •Reserved Keys
- •Spawn Example
- •Manager-worker Example, Using MPI_COMM_SPAWN.
- •Establishing Communication
- •Names, Addresses, Ports, and All That
- •Server Routines
- •Client Routines
- •Name Publishing
- •Reserved Key Values
- •Client/Server Examples
- •Ocean/Atmosphere - Relies on Name Publishing
- •Simple Client-Server Example.
- •Other Functionality
- •Universe Size
- •Singleton MPI_INIT
- •MPI_APPNUM
- •Releasing Connections
- •Another Way to Establish MPI Communication
- •One-Sided Communications
- •Introduction
- •Initialization
- •Window Creation
- •Window Attributes
- •Communication Calls
- •Examples
- •Accumulate Functions
- •Synchronization Calls
- •Fence
- •General Active Target Synchronization
- •Lock
- •Assertions
- •Examples
- •Error Handling
- •Error Handlers
- •Error Classes
- •Semantics and Correctness
- •Atomicity
- •Progress
- •Registers and Compiler Optimizations
- •External Interfaces
- •Introduction
- •Generalized Requests
- •Examples
- •Associating Information with Status
- •MPI and Threads
- •General
- •Initialization
- •Introduction
- •File Manipulation
- •Opening a File
- •Closing a File
- •Deleting a File
- •Resizing a File
- •Preallocating Space for a File
- •Querying the Size of a File
- •Querying File Parameters
- •File Info
- •Reserved File Hints
- •File Views
- •Data Access
- •Data Access Routines
- •Positioning
- •Synchronism
- •Coordination
- •Data Access Conventions
- •Data Access with Individual File Pointers
- •Data Access with Shared File Pointers
- •Noncollective Operations
- •Collective Operations
- •Seek
- •Split Collective Data Access Routines
- •File Interoperability
- •Datatypes for File Interoperability
- •Extent Callback
- •Datarep Conversion Functions
- •Matching Data Representations
- •Consistency and Semantics
- •File Consistency
- •Random Access vs. Sequential Files
- •Progress
- •Collective File Operations
- •Type Matching
- •Logical vs. Physical File Layout
- •File Size
- •Examples
- •Asynchronous I/O
- •I/O Error Handling
- •I/O Error Classes
- •Examples
- •Subarray Filetype Constructor
- •Requirements
- •Discussion
- •Logic of the Design
- •Examples
- •MPI Library Implementation
- •Systems with Weak Symbols
- •Systems Without Weak Symbols
- •Complications
- •Multiple Counting
- •Linker Oddities
- •Multiple Levels of Interception
- •Deprecated Functions
- •Deprecated since MPI-2.0
- •Deprecated since MPI-2.2
- •Language Bindings
- •Overview
- •Design
- •C++ Classes for MPI
- •Class Member Functions for MPI
- •Semantics
- •C++ Datatypes
- •Communicators
- •Exceptions
- •Mixed-Language Operability
- •Problems With Fortran Bindings for MPI
- •Problems Due to Strong Typing
- •Problems Due to Data Copying and Sequence Association
- •Special Constants
- •Fortran 90 Derived Types
- •A Problem with Register Optimization
- •Basic Fortran Support
- •Extended Fortran Support
- •The mpi Module
- •No Type Mismatch Problems for Subroutines with Choice Arguments
- •Additional Support for Fortran Numeric Intrinsic Types
- •Language Interoperability
- •Introduction
- •Assumptions
- •Initialization
- •Transfer of Handles
- •Status
- •MPI Opaque Objects
- •Datatypes
- •Callback Functions
- •Error Handlers
- •Reduce Operations
- •Addresses
- •Attributes
- •Extra State
- •Constants
- •Interlanguage Communication
- •Language Bindings Summary
- •Groups, Contexts, Communicators, and Caching Fortran Bindings
- •External Interfaces C++ Bindings
- •Change-Log
- •Bibliography
- •Examples Index
- •MPI Declarations Index
- •MPI Function Index
180 |
CHAPTER 5. COLLECTIVE COMMUNICATION |
1The \in place" option for intracommunicators is speci ed by passing MPI_IN_PLACE in
2the sendbuf argument. In this case, the input data is taken from the receive bu er. It is
3not required to specify the \in place" option on all processes, since the processes for which
4recvcounts[i]==0 may not have allocated a receive bu er.
5If comm is an intercommunicator, then the result of the reduction of the data provided
6by processes in one group (group A) is scattered among processes in the other group (group
7B), and vice versa. Within each group, all processes provide the same recvcounts argument,
8 and provide input vectors of count = Pn 1 recvcounts[i] elements stored in the send bu ers,
i=0
9where n is the size of the group. The resulting vector from the other group is scattered in
10blocks of recvcounts[i] elements among the processes in the group. The number of elements
11count must be the same for the two groups.
12
13Rationale. The last restriction is needed so that the length of the send bu er can be
14determined by the sum of the local recvcounts entries. Otherwise, a communication
15is needed to gure out how many elements are reduced. (End of rationale.)
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
5.11 Scan
5.11.1 Inclusive Scan
MPI_SCAN( sendbuf, recvbuf, count, datatype, op, comm )
IN |
sendbuf |
starting address of send bu er (choice) |
OUT |
recvbuf |
starting address of receive bu er (choice) |
IN |
count |
number of elements in input bu er (non-negative in- |
|
|
teger) |
IN |
datatype |
data type of elements of input bu er (handle) |
IN |
op |
operation (handle) |
IN |
comm |
communicator (handle) |
34 int MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm )
MPI_SCAN(SENDBUF, RECVBUF, COUNT, DATATYPE, OP, COMM, IERROR)
<type> SENDBUF(*), RECVBUF(*)
38
INTEGER COUNT, DATATYPE, OP, COMM, IERROR
39
40 fvoid MPI::Intracomm::Scan(const void* sendbuf, void* recvbuf, int count,
41 const MPI::Datatype& datatype, const MPI::Op& op) const
(binding deprecated, see Section 15.2) g
If comm is an intracommunicator, MPI_SCAN is used to perform a pre x reduction on data distributed across the group. The operation returns, in the receive bu er of the process with rank i, the reduction of the values in the send bu ers of processes with ranks
46
0,...,i (inclusive). The type of operations supported, their semantics, and the constraints
47
on send and receive bu ers are as for MPI_REDUCE.
48
5.11. SCAN |
181 |
The \in place" option for intracommunicators is speci ed by passing MPI_IN_PLACE in the sendbuf argument. In this case, the input data is taken from the receive bu er, and replaced by the output data.
This operation is invalid for intercommunicators.
5.11.2 Exclusive Scan
MPI_EXSCAN(sendbuf, recvbuf, count, datatype, op, comm)
IN |
sendbuf |
starting address of send bu er (choice) |
OUT |
recvbuf |
starting address of receive bu er (choice) |
IN |
count |
number of elements in input bu er (non-negative in- |
|
|
teger) |
IN |
datatype |
data type of elements of input bu er (handle) |
IN |
op |
operation (handle) |
IN |
comm |
intracommunicator (handle) |
int MPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
MPI_EXSCAN(SENDBUF, RECVBUF, COUNT, DATATYPE, OP, COMM, IERROR) <type> SENDBUF(*), RECVBUF(*)
INTEGER COUNT, DATATYPE, OP, COMM, IERROR
fvoid MPI::Intracomm::Exscan(const void* sendbuf, void* recvbuf, int count, const MPI::Datatype& datatype, const MPI::Op& op) const
(binding deprecated, see Section 15.2) g
If comm is an intracommunicator, MPI_EXSCAN is used to perform a pre x reduction on data distributed across the group. The value in recvbuf on the process with rank 0 is unde ned, and recvbuf is not sign cant on process 0. The value in recvbuf on the process with rank 1 is de ned as the value in sendbuf on the process with rank 0. For processes with rank i > 1, the operation returns, in the receive bu er of the process with rank i, the reduction of the values in the send bu ers of processes with ranks 0; : : : ; i 1 (inclusive). The type of operations supported, their semantics, and the constraints on send and receive bu ers, are as for MPI_REDUCE.
The \in place" option for intracommunicators is speci ed by passing MPI_IN_PLACE in the sendbuf argument. In this case, the input data is taken from the receive bu er, and replaced by the output data. The receive bu er on rank 0 is not changed by this operation.
This operation is invalid for intercommunicators.
Rationale. The exclusive scan is more general than the inclusive scan. Any inclusive scan operation can be achieved by using the exclusive scan and then locally combining the local contribution. Note that for non-invertable operations such as MPI_MAX, the exclusive scan cannot be computed with the inclusive scan. (End of rationale.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
1
2
3
182 |
CHAPTER 5. COLLECTIVE COMMUNICATION |
5.11.3 Example using MPI_SCAN
The example in this section uses an intracommunicator.
4Example 5.22 This example uses a user-de ned operation to produce a segmented scan.
5A segmented scan takes, as input, a set of values and a set of logicals, and the logicals
6
7
delineate the various segments of the scan. For example:
8 |
values |
v1 |
v2 |
v3 |
v4 |
v5 |
|
v6 |
v7 |
v8 |
9 |
logicals |
0 |
0 |
1 |
1 |
1 |
|
0 |
0 |
1 |
10 |
result |
v1 |
v1 + v2 |
v3 |
v3 + v4 |
v3 + v4 |
+ v5 |
v6 |
v6 + v7 |
v8 |
11
12
The operator that produces this e ect is,
13
14
15
! ! !
u |
|
v |
= |
w |
; |
i |
j |
j |
16
17
18
19
where,
w = |
( v |
if i = j : |
|
u + v |
if i = j |
|
|
6 |
20Note that this is a non-commutative operator. C code that implements it is given
21below.
22
typedef struct {
23
double val;
24
int log;
25
} SegScanPair;
26
27
/* the user-defined function
28
*/
29
void segScan( SegScanPair *in, SegScanPair *inout, int *len,
30
MPI_Datatype *dptr )
31
{
32
33
34
35
36
37
38
39
40
41
42
43
int i; SegScanPair c;
for (i=0; i< *len; ++i) {
if ( in->log == inout->log ) c.val = in->val + inout->val;
else
c.val = inout->val; c.log = inout->log; *inout = c;
in++; inout++;
}
44
}
45
46Note that the inout argument to the user-de ned function corresponds to the right-
47hand operand of the operator. When using this operator, we must be careful to specify that
48it is non-commutative, as in the following.