qualpal 3.3.0
Loading...
Searching...
No Matches
qualpal::Threads Class Reference

Centralized management of thread settings for parallel computations. More...

#include <threads.h>

Static Public Member Functions

static void set (const std::size_t n)
 Set the number of threads to use for parallel computations.
 
static std::size_t get ()
 Get the current number of threads used for parallel computations.
 

Detailed Description

Centralized management of thread settings for parallel computations.

The Threads class provides a unified interface to control the number of threads used for parallel computations throughout qualpal. It supports both OpenMP and non-OpenMP builds:

  • When OpenMP is available, it sets and queries the OpenMP thread count.
  • When OpenMP is not available, all computations run sequentially (single-threaded).

By default, the thread count is set to half the number of available hardware threads (typically the number of physical CPU cores), but can be changed at runtime.

Note
This class is not thread-safe. Set the thread count before starting parallel work.
qualpal::Threads::set(4); // Set to use 4 threads
std::size_t n = qualpal::Threads::get(); // Get current thread count
static void set(const std::size_t n)
Set the number of threads to use for parallel computations.
Definition threads.h:48
static std::size_t get()
Get the current number of threads used for parallel computations.
Definition threads.h:65

Definition at line 38 of file threads.h.

Member Function Documentation

◆ get()

static std::size_t qualpal::Threads::get ( )
inlinestatic

Get the current number of threads used for parallel computations.

Returns
The current thread count as set by set(), or the default value.

Definition at line 65 of file threads.h.

◆ set()

static void qualpal::Threads::set ( const std::size_t  n)
inlinestatic

Set the number of threads to use for parallel computations.

Parameters
nNumber of threads. Must be positive.
Exceptions
std::invalid_argumentif n is zero.
Note
When OpenMP is enabled, this sets the OpenMP thread count globally.

Definition at line 48 of file threads.h.


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