OpenMS
Loading...
Searching...
No Matches
SysInfo Class Reference

Some functions to get system information. More...

#include <OpenMS/SYSTEM/SysInfo.h>

Classes

struct  MemUsage
 A convenience class to report either absolute or delta (between two timepoints) RAM usage. More...
 

Static Public Member Functions

static bool getProcessMemoryConsumption (size_t &mem_virtual)
 
static bool getProcessPeakMemoryConsumption (size_t &mem_virtual)
 
static bool getFreeSystemMemory (size_t &mem_available)
 Get currently available physical system memory in KiloBytes (KB).
 
static Int64 getProcessId ()
 
static UInt getAvailablePhysicalCores (const std::vector< int > &cpus={})
 The number of physical cores the process may run on (at least 1).
 
static int ompThreadsOfThisThread ()
 The OpenMP threads for the parallel regions that the calling thread starts.
 
static void setOmpThreadsOfThisThread (int threads)
 Sets the OpenMP threads that ompThreadsOfThisThread() reports for the calling thread (0: omp_get_max_threads() again)
 
static bool ompThreadCountIsGlobal ()
 Whether the OpenMP runtime keeps one process-wide number of threads.
 

Detailed Description

Some functions to get system information.

Supports current memory and peak memory consumption.

Member Function Documentation

◆ getAvailablePhysicalCores()

static UInt getAvailablePhysicalCores ( const std::vector< int > &  cpus = {})
static

The number of physical cores the process may run on (at least 1).

Counts cores, not their hardware threads (SMT), which std::thread::hardware_concurrency() and omp_get_num_procs() count. On Linux: the cores of the CPUs in the affinity mask of the calling thread (taskset, cpusets), or of cpus if given (e.g. the CPUs of the OpenMP places, if the OpenMP runtime has bound the calling thread already), at most the CPU quota of the cgroup of the process and of those above it as far as visible (cgroup v2 cpu.max, rounded up). On macOS: hw.physicalcpu. On Windows: the cores of the processors in the affinity mask of the process, in the processor group of the calling thread. Falls back to the hardware threads where this cannot be found out.

Parameters
cpusLinux only: the logical CPUs (numbers as in /sys/devices/system/cpu) to count the cores of instead of those of the affinity mask

◆ getFreeSystemMemory()

static bool getFreeSystemMemory ( size_t &  mem_available)
static

Get currently available physical system memory in KiloBytes (KB).

On Linux this prefers MemAvailable from /proc/meminfo so file-system cache that can be reclaimed by the kernel is counted as available.

Parameters
[out]mem_availableAvailable physical system memory
Returns
True on success, false otherwise. If false is returned, then mem_available is set to 0.

◆ getProcessId()

static Int64 getProcessId ( )
static

@brief Get the current process ID

@return The process ID of the current process

◆ getProcessMemoryConsumption()

static bool getProcessMemoryConsumption ( size_t &  mem_virtual)
static

Get memory consumption in KiloBytes (KB) On Windows, this is equivalent to 'Peak Working Set (Memory)' in Task Manager. On other OS this might be very unreliable, depending on operating system and kernel version.

Parameters
[out]mem_virtualTotal virtual memory currently allocated by this process
Returns
True on success, false otherwise. If false is returned, then mem_virtual is set to 0.

◆ getProcessPeakMemoryConsumption()

static bool getProcessPeakMemoryConsumption ( size_t &  mem_virtual)
static

Get peak memory consumption in KiloBytes (KB) On Windows, this is equivalent to 'Working Set (Memory)' in Task Manager. On other OS this might be very unreliable, depending on operating system and kernel version.

Parameters
[out]mem_virtualTotal virtual memory allocated by this process
Returns
True on success, false otherwise. If false is returned, then mem_virtual is set to 0.

◆ ompThreadCountIsGlobal()

static bool ompThreadCountIsGlobal ( )
static

Whether the OpenMP runtime keeps one process-wide number of threads.

With MSVC's OpenMP 2.0 runtime (vcomp) omp_set_num_threads() by any thread sets the number for every thread; the OpenMP 3.0 runtimes (libgomp, LLVM's libomp, also MSVC's /openmp:llvm) keep one per thread. Code that runs OpenMP on helper threads must not call omp_set_num_threads() there on such a runtime (it would change the number of the main thread too); it sets its share with setOmpThreadsOfThisThread() instead. Probed once, on the first call: a thread sets another number and the caller checks its own, then sets it back. Without OpenMP: false.

◆ ompThreadsOfThisThread()

static int ompThreadsOfThisThread ( )
static

The OpenMP threads for the parallel regions that the calling thread starts.

omp_get_max_threads(), unless a number was set for this thread with setOmpThreadsOfThisThread(): a helper thread of a tool sets its share there when the OpenMP runtime keeps one number of threads for the whole process (MSVC's vcomp: omp_set_num_threads() by any thread sets it for every thread), where it must not call omp_set_num_threads(). Library code that sizes a team itself (e.g. with a num_threads clause) reads this instead of omp_get_max_threads(). Without OpenMP: 1.

◆ setOmpThreadsOfThisThread()

static void setOmpThreadsOfThisThread ( int  threads)
static

Sets the OpenMP threads that ompThreadsOfThisThread() reports for the calling thread (0: omp_get_max_threads() again)