Qualpal
Repositories

qualpal::Threads

C++ · cpp · 4.1.0

class qualpal::Threads

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

Methods

get

static inline std::size_t get()

Get the current number of threads used for parallel computations.

Returns

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

set

static inline void set(const std::size_t n)

Set the number of threads to use for parallel computations.

Parameters

n

Number of threads. Must be positive.

Throws

std::invalid_argument

if n is zero.

Note

When OpenMP is enabled, this sets the OpenMP thread count globally.