MPI_TYPE_MATCH_SIZE(3)

πŸ’– MPI_Type_match_size β€” bestie edition πŸ’–

okay so this is MPI_TYPE_MATCH_SIZE(3) from the Open MPI manual, and honestly? it's kind of a bop. it's that one little function that goes "hey, you got a type and a size? say less, here's a datatype that matches." iconic behavior fr fr. πŸ¦‹

MPI_Type_match_size β€” returns an MPI datatype of a given type and size ✨


✨ SYNOPSIS ✨

πŸŽ€ 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, bestie. it's an integer πŸ’…
  • size β€” how big the representation is, in bytes. also an integer 🫢

πŸ’œ OUTPUT PARAMETERS πŸ’œ

  • type β€” a datatype that's got the right type AND the right size. it's a handle, bestie πŸŽ€
  • ierror β€” Fortran only, babes: the error status, as an integer

πŸ¦‹ DESCRIPTION πŸ¦‹

so what does this actually do. the function hands you back an MPI datatype that matches a local variable of type (typeclass, size). and here's the tea: the returned type is a reference (handle) to a predefined named datatype, NOT a duplicate. meaning… you cannot free it. do not try it. it's not yours to free. periodt. πŸ’€

the value of typeclass can be set to one of these three, depending on the datatype you're manifesting:

  • MPI_TYPECLASS_REAL
  • MPI_TYPECLASS_INTEGER
  • MPI_TYPECLASS_COMPLEX

MPI_type_match_size can be used to obtain a size-specific type that matches a Fortran numeric intrinsic type, and the little two-step is: first call MPI_Sizeof <#mpi-sizeof> to compute the variable size, then call MPI_Type_match_size to find a suitable datatype. in C, use the sizeof builtin instead of MPI_Sizeof <#mpi-sizeof>. slay. ✨

⚠️ it is erroneous to specify a size that the compiler doesn't support. like, don't do that. the compiler does not know her. 😭

😭 ERRORS 😭

almost all MPI routines return an error value, bestie. for C routines it's the return result of the function, and for Fortran routines it's in that last argument. standard.

before the error value comes back to you, the current MPI error handler associated with the communication object (think: communicator, window, file) gets called. if there's no communication object associated with the MPI call, then the call counts as attached to MPI_COMM_SELF and it'll call the associated MPI error handler. and when MPI_COMM_SELF is not initialized (i.e., before MPI_Init <#mpi-init>/MPI_Init_thread <#mpi-init-thread>, after MPI_Finalize <#mpi-finalize>, or when you're 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 <#mpi-comm-set-errhandler> on MPI_COMM_SELF when you're using the World model, or via the mpi_initial_errhandler CLI argument to mpiexec, or the info key to MPI_Comm_spawn <#mpi-comm-spawn>/MPI_Comm_spawn_multiple <#mpi-comm-spawn-multiple>. and if no other appropriate error handler has been set, then MPI_ERRORS_RETURN gets called for MPI I/O functions, and MPI_ERRORS_ABORT gets called for all the other MPI functions.

Open MPI ships with three predefined error handlers you can use, and they are:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. yeah. all of them. πŸ’€
  • 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 <#mpi-abort> was called on that communicator. if called on a window or file, it acts as if MPI_Abort <#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. selective king behavior πŸ‘‘
  • 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 <#mpi-comm-create-errhandler> then MPI_Comm_set_errhandler <#mpi-comm-set-errhandler>
  • MPI_File_create_errhandler <#mpi-file-create-errhandler> then MPI_File_set_errhandler <#mpi-file-set-errhandler>
  • MPI_Session_create_errhandler <#mpi-session-create-errhandler> then MPI_Session_set_errhandler <#mpi-session-set-errhandler> or at MPI_Session_init <#mpi-session-init>
  • MPI_Win_create_errhandler <#mpi-win-create-errhandler> then MPI_Win_set_errhandler <#mpi-win-set-errhandler>
⚠️ note that MPI does not guarantee that an MPI program can continue past an error. no cap.

see the MPI man page <#open-mpi> for a full list of MPI error codes <#open-mpi-errors>. 🌈

see the Error Handling section of the MPI-3.1 standard for more information.

See also:

  • MPI_Sizeof <#mpi-sizeof>
  • MPI_Type_get_extent <#mpi-type-get-extent>

2003-2026, The Open MPI Community


okay that's the whole page bestie, you ate that. πŸ’… and just so you know where this came from: it's the Open MPI manual, page MPI_TYPE_MATCH_SIZE(3), dated Sep 10, 2026. go forth and match those sizes, you main character. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from