MPI_COMM_GET_ATTR(3)

πŸ’– MPI_COMM_GET_ATTR πŸ’–

okay bestie, welcome to Open MPI's page for MPI_Comm_get_attr(3) β€” aka the little function that goes "hey, what's the value attached to this key?" and hands you the goods. it's giving detective energy, honestly πŸ”βœ¨


✨ NAME ✨

MPI_Comm_get_attr β€” retrieves attribute value by key. that's it, that's the whole job, and she does it flawlessly πŸ’…


🌸 SYNTAX 🌸

πŸŽ€ C Syntax

#include <mpi.h>

int MPI_Comm_get_attr(MPI_Comm comm, int comm_keyval,
     void *attribute_val, int *flag)

πŸŽ€ Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_COMM_GET_ATTR(COMM, COMM_KEYVAL, ATTRIBUTE_VAL, FLAG, IERROR)
     INTEGER COMM, COMM_KEYVAL, IERROR
     INTEGER(KIND=MPI_ADDRESS_KIND) ATTRIBUTE_VAL
     LOGICAL FLAG

πŸŽ€ Fortran 2008 Syntax

USE mpi_f08
MPI_Comm_get_attr(comm, comm_keyval, attribute_val, flag, ierror)
     TYPE(MPI_Comm), INTENT(IN) :: comm
     INTEGER, INTENT(IN) :: comm_keyval
     INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(OUT) :: attribute_val
     LOGICAL, INTENT(OUT) :: flag
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ’œ INPUT PARAMETERS πŸ’œ

  • comm β€” the communicator the attribute is glued onto (it's a handle, bestie 🫢).
  • comm_keyval β€” the key value, and she's an integer πŸ”’.

πŸ¦‹ OUTPUT PARAMETER πŸ¦‹

  • attribute_val β€” the attribute value ✨ but only if flag = false is NOT the case, iykyk.
  • flag β€” logical; comes back false if there's no attribute hanging out with that key πŸ™ˆ.
  • ierror β€” Fortran only: the error status, as an integer πŸ’€.

🌈 DESCRIPTION 🌈

MPI_Comm_get_attr retrieves an attribute value by key. simple. iconic. does exactly what it says on the tin.

But here's the plot twist πŸ‘€ β€” the call is erroneous if there is no key with value keyval. like, that key genuinely does not exist, so don't even try it.

on the other hand, the call is correct if the key value totally exists, but no attribute is attached on comm for that key. in that case? the call returns flag = false and you just vibe. no drama, no error. 🧚

and specifically β€” listen up β€” MPI_KEYVAL_INVALID is an erroneous key value. periodt. don't pass it, bestie πŸ’€

this function replaces MPI_Attr_get, whose use is deprecated (yes, deprecated, we don't do that anymore, it's so last season 🚫). the C binding is identical. the Fortran binding differs in that attribute_val is an address-sized integer β€” that's the one glow-up, no cap.


πŸ”₯ ERRORS πŸ”₯

almost all MPI routines return an error value, okurrr? for C routines it's the return result of the function, and for Fortran routines it's in the last argument. πŸ’…

before that error value comes back to you, the current MPI error handler associated with the communication object (e.g., communicator, window, file) gets 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. noted 🫑

when MPI_COMM_SELF is not initialized β€” that's 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. and you can change that initial error handler:

  • by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when 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_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. ok so that's the breakdown πŸ“


πŸŽ€ Predefined error handlers πŸŽ€

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

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes. yes, all of them. it's giving scorched earth πŸ’€
  • 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 (just the one, lowkey polite of her).
  • MPI_ERRORS_RETURN β€” returns an error code to the application. the chill one 🌸

πŸ’… DIY error handlers πŸ’…

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

build your own, make it cute, make it yours ✨

⚠️ note that MPI does not guarantee that an MPI program can continue past an error. like, at all. so don't count on it 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. go read, it's good for you πŸ“š


2003-2026, The Open MPI Community


and that's the whole page, bestie πŸ₯³πŸ’– you now know literally everything this manpage has to say, no details dropped, no cap. this was MPI_COMM_GET_ATTR(3) from Open MPI, and the page was dated Sep 10, 2026 β€” slay, go get those attributes πŸ‘‘βœ¨πŸ¦‹

πŸ“¦ where this page comes from