DASH  0.3.0
dash::util::UnitLocality Class Reference

Wrapper of a single dart_unit_locality_t object. More...

#include <UnitLocality.h>

Public Member Functions

 UnitLocality (const dash::Team &team, team_unit_t unit)
 
 UnitLocality (global_unit_t unit)
 
 UnitLocality (const UnitLocality &)=default
 
UnitLocalityoperator= (const UnitLocality &)=default
 
const dart_hwinfo_thwinfo () const
 
dart_hwinfo_thwinfo ()
 
dart_domain_locality_tdomain ()
 
const dart_domain_locality_tdomain () const
 
const dash::Teamteam () const
 
team_unit_t unit_id () const
 
dash::util::LocalityDomainnode_domain ()
 
dash::util::LocalityDomain parent ()
 
dash::util::LocalityDomain parent_in_scope (dash::util::Locality::Scope scope)
 
std::string domain_tag () const
 
std::string host () const
 
void set_domain_tag (const std::string &tag)
 
void set_host (const std::string &hostname)
 
int num_cores () const
 
int min_threads ()
 
int max_threads ()
 
int num_threads () const
 
int num_numa () const
 
int numa_id () const
 
int cpu_id () const
 
int cpu_mhz () const
 
int max_shmem_mbps () const
 
int max_cpu_mhz ()
 
int min_cpu_mhz ()
 
int cache_line_size (int cache_level)
 
std::string hostname ()
 
int num_domain_threads ()
 Number of threads currently available to the active unit. More...
 

Detailed Description

Wrapper of a single dart_unit_locality_t object.

Definition at line 30 of file UnitLocality.h.

Member Function Documentation

◆ num_domain_threads()

int dash::util::UnitLocality::num_domain_threads ( )
inline

Number of threads currently available to the active unit.

The returned value is calculated from unit locality data and hardware specifications and can, for example, be used to set the num_threads parameter of OpenMP sections:

#ifdef DASH_ENABLE_OPENMP
auto n_threads = dash::util::Locality::NumUnitDomainThreads();
if (n_threads > 1) {
#pragma omp parallel num_threads(n_threads) private(t_id)
{
// ...
}
#endif

The following configuration keys affect the number of available threads:

  • DASH_DISABLE_THREADS: If set, disables multi-threading at unit scope and this method returns 1.
  • DASH_MAX_SMT: If set, virtual SMT CPUs (hyperthreads) instead of physical cores are used to determine availble threads.
  • DASH_MAX_UNIT_THREADS: Specifies the maximum number of threads available to a single unit.

Note that these settings may differ between hosts.

Example for MPI:

mpirun -host node.0 -env DASH_MAX_UNIT_THREADS 4 -n 16 myprogram : -host node.1 -env DASH_MAX_UNIT_THREADS 2 -n 32 myprogram

The DASH configuration can also be changed at run time with the dash::util::Config interface.

See also
dash::util::Config
dash::util::TeamLocality

Definition at line 306 of file UnitLocality.h.

Referenced by dash::fill(), and dash::min_element().

307  {
308  auto n_threads = num_cores();
309  if (dash::util::Config::get<bool>("DASH_DISABLE_THREADS")) {
310  // Threads disabled in unit scope:
311  n_threads = 1;
312  } else if (dash::util::Config::get<bool>("DASH_MAX_SMT")) {
313  // Configured to use SMT (hyperthreads):
314  n_threads *= max_threads();
315  } else {
316  // Start one thread on every physical core assigned to this unit:
317  n_threads *= min_threads();
318  }
319  if (dash::util::Config::is_set("DASH_MAX_UNIT_THREADS")) {
320  n_threads = std::min(dash::util::Config::get<int>(
321  "DASH_MAX_UNIT_THREADS"),
322  n_threads);
323  }
324  return n_threads;
325  }

The documentation for this class was generated from the following file: