MPI_TYPE_SET_ATTR(3)

πŸ’– MPI_TYPE_SET_ATTR

okay bestie, so this is the Open MPI manual page for MPI_TYPE_SET_ATTR(3) β€” yes it's a whole man page, yes it's about gluing attributes onto datatypes, and yes we're gonna make it make sense. 🫢


✨ NAME ✨

MPI_Type_set_attr β€” sets a key value/attribute pair to a data type. literally that's the whole job description. πŸ’…


🌈 SYNTAX 🌈

πŸŽ€ C Syntax

#include <mpi.h>

int MPI_Type_set_attr(MPI_Datatype type, int type_keyval,
     void *attribute_val)

πŸŽ€ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_TYPE_SET_ATTR(TYPE, TYPE_KEYVAL, ATTRIBUTE_VAL, IERROR)
     INTEGER TYPE, TYPE_KEYVAL, IERROR
     INTEGER(KIND=MPI_ADDRESS_KIND) ATTRIBUTE_VAL

πŸŽ€ Fortran 2008 Syntax

USE mpi_f08
MPI_Type_set_attr(datatype, type_keyval, attribute_val, ierror)
     TYPE(MPI_Datatype), INTENT(IN) :: datatype
     INTEGER, INTENT(IN) :: type_keyval
     INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(IN) :: attribute_val
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ¦‹ INPUT/OUTPUT PARAMETER πŸ¦‹

  • type β€” the data type the attribute is getting attached to (it's a handle, bestie). πŸ’–

🌸 INPUT PARAMETERS 🌸

  • type_keyval β€” the key value (an integer, no cap).
  • attribute_val β€” the attribute value itself.

⭐ OUTPUT PARAMETER ⭐

  • ierror β€” Fortran only: the error status (integer). so Fortran girlies get the tea handed back to them directly. πŸ™ˆ

πŸ’« DESCRIPTION πŸ’«

So for whatever data type you hand it, MPI_Type_set_attr sets the key value to the value of the specified attribute. that's it. that's the function. short and iconic, honestly. πŸ‘‘


πŸ’€ ERRORS πŸ’€

okay this is the long part but it's important, stay with me.

Almost all MPI routines return an error value β€” C routines pass it back as the return result of the function, and Fortran routines stick it in that last argument. classic.

Before the error value actually gets returned, the current MPI error handler associated with the communication object gets called (think: communicator, window, file). 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 error handler associated with that. And when MPI_COMM_SELF isn't initialized β€” meaning before MPI_Init/MPI_Init_thread, after 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 on MPI_COMM_SELF when you're using the World model, or
  • the mpi_initial_errhandler CLI argument to mpiexec, or
  • the info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple.

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 other MPI functions. so like, default behavior is not always gentle, iykyk. 😭

Open MPI ships with three predefined error handlers you can use:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. it's giving nuclear option. πŸ’€
  • MPI_ERRORS_ABORT β€” an error handler that can be invoked on a communicator, window, file, or session. When it's called on a communicator, it acts as if MPI_Abort was called on that communicator. If it's 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 it's called on a session, it aborts only the local process.
  • MPI_ERRORS_RETURN β€” returns an error code to the application. the polite 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
⚠️ heads up bestie: MPI does not guarantee that an MPI program can continue past an error. like, no promises. plan accordingly. ✨

See the MPI man page for a full list of MPI error codes. 🌈

See the Error Handling section of the MPI-3.1 standard if you want even more detail.

See also:

  • MPI_Type_get_attr

2003-2026, The Open MPI Community.


and that's the whole page, bestie!! πŸ’– this lil drop came to you from the Open MPI manual, dated Sep 10, 2026, and it's the MPI_TYPE_SET_ATTR(3) page. slay, go set some attributes, and remember: MPI_Type_get_attr is right there when you need to read them back. periodt. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from