2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
37 * Declares functions for managing mdrun thread affinity.
40 * \ingroup module_mdrunutility
42 #ifndef GMX_MDRUNUTILITY_THREADAFFINITY_H
43 #define GMX_MDRUNUTILITY_THREADAFFINITY_H
47 #include "gromacs/utility/basedefinitions.h"
50 struct gmx_multisim_t
;
56 class HardwareTopology
;
58 class PhysicalNodeCommunicator
;
60 class IThreadAffinityAccess
63 virtual bool isThreadAffinitySupported() const = 0;
64 virtual bool setCurrentThreadAffinityToCore(int core
) = 0;
67 virtual ~IThreadAffinityAccess();
72 /*! \brief Communicates within physical nodes to discover the
73 * distribution of threads over ranks. */
74 void analyzeThreadsOnThisNode(const gmx::PhysicalNodeCommunicator
&physicalNodeComm
,
75 int numThreadsOnThisRank
,
76 int *numThreadsOnThisNode
,
77 int *intraNodeThreadOffset
);
80 * Sets the thread affinity using the requested setting stored in hw_opt.
82 * See analyzeThreadsOnThisNode(), which prepares some of the input.
84 * \param[out] mdlog Logger.
85 * \param[in] cr Communication handler.
86 * \param[in] hw_opt Accesses user choices for thread affinity handling.
87 * \param[in] hwTop Detected hardware topology.
88 * \param[in] numThreadsOnThisRank The number of threads on this rank.
89 * \param[in] numThreadsOnThisNode The number of threads on all ranks of this node.
90 * \param[in] intraNodeThreadOffset The index of the first hardware thread of this rank
91 * in the set of all the threads of all MPI ranks within a node (ordered by MPI rank ID).
92 * \param[in] affinityAccess Interface for low-level access to affinity details.
95 gmx_set_thread_affinity(const gmx::MDLogger
&mdlog
,
97 const gmx_hw_opt_t
*hw_opt
,
98 const gmx::HardwareTopology
&hwTop
,
99 int numThreadsOnThisRank
,
100 int numThreadsOnThisNode
,
101 int intraNodeThreadOffset
,
102 gmx::IThreadAffinityAccess
*affinityAccess
);
105 * Checks the process affinity mask and if it is found to be non-zero,
106 * will honor it and disable mdrun internal affinity setting.
108 * This function should be called first before the OpenMP library gets
109 * initialized with the last argument FALSE (which will detect affinity
110 * set by external tools like taskset), and later, after the OpenMP
111 * initialization, with the last argument TRUE to detect affinity changes
112 * made by the OpenMP library.
114 * Note that this will only work on Linux as we use a GNU feature.
115 * With bAfterOpenmpInit false, it will also detect whether OpenMP environment
116 * variables for setting the affinity are set.
119 gmx_check_thread_affinity_set(const gmx::MDLogger
&mdlog
,
120 gmx_hw_opt_t
*hw_opt
, int ncpus
,
121 gmx_bool bAfterOpenmpInit
);