Reference documentation for deal.II version Git a2518c4284 2020-04-02 19:23:00 +0200
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members

#include <deal.II/base/multithread_info.h>

Public Member Functions

 MultithreadInfo ()=delete

Static Public Member Functions

static unsigned int n_cores ()
static unsigned int n_threads ()
static std::size_t memory_consumption ()
static void set_thread_limit (const unsigned int max_threads=numbers::invalid_unsigned_int)
static bool is_running_single_threaded ()
static void initialize_multithreading ()

Static Private Member Functions

static unsigned int get_n_cpus ()

Static Private Attributes

static unsigned int n_max_threads = numbers::invalid_unsigned_int
static const unsigned int n_cpus = MultithreadInfo::get_n_cpus()

Detailed Description

This class provides information about the system which may be of use in multithreaded programs. At the moment this is just the number of CPUs. If deal.II is compiled with multithreading support, some functions will use multiple threads for their action. Currently the library supports both thread-based and task-based parallelism. Parallel computing with multiple processors accessing shared memory describes the different uses of each. The default number of threads used for task-based parallel methods is selected automatically by the Threading Building Blocks library. See Parallel computing with multiple processors accessing shared memory for more information on this. Thread-based parallel methods need to explicitly create threads and may want to use a number of threads that is related to the number of CPUs in your system. The recommended number of threads can be queried using MultithreadInfo::n_threads(), while the number of cores in the system is returned by MultithreadInfo::n_cores().

Thomas Richter, Wolfgang Bangerth, 2000

Definition at line 48 of file multithread_info.h.

Constructor & Destructor Documentation

◆ MultithreadInfo()

MultithreadInfo::MultithreadInfo ( )

Constructor. This constructor is deleted because no instance of this class needs to be constructed (all members are static).

Member Function Documentation

◆ n_cores()

unsigned int MultithreadInfo::n_cores ( )

The number of CPUs in the system. At the moment detection of CPUs is only implemented on Linux, FreeBSD, and Mac computers. It is one if detection failed or is not implemented on your system.

If it is one, although you are on a multi-processor machine, please refer to the documentation in near to the error directive.

Definition at line 107 of file

◆ n_threads()

unsigned int MultithreadInfo::n_threads ( )

Return the number of threads to use. This is initially set to the number of cores the system has (see n_cores()) but can be further restricted by set_thread_limit() and the environment variable DEAL_II_NUM_THREADS.

Definition at line 167 of file

◆ memory_consumption()

std::size_t MultithreadInfo::memory_consumption ( )

Return an estimate for the memory consumption, in bytes, of this object. This is not exact (but will usually be close) because calculating the memory usage of trees (e.g., std::map) is difficult.

Definition at line 209 of file

◆ set_thread_limit()

void MultithreadInfo::set_thread_limit ( const unsigned int  max_threads = numbers::invalid_unsigned_int)

Set the maximum number of threads to be used to the minimum of the environment variable DEAL_II_NUM_THREADS and the given argument (or its default value). This affects the initialization of the TBB. If neither is given, the default from TBB is used (based on the number of cores in the system).

This routine is executed automatically with the default argument before your code in main() is running (using a static constructor). It is also executed by Utilities::MPI::MPI_InitFinalize. Use the appropriate argument of the constructor of Utilities::MPI::MPI_InitFinalize if you have an MPI based code.

Definition at line 114 of file

◆ is_running_single_threaded()

bool MultithreadInfo::is_running_single_threaded ( )

Return if the TBB is running using a single thread either because of thread affinity or because it is set via a call to set_thread_limit. This is used in the PETScWrappers to avoid using the interface that is not thread-safe.

Definition at line 202 of file

◆ initialize_multithreading()

void MultithreadInfo::initialize_multithreading ( )

Make sure the multithreading API is initialized. This normally does not need to be called in usercode.

Definition at line 218 of file

◆ get_n_cpus()

unsigned int MultithreadInfo::get_n_cpus ( )

Private function to determine the number of CPUs. Implementation for Linux, OSF, SGI, and Sun machines; if no detection of the number of CPUs is supported, or if detection fails, this function returns one.

Definition at line 99 of file

Member Data Documentation

◆ n_max_threads

unsigned int MultithreadInfo::n_max_threads = numbers::invalid_unsigned_int

Variable representing the maximum number of threads.

Definition at line 130 of file multithread_info.h.

◆ n_cpus

const unsigned int MultithreadInfo::n_cpus = MultithreadInfo::get_n_cpus()

Variable representing the number of cores in the system. This is computed by get_n_cpus() and is returned by n_cores().

Definition at line 136 of file multithread_info.h.

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