170. Naming Objects

PreviousUpNext
Up: Contents Next: Formalizing the Loosely Synchronous Model Previous: Attributes Example

There are many occasions on which it would be useful to allow a user to associate a printable identifier with an MPI communicator, window, or datatype, for instance error reporting, debugging, and profiling. The names attached to opaque objects do not propagate when the object is duplicated or copied by MPI routines. For communicators this can be achieved using the following two functions.

MPI_COMM_SET_NAME (comm, comm_name)
INOUT commcommunicator whose identifier is to be set (handle)
IN comm_namethe character string which is remembered as the name (string)

int MPI_Comm_set_name(MPI_Comm comm, const char *comm_name)

MPI_Comm_set_name(comm, comm_name, ierror)
TYPE(MPI_Comm), INTENT(IN) :: comm
CHARACTER(LEN=*), INTENT(IN) :: comm_name
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_COMM_SET_NAME(COMM, COMM_NAME, IERROR)
INTEGER COMM, IERROR
CHARACTER*(*) COMM_NAME

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 significant but trailing ones are not.

MPI_COMM_SET_NAME is a local (non-collective) operation, which only affects 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 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 fixed 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 define 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 commcommunicator whose name is to be returned (handle)
OUT comm_namethe name previously stored on the communicator, or an empty string if no such name exists (string)
OUT resultlenlength 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)
TYPE(MPI_Comm), INTENT(IN) :: comm
CHARACTER(LEN=MPI_MAX_OBJECT_NAME), INTENT(OUT) :: comm_name
INTEGER, INTENT(OUT) :: resultlen
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_COMM_GET_NAME(COMM, COMM_NAME, RESULTLEN, IERROR)
INTEGER COMM, RESULTLEN, IERROR
CHARACTER*(*) COMM_NAME

MPI_COMM_GET_NAME returns the last name which has previously been associated with the given communicator. The name may be set and retrieved from any language. The same name will be returned independent of the language used. name should be allocated so that it can hold a resulting string of length MPI_MAX_OBJECT_NAME characters. MPI_COMM_GET_NAME returns a copy of the set name in name.

In C, a null character is additionally stored at name[resultlen]. The value of resultlen cannot be larger than MPI_MAX_OBJECT_NAME-1. In Fortran, name is padded on the right with blank characters. The value of resultlen cannot be larger than MPI_MAX_OBJECT_NAME.

If the user has not associated a name with a communicator, or an error occurs, MPI_COMM_GET_NAME will return an empty string (all spaces in Fortran, "" in C). The three predefined communicators will have predefined names associated with them. Thus, the names of MPI_COMM_WORLD, MPI_COMM_SELF, and the communicator returned by MPI_COMM_GET_PARENT (if not MPI_COMM_NULL) will have the default of MPI_COMM_WORLD, MPI_COMM_SELF, and MPI_COMM_PARENT. The fact that the system may have chosen to give a default name to a communicator does not prevent the user from setting a name on the same communicator; doing this removes the old name and assigns the new one.


Rationale.

We provide separate functions for setting and getting the name of a communicator, rather than simply providing a predefined attribute key for the following reasons:


( End of rationale.)

Advice to users.

The above definition means that it is safe simply to print the string returned by MPI_COMM_GET_NAME, as it is always a valid string even if there was no name.

Note that associating a name with a communicator has no effect on the semantics of an MPI program, and will (necessarily) increase the store requirement of the program, since the names must be saved. Therefore there is no requirement that users use these functions to associate names with communicators. However debugging and profiling MPI applications may be made easier if names are associated with communicators, since the debugger or profiler should then be able to present information in a less cryptic manner. ( End of advice to users.)
The following functions are used for setting and getting names of datatypes. The constant MPI_MAX_OBJECT_NAME also applies to these names.

MPI_TYPE_SET_NAME (datatype, type_name)
INOUT datatypedatatype whose identifier is to be set (handle)
IN type_namethe character string which is remembered as the name (string)

int MPI_Type_set_name(MPI_Datatype datatype, const char *type_name)

MPI_Type_set_name(datatype, type_name, ierror)
TYPE(MPI_Datatype), INTENT(IN) :: datatype
CHARACTER(LEN=*), INTENT(IN) :: type_name
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_TYPE_SET_NAME(DATATYPE, TYPE_NAME, IERROR)
INTEGER DATATYPE, IERROR
CHARACTER*(*) TYPE_NAME

MPI_TYPE_GET_NAME (datatype, type_name, resultlen)
IN datatypedatatype whose name is to be returned (handle)
OUT type_namethe name previously stored on the datatype, or a empty string if no such name exists (string)
OUT resultlenlength of returned name (integer)

int MPI_Type_get_name(MPI_Datatype datatype, char *type_name, int *resultlen)

MPI_Type_get_name(datatype, type_name, resultlen, ierror)
TYPE(MPI_Datatype), INTENT(IN) :: datatype
CHARACTER(LEN=MPI_MAX_OBJECT_NAME), INTENT(OUT) :: type_name
INTEGER, INTENT(OUT) :: resultlen
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_TYPE_GET_NAME(DATATYPE, TYPE_NAME, RESULTLEN, IERROR)
INTEGER DATATYPE, RESULTLEN, IERROR
CHARACTER*(*) TYPE_NAME

Named predefined 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. The constant MPI_MAX_OBJECT_NAME also applies to these names.

MPI_WIN_SET_NAME (win, win_name)
INOUT winwindow whose identifier is to be set (handle)
IN win_namethe character string which is remembered as the name (string)

int MPI_Win_set_name(MPI_Win win, const char *win_name)

MPI_Win_set_name(win, win_name, ierror)
TYPE(MPI_Win), INTENT(IN) :: win
CHARACTER(LEN=*), INTENT(IN) :: win_name
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_WIN_SET_NAME(WIN, WIN_NAME, IERROR)
INTEGER WIN, IERROR
CHARACTER*(*) WIN_NAME

MPI_WIN_GET_NAME (win, win_name, resultlen)
IN winwindow whose name is to be returned (handle)
OUT win_namethe name previously stored on the window, or a empty string if no such name exists (string)
OUT resultlenlength of returned name (integer)

int MPI_Win_get_name(MPI_Win win, char *win_name, int *resultlen)

MPI_Win_get_name(win, win_name, resultlen, ierror)
TYPE(MPI_Win), INTENT(IN) :: win
CHARACTER(LEN=MPI_MAX_OBJECT_NAME), INTENT(OUT) :: win_name
INTEGER, INTENT(OUT) :: resultlen
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_WIN_GET_NAME(WIN, WIN_NAME, RESULTLEN, IERROR)
INTEGER WIN, RESULTLEN, IERROR
CHARACTER*(*) WIN_NAME


PreviousUpNext
Up: Contents Next: Formalizing the Loosely Synchronous Model Previous: Attributes Example


Return to MPI-3.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-3.1 of June 4, 2015
HTML Generated on June 4, 2015