#include "config.h"
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
#ifdef HAVE_SCHED_AFFINITY
# include <sched.h>
#include "gromacs/utility/basenetwork.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/gmxomp.h"
#include "gromacs/utility/smalloc.h"
const gmx_hw_info_t *hwinfo)
{
int nth_affinity_set, thread0_id_node,
- nthread_local, nthread_node, nthread_hw_max, nphyscore;
+ nthread_local, nthread_node;
int offset;
const int *locality_order;
int rc;
* Reducing these 0/1 values over the threads will give the total number
* of threads on which we succeeded.
*/
+
+ // To avoid warnings from the static analyzer we initialize nth_affinity_set
+ // to zero outside the OpenMP block, and then add to it inside the block.
+ // The value will still always be 0 or 1 from each thread.
nth_affinity_set = 0;
#pragma omp parallel num_threads(nthread_local) reduction(+:nth_affinity_set)
{
setaffinity_ret = tMPI_Thread_setaffinity_single(tMPI_Thread_self(), core);
/* store the per-thread success-values of the setaffinity */
- nth_affinity_set = (setaffinity_ret == 0);
+ nth_affinity_set += (setaffinity_ret == 0);
if (debug)
{
int gmx_unused nthreads_hw_avail,
gmx_bool bAfterOpenmpInit)
{
-#ifdef HAVE_SCHED_AFFINITY
- cpu_set_t mask_current;
- int i, ret, cpu_count, cpu_set;
- gmx_bool bAllSet;
-#endif
-#ifdef GMX_LIB_MPI
- gmx_bool bAllSet_All;
-#endif
+ GMX_RELEASE_ASSERT(hw_opt, "hw_opt must be a non-NULL pointer");
- assert(hw_opt);
if (!bAfterOpenmpInit)
{
/* Check for externally set OpenMP affinity and turn off internal
}
#ifdef HAVE_SCHED_GETAFFINITY
+ int ret;
+ cpu_set_t mask_current;
+
if (hw_opt->thread_affinity == threadaffOFF)
{
/* internal affinity setting is off, don't bother checking process affinity */
}
#endif /* CPU_COUNT */
- bAllSet = TRUE;
- for (i = 0; (i < nthreads_hw_avail && i < CPU_SETSIZE); i++)
+ gmx_bool bAllSet = TRUE;
+ for (int i = 0; (i < nthreads_hw_avail && i < CPU_SETSIZE); i++)
{
bAllSet = bAllSet && (CPU_ISSET(i, &mask_current) != 0);
}
#ifdef GMX_LIB_MPI
+ gmx_bool bAllSet_All;
+
MPI_Allreduce(&bAllSet, &bAllSet_All, 1, MPI_INT, MPI_LAND, MPI_COMM_WORLD);
bAllSet = bAllSet_All;
#endif