MPI_GET_ELEMENTS_X(3)
π MPI_Get_elements / MPI_Get_elements_x β Open MPI manual page MPI_GET_ELEMENTS_X(3) π
πΈ NAME πΈ
MPI_Get_elements, MPI_Get_elements_x β returns the number of basic elements in a data type. bestie, this is the βhow many basic elements are actually in there?β page π
β¨ SYNTAX β¨
π» C Syntax π»
#include <mpi.h>
int MPI_Get_elements(const MPI_Status *status, MPI_Datatype datatype,
int *count)
int MPI_Get_elements_x(const MPI_Status *status, MPI_Datatype datatype,
MPI_Count *count)
π§ Fortran Syntax π§
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_GET_ELEMENTS(STATUS, DATATYPE, COUNT, IERROR)
INTEGER STATUS(MPI_STATUS_SIZE), DATATYPE, COUNT, IERROR
MPI_GET_ELEMENTS_X(STATUS, DATATYPE, COUNT, IERROR)
INTEGER STATUS(MPI_STATUS_SIZE), DATATYPE
INTEGER(KIND=MPI_COUNT_KIND) COUNT
INTEGER IERROR
π¦ Fortran 2008 Syntax π¦
USE mpi_f08
MPI_Get_elements(status, datatype, count, ierror)
TYPE(MPI_Status), INTENT(IN) :: status
TYPE(MPI_Datatype), INTENT(IN) :: datatype
INTEGER, INTENT(OUT) :: count
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_Get_elements_x(status, datatype, count, ierror)
TYPE(MPI_Status), INTENT(IN) :: status
TYPE(MPI_Datatype), INTENT(IN) :: datatype
INTEGER(KIND = MPI_COUNT_KIND), INTENT(OUT) :: count
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETERS π
statusβ return status of the receive operation (astatus). it's giving βreceipt from the receiveβ energy π§Ύdatatypeβ datatype used by the receive operation (handle). this is the type whose basic elements we're counting, periodt β¨
π«Ά OUTPUT PARAMETERS π«Ά
ierrorβ Fortran only: error status (integer). yes ma'am, Fortran gets the error spot π
π₯ DESCRIPTION π₯
okay so here's the tea: MPI_Get_elements and MPI_Get_elements_x behave different from MPI_Get_count, which returns the number of βtop-level entriesβ received β i.e., the number of βcopiesβ of type datatype. MPI_Get_count may return any integer value k, where 0 =< k =< count. If MPI_Get_count returns k, then the number of basic elements received (and the value returned by MPI_Get_elements and MPI_Get_elements_x) is n k, where n is the number of basic elements in the type map of datatype.
If the number of basic elements received is not a multiple of n β that is, if the receive operation has not received an integral number of datatype βcopiesβ β then MPI_Get_count returns the value MPI_UNDEFINED. for both functions, if the count parameter cannot express the value to be returned (e.g., if the parameter is too small to hold the output value), it is set to MPI_UNDEFINED. no cap, that's the rule π«‘
Example: Usage of MPI_Get_count and MPI_Get_elements:
call MPI_TYPE_CONTIGUOUS(2, MPI_REAL, Type2, ierr)
call MPI_TYPE_COMMIT(Type2, ierr)
call MPI_COMM_RANK(comm, rank, ierr)
IF ( rank == 0 ) THEN
CALL MPI_SEND(a, 2, MPI_REAL, 1, 0, comm, ierr)
CALL MPI_SEND(a, 3, MPI_REAL, 1, 0, comm, ierr)
ELSE
CALL MPI_RECV(a, 2, Type2, 0, 0, comm, stat, ierr)
CALL MPI_GET_COUNT(stat, Type2, i, ierr) ! returns i=1
CALL MPI_GET_ELEMENTS(stat, Type2, i, ierr) ! returns i=2
CALL MPI_RECV(a, 2, Type2, 0, 0, comm, stat, ierr)
CALL MPI_GET_COUNT(stat, Type2, i, ierr) ! returns i=MPI_UNDEFINED
CALL MPI_GET_ELEMENTS(stat, Type2, i, ierr) ! returns i=3
END IF
The function MPI_Get_elements can also be used after a probe to find the number of elements in the probed message. note that the two functions MPI_Get_count and MPI_Get_elements return the same values when they are used with primitive data types β twin behavior, but only for primitives, iykyk π―ββοΈ
π ERRORS π
Almost all MPI routines return an error value; C routines as the return result of the function and Fortran routines in the last argument.
Before the error value is returned, the current MPI error handler associated with the communication object (e.g., communicator, window, file) is called. If no communication object is associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and will call the associated MPI error handler. When MPI_COMM_SELF is not initialized (i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when using the Sessions Model exclusively) the error raises the initial error handler. The initial error handler can be changed by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when using the World model, or the mpi_initial_errhandler CLI argument to mpiexec or info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple. If no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions and the MPI_ERRORS_ABORT error handler is called for all other MPI functions.
Open MPI includes three predefined error handlers that can be used:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. dramatic? yes. but that's literally what it does πMPI_ERRORS_ABORTβ an error handler that can be invoked on a communicator, window, file, or session. When called on a communicator, it acts as ifMPI_Abortwas called on that communicator. If called on a window or file, acts as ifMPI_Abortwas called on a communicator containing the group of processes in the corresponding window or file. If called on a session, aborts only the local process. very βpick your chaos scopeβ energy πMPI_ERRORS_RETURNβ returns an error code to the application. the respectful βhere's your receiptβ option π§Ύ
MPI applications can also implement their own error handlers by calling:
MPI_Comm_create_errhandlerthenMPI_Comm_set_errhandlerMPI_File_create_errhandlerthenMPI_File_set_errhandlerMPI_Session_create_errhandlerthenMPI_Session_set_errhandleror atMPI_Session_initMPI_Win_create_errhandlerthenMPI_Win_set_errhandler
Note that MPI does not guarantee that an MPI program can continue past an error. so likeβ¦ do not treat errors as a cute little detour, bestie π¨
See the MPI man page for a full list of MPI error codes.
See the Error Handling section of the MPI-3.1 standard for more information.
π SEE ALSO π
MPI_Get_count β the sibling page you're probably lowkey looking for π
π COPYRIGHT π
2003-2026, The Open MPI Community
π cute sign-off: this page comes from the Open MPI manual, datedSep 11, 2026, with copyright2003-2026, The Open MPI Community. that's the whole vibe, bestie β mwah π«Άπ
π¦ where this page comes from
- arch rolling: openmpi 5.0.11-1 Β· BSD-3-Clause AND LicenseRef-MPICH
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms