MPI_COMM_GET_ATTR(3)

πŸ’… MPI_COMM_GET_ATTR(3) β€” like, the Open MPI glow-up edition πŸŽ€

okay bestie, so this is a page from the Open MPI manual, and it's literally about MPI_COMM_GET_ATTR β€” the little function that goes "hey, what's the attribute attached to this key?" and hands it to you. no cap, it's giving detective energy πŸ”βœ¨


🌸 NAME 🌸

MPI_Comm_get_attr β€” retrieves attribute value by key. that's it, that's the whole vibe πŸ’–


✨ 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 that the attribute is attached to (handle). your main character object πŸ’«
  • comm_keyval β€” the key value (integer). like the little name tag on the attribute 🏷️

🌈 OUTPUT PARAMETER 🌈

  • attribute_val β€” the attribute value, unless flag = false. so if flag says no, don't go trusting this, bestie πŸ™ˆ
  • flag β€” false if no attribute is associated with the key (logical). it's the vibe check of this whole call βœ…
  • ierror β€” Fortran only: error status (integer).

πŸ‘‘ DESCRIPTION πŸ‘‘

MPI_Comm_get_attr retrieves an attribute value by key. literally its whole job πŸ’…

but here's the tea: the call is erroneous if there is no key with value keyval. like, you can't just make up a key, that's not the move 😭

on the other hand, the call is correct if the key value exists but no attribute is attached on comm for that key β€” in that case, the call returns flag = false. so "no attribute here" is a perfectly valid answer, it's just the shy one 🫢

in particular, MPI_KEYVAL_INVALID is an erroneous key value. so don't do that. periodt πŸ’€

this function replaces MPI_Attr_get, the use of which is deprecated. so like, move on, we don't do that anymore πŸ’– the C binding is identical. the Fortran binding differs in that attribute_val is an address-sized integer. noted ✨


πŸ”₯ 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. classic 😌

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. big yikes but okay, we love documentation πŸ’€

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 much? but yes πŸ’€
  • 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, 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, aborts only the local process. very "it depends on the context" of it πŸ”₯
  • 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. fr fr, this is not a drill 😭

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. iykyk πŸ“šβœ¨


and that's the whole page, bestie 🫢

2003-2026, The Open MPI Community πŸ’– β€” documented with love, dated Sep 11, 2026, and yes the manual page title is still MPI_COMM_GET_ATTR(3) in case you forgot where you were ✨ slay πŸ¦‹

πŸ“¦ where this page comes from