18.2.193. MPI_Get_hw_resource_info

MPI_Get_hw_resource_info — Returns information about the hardware resources on which the calling process can execute.

18.2.193.1. SYNTAX

18.2.193.1.1. C Syntax

int MPI_Get_hw_resource_info(MPI_Info* hw_info)

18.2.193.1.2. Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_GET_HW_RESOURCE_INFO(HW_INFO, IERROR)
    INTEGER HW_INFO, IERROR

18.2.193.1.3. Fortran 2008 Syntax

USE mpi_f08
MPI_Get_hw_resource_info(hw_info, ierror)
    TYPE(MPI_Info), INTENT(OUT) :: hw_info
    INTEGER, OPTIONAL, INTENT(OUT) :: ierror

18.2.193.2. OUTPUT PARAMETERS

  • info: Info object containing local hardware resource information (handle).

  • ierror: Fortran only: Error status (integer).

18.2.193.3. DESCRIPTION

MPI_Get_hw_resource_info returns an info object describing hardware resource types associated with the calling MPI/ process at the moment of the call. The application is responsible for freeing the returned info object with MPI_Info_free.

Open MPI obtains this information from hwloc. Each key uses the URI form hwloc://<resource-type>. The value is true if the calling process is restricted to a single instance of that resource type and false if its CPU binding spans multiple instances. Depending on the local topology, the returned keys can include:

  • hwloc://NUMANode

  • hwloc://Package

  • hwloc://L3Cache

  • hwloc://L2Cache

  • hwloc://L1Cache

  • hwloc://Core

  • hwloc://PU

Resource types absent from the local topology are omitted. Open MPI returns an empty info object if hardware topology or process binding information is not available. The routine may be called before MPI_Init and after MPI_Finalize; Open MPI returns an empty info object outside the active MPI lifetime.

The returned keys can be passed as values of the mpi_hw_resource_type info key to MPI_Comm_split_type with MPI_COMM_TYPE_HW_GUIDED or MPI_COMM_TYPE_RESOURCE_GUIDED. A process receives MPI_COMM_NULL if its current binding is unavailable or spans multiple instances of the requested resource. For example:

MPI_Info hw_info;
MPI_Comm hw_comm;
int      nb_keys  = 0, flag = 0;
int      is_found = 0, is_restricted = 0;
int      valuelen = 6; // max length between "false" and "true" + 1
char    *value    = calloc(valuelen, sizeof(char));
char    *hw_type  = calloc((MPI_MAX_INFO_KEY+1), sizeof(char));

MPI_Get_hw_resource_info(&hw_info);

MPI_Info_get_nkeys(hw_info, &nb_keys);
for(int index = 0 ; index < nb_keys ; index++){
  MPI_Info_get_nthkey(hw_info, index, hw_type);
  MPI_Info_get_string(hw_info, hw_type, &valuelen, value, &flag);
  if(strcmp(hw_type, "hwloc://NUMANode") == 0){
    is_found = 1;
    if(strcmp(value,"true") == 0)
      is_restricted = 1;
    break; // Resource of type NUMANode found
  }
}

// The calling MPI process is restricted to a resource
// of the chosen type (NUMANode)
if(is_found  && is_restricted){
  MPI_Info split_info;
  int rank;

  MPI_Info_create(&split_info);

  // hw_type now serves as value for the "mpi_hw_resource_type" key
  MPI_Info_set(split_info, "mpi_hw_resource_type", hw_type);

  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_RESOURCE_GUIDED,
                      rank, split_info, &hw_comm);

  // Check and use hw_comm from this point if it's a valid
  // communicator or different from MPI_COMM_SELF or MPI_COMM_WORLD.
} else {
  // If resource is not found or not restricted to it,
  // the calling MPI process does not participate to the call
  // hence the use of MPI_UNDEFINED as split_type and
  // MPI_COMM_NULL is produced as output communicator

  MPI_Comm_split_type(MPI_COMM_WORLD, MPI_UNDEFINED,
                      -1, MPI_INFO_NULL, &hw_comm);
}

18.2.193.4. 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.

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.

Open MPI includes three predefined error handlers that can be used:

  • MPI_ERRORS_ARE_FATAL Causes the program to abort all connected MPI processes.

  • 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.

  • MPI_ERRORS_RETURN Returns an error code to the application.

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

Note that MPI does not guarantee that an MPI program can continue past an error.

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

See the Error Handling section of the MPI-5.0 standard for more information.