MPI_TYPE_MATCH_SIZE(3)

๐Ÿ’… MPI_TYPE_MATCH_SIZE(3) โ€” the Open MPI glow-up

okay bestie, so this is a page from the Open MPI manual set, and it's about MPI_Type_match_size. it's literally the "which datatype matches this size" hotline. let's get into it โœจ


๐ŸŒธ NAME ๐ŸŒธ

MPI_Type_match_size โ€” returns an MPI datatype of a given type and size ๐ŸŽ€


โœจ SYNTAX โœจ

๐Ÿงš C Syntax

#include <mpi.h>

int MPI_Type_match_size(int typeclass, int size,
     MPI_Datatype *type)

๐Ÿฆ‹ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_TYPE_MATCH_SIZE(TYPECLASS, SIZE, TYPE, IERROR)
     INTEGER TYPECLASS, SIZE, TYPE, IERROR

๐Ÿ’œ Fortran 2008 Syntax

USE mpi_f08
MPI_Type_match_size(typeclass, size, datatype, ierror)
     INTEGER, INTENT(IN) :: typeclass, size
     TYPE(MPI_Datatype), INTENT(OUT) :: datatype
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

๐Ÿ“ INPUT PARAMETERS ๐Ÿ“

  • typeclass โ€” the generic type specifier, an integer. this is you telling it "girl, I want a real / integer / complex type". ๐Ÿ’ซ
  • size โ€” the size, in bytes, of the representation. also an integer. ๐Ÿ“

๐ŸŒˆ OUTPUT PARAMETERS ๐ŸŒˆ

  • type โ€” the datatype with the correct type and size, as a handle. ๐Ÿซถ
  • ierror โ€” Fortran only: the error status, an integer. ๐Ÿ˜Œ

๐Ÿ”ฅ DESCRIPTION ๐Ÿ”ฅ

so what it does: the function returns an MPI datatype that matches a local variable of type (typeclass, size). and listen โ€” the type it hands you back is a reference (handle) to a predefined named datatype, not a duplicate. which means you cannot free this type. not "shouldn't", cannot. it's not yours to yeet. ๐Ÿ’€

typeclass can be set to one of MPI_TYPECLASS_REAL, MPI_TYPECLASS_INTEGER, or MPI_TYPECLASS_COMPLEX, depending on which datatype you're craving. ๐Ÿ‘‘

and here's the iconic use case: MPI_Type_match_size can be used to obtain a size-specific type that matches a Fortran numeric intrinsic type. the workflow is literally:

  1. call MPI_Sizeof to compute the variable size ๐Ÿงฎ
  2. call MPI_Type_match_size to find a suitable datatype ๐ŸŽฏ

and if you're in C? use the sizeof builtin instead of MPI_Sizeof. easy. no cap. โœจ

โš ๏ธ it is erroneous to specify a size not supported by the compiler. so, like, don't do that. fr fr. ๐Ÿ™ˆ

๐Ÿ’€ ERRORS ๐Ÿ’€

almost all MPI routines return an error value. C routines return it as the return result of the function, and Fortran routines put it in the last argument. standard behavior, you know the drill. ๐Ÿ’…

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. and 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 you can use, and they are:

  • MPI_ERRORS_ARE_FATAL โ€” causes the program to abort all connected MPI processes. dramatic, but make it functional. ๐Ÿ’€
  • 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 if MPI_Abort was called on that communicator. if called on a window or file, it acts as if MPI_Abort was called on a communicator containing the group of processes in the corresponding window or file. if called on a session, it aborts only the local process. ๐Ÿซ 
  • MPI_ERRORS_RETURN โ€” returns an error code to the application. the chill one. ๐Ÿ˜Œ

MPI applications can also implement their own error handlers by calling:

  • MPI_Comm_create_errhandler then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler then MPI_File_set_errhandler
  • MPI_Session_create_errhandler then MPI_Session_set_errhandler or at MPI_Session_init
  • MPI_Win_create_errhandler then MPI_Win_set_errhandler
โš ๏ธ note that MPI does not guarantee that an MPI program can continue past an error. like, it might just not. so plan accordingly 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_Sizeof
  • MPI_Type_get_extent

2003-2026, The Open MPI Community


and that's the whole page, bestie ๐Ÿซถ โ€” big slay, iconique, no notes. this one's dated Sep 11, 2026, brought to you by The Open MPI Community, and it's officially a wrap. ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from