Gromacs  2026.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
#include <cstdio>
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/gmxmpi.h"
+ Include dependency graph for threadaffinity.h:

Description

Declares functions for managing mdrun thread affinity.

Functions

void gmx_set_thread_affinity (const gmx::MDLogger &mdlog, const gmx::MpiComm &mpiCommMySim, const gmx::PhysicalNodeCommunicator &mpiCommNode, const gmx_hw_opt_t *hw_opt, const gmx::HardwareTopology &hwTop, int numThreadsOnThisRank, gmx::IThreadAffinityAccess *affinityAccess)
 Sets the thread affinity using the requested setting stored in hw_opt. More...
 
void gmx_check_thread_affinity_set (const gmx::MDLogger &mdlog, gmx_hw_opt_t *hw_opt, int ncpus, gmx_bool bAfterOpenmpInit, MPI_Comm world)
 Checks the process affinity mask and if it is found to be non-zero, will honor it and disable mdrun internal affinity setting. More...
 

Function Documentation

void gmx_check_thread_affinity_set ( const gmx::MDLogger mdlog,
gmx_hw_opt_t *  hw_opt,
int  ncpus,
gmx_bool  bAfterOpenmpInit,
MPI_Comm  world 
)

Checks the process affinity mask and if it is found to be non-zero, will honor it and disable mdrun internal affinity setting.

This function should be called first before the OpenMP library gets initialized with the last argument FALSE (which will detect affinity set by external tools like taskset), and later, after the OpenMP initialization, with the last argument TRUE to detect affinity changes made by the OpenMP library.

Note that this will only work on Linux as we use a GNU feature. With bAfterOpenmpInit false, it will also detect whether OpenMP environment variables for setting the affinity are set.

void gmx_set_thread_affinity ( const gmx::MDLogger mdlog,
const gmx::MpiComm mpiCommMySim,
const gmx::PhysicalNodeCommunicator mpiCommNode,
const gmx_hw_opt_t *  hw_opt,
const gmx::HardwareTopology hwTop,
int  numThreadsOnThisRank,
gmx::IThreadAffinityAccess *  affinityAccess 
)

Sets the thread affinity using the requested setting stored in hw_opt.

See analyzeThreadsOnThisNode(), which prepares some of the input.

Parameters
[out]mdlogLogger.
[in]mpiCommMySimCommunication handler for the simulation.
[in]mpiCommNodeCommunication handler for the physical node.
[in]hw_optAccesses user choices for thread affinity handling.
[in]hwTopDetected hardware topology.
[in]numThreadsOnThisRankThe number of threads on this rank.
[in]affinityAccessInterface for low-level access to affinity details.