- •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
238 CHAPTER 6. GROUPS, CONTEXTS, COMMUNICATORS, AND CACHING
1
2
3
4
5
6
7
gop_stuff_destructor (comm, keyval, gop_stuff, extra) MPI_Comm comm;
int keyval;
gop_stuff_type *gop_stuff; void *extra;
{
8if (keyval != gop_key) { /* abort -- programming error */ }
9
10/* The group's being freed removes one reference to gop_stuff */
11gop_stuff -> ref_count -= 1;
12
13/* If no references remain, then free the storage */
14if (gop_stuff -> ref_count == 0) {
15free((void *)gop_stuff);
16}
17}
18
19/* The following routine is called by MPI when a group is copied */
20gop_stuff_copier (comm, keyval, extra, gop_stuff_in, gop_stuff_out, flag)
21MPI_Comm comm;
22int keyval;
23gop_stuff_type *gop_stuff_in, *gop_stuff_out;
24void *extra;
25{
26if (keyval != gop_key) { /* abort -- programming error */ }
27
28/* The new group adds one reference to this gop_stuff */
29gop_stuff -> ref_count += 1;
30gop_stuff_out = gop_stuff_in;
31}
32
33
34 6.8 Naming Objects
35
There are many occasions on which it would be useful to allow a user to associate a printable
36
identi er with an MPI communicator, window, or datatype, for instance error reporting,
37
debugging, and pro ling. The names attached to opaque objects do not propagate when
38
the object is duplicated or copied by MPI routines. For communicators this can be achieved
39
using the following two functions.
40
41
42 |
MPI_COMM_SET_NAME (comm, comm_name) |
|
43
44
45
46
47
INOUT |
comm |
communicator whose identi er is to be set (handle) |
IN |
comm_name |
the character string which is remembered as the name |
|
|
(string) |
48 |
int MPI_Comm_set_name(MPI_Comm comm, char *comm_name) |
|
6.8. NAMING OBJECTS |
239 |
MPI_COMM_SET_NAME(COMM, COMM_NAME, IERROR)
INTEGER COMM, IERROR
CHARACTER*(*) COMM_NAME
fvoid MPI::Comm::Set_name(const char* comm_name) (binding deprecated, see Section 15.2) g
MPI_COMM_SET_NAME allows a user to associate a name string with a communicator. The character string which is passed to MPI_COMM_SET_NAME will be saved inside the MPI library (so it can be freed by the caller immediately after the call, or allocated on the stack). Leading spaces in name are signi cant but trailing ones are not.
MPI_COMM_SET_NAME is a local (non-collective) operation, which only a ects the name of the communicator as seen in the process which made the MPI_COMM_SET_NAME call. There is no requirement that the same (or any) name be assigned to a communicator in every process where it exists.
Advice to users. Since MPI_COMM_SET_NAME is provided to help debug code, it is sensible to give the same name to a communicator in all of the processes where it exists, to avoid confusion. (End of advice to users.)
The length of the name which can be stored is limited to the value of
MPI_MAX_OBJECT_NAME in Fortran and MPI_MAX_OBJECT_NAME-1 in C and C++ to allow for the null terminator. Attempts to put names longer than this will result in truncation of the name. MPI_MAX_OBJECT_NAME must have a value of at least 64.
Advice to users. Under circumstances of store exhaustion an attempt to put a name of any length could fail, therefore the value of MPI_MAX_OBJECT_NAME should be viewed only as a strict upper bound on the name length, not a guarantee that setting names of less than this length will always succeed. (End of advice to users.)
Advice to implementors. Implementations which pre-allocate a xed size space for a name should use the length of that allocation as the value of MPI_MAX_OBJECT_NAME. Implementations which allocate space for the name from the heap should still de ne MPI_MAX_OBJECT_NAME to be a relatively small value, since the user has to allocate space for a string of up to this size when calling MPI_COMM_GET_NAME. (End of advice to implementors.)
MPI_COMM_GET_NAME (comm, comm_name, resultlen)
IN |
comm |
communicator whose name is to be returned (handle) |
OUT |
comm_name |
the name previously stored on the communicator, or |
|
|
an empty string if no such name exists (string) |
OUT |
resultlen |
length of returned name (integer) |
int MPI_Comm_get_name(MPI_Comm comm, char *comm_name, int *resultlen)
MPI_COMM_GET_NAME(COMM, COMM_NAME, RESULTLEN, IERROR)
INTEGER COMM, RESULTLEN, IERROR
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
240 CHAPTER 6. GROUPS, CONTEXTS, COMMUNICATORS, AND CACHING
CHARACTER*(*) COMM_NAME
3fvoid MPI::Comm::Get_name(char* comm_name, int& resultlen) const (binding
4 |
deprecated, see Section 15.2) g |
5MPI_COMM_GET_NAME returns the last name which has previously been associated
6with the given communicator. The name may be set and got from any language. The same
7name will be returned independent of the language used. name should be allocated so that
8it can hold a resulting string of length MPI_MAX_OBJECT_NAME characters.
9MPI_COMM_GET_NAME returns a copy of the set name in name.
10In C, a null character is additionally stored at name[resultlen]. resultlen cannot be
11larger then MPI_MAX_OBJECT_NAME-1. In Fortran, name is padded on the right with
12blank characters. resultlen cannot be larger then MPI_MAX_OBJECT_NAME.
13If the user has not associated a name with a communicator, or an error occurs,
14MPI_COMM_GET_NAME will return an empty string (all spaces in Fortran, "" in C and
15C++). The three prede ned communicators will have prede ned names associated with
16them. Thus, the names of MPI_COMM_WORLD, MPI_COMM_SELF, and the communicator
17returned by MPI_COMM_GET_PARENT (if not MPI_COMM_NULL) will have the default of
18MPI_COMM_WORLD, MPI_COMM_SELF, and MPI_COMM_PARENT. The fact that the system
19may have chosen to give a default name to a communicator does not prevent the user from
20setting a name on the same communicator; doing this removes the old name and assigns
21the new one.
22
23Rationale. We provide separate functions for setting and getting the name of a com-
24municator, rather than simply providing a prede ned attribute key for the following
25reasons:
26
27
It is not, in general, possible to store a string as an attribute from Fortran.
28It is not easy to set up the delete function for a string attribute unless it is known
29to have been allocated from the heap.
30To make the attribute key useful additional code to call strdup is necessary. If
31this is not standardized then users have to write it. This is extra unneeded work
32which we can easily eliminate.
33
34
35
36
37
38
The Fortran binding is not trivial to write (it will depend on details of the Fortran compilation system), and will not be portable. Therefore it should be in the library rather than in user code.
(End of rationale.)
39Advice to users. The above de nition means that it is safe simply to print the string
40returned by MPI_COMM_GET_NAME, as it is always a valid string even if there was
41no name.
42Note that associating a name with a communicator has no e ect on the semantics of
43an MPI program, and will (necessarily) increase the store requirement of the program,
44since the names must be saved. Therefore there is no requirement that users use these
45functions to associate names with communicators. However debugging and pro ling
46MPI applications may be made easier if names are associated with communicators,
47since the debugger or pro ler should then be able to present information in a less
48cryptic manner. (End of advice to users.)
6.8. NAMING OBJECTS |
241 |
The following functions are used for setting and getting names of datatypes.
MPI_TYPE_SET_NAME (type, type_name)
INOUT |
type |
datatype whose identi er is to be set (handle) |
IN |
type_name |
the character string which is remembered as the name |
|
|
(string) |
int MPI_Type_set_name(MPI_Datatype type, char *type_name)
MPI_TYPE_SET_NAME(TYPE, TYPE_NAME, IERROR)
INTEGER TYPE, IERROR
CHARACTER*(*) TYPE_NAME
fvoid MPI::Datatype::Set_name(const char* type_name) (binding deprecated, see Section 15.2) g
MPI_TYPE_GET_NAME (type, type_name, resultlen)
IN |
type |
datatype whose name is to be returned (handle) |
OUT |
type_name |
the name previously stored on the datatype, or a empty |
|
|
string if no such name exists (string) |
OUT |
resultlen |
length of returned name (integer) |
int MPI_Type_get_name(MPI_Datatype type, char *type_name, int *resultlen)
MPI_TYPE_GET_NAME(TYPE, TYPE_NAME, RESULTLEN, IERROR)
INTEGER TYPE, RESULTLEN, IERROR
CHARACTER*(*) TYPE_NAME
fvoid MPI::Datatype::Get_name(char* type_name, int& resultlen) const
(binding deprecated, see Section 15.2) g
Named prede ned datatypes have the default names of the datatype name. For example, MPI_WCHAR has the default name of MPI_WCHAR.
The following functions are used for setting and getting names of windows.
MPI_WIN_SET_NAME (win, win_name)
INOUT |
win |
window whose identi er is to be set (handle) |
IN |
win_name |
the character string which is remembered as the name |
|
|
(string) |
int MPI_Win_set_name(MPI_Win win, char *win_name)
MPI_WIN_SET_NAME(WIN, WIN_NAME, IERROR)
INTEGER WIN, IERROR
CHARACTER*(*) WIN_NAME
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