RDKit: RDThreads.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
RDThreads.h
Go to the documentation of this file.
1//
2// Copyright (C) 2015-2018 Greg Landrum
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10
11#include <RDGeneral/export.h>
12#ifndef RDTHREADS_H_2015
13#define RDTHREADS_H_2015
14
15#include <RDGeneral/Invariant.h>
16
17#ifdef RDK_BUILD_THREADSAFE_SSS
18#include <thread>
19
20namespace RDKit {
21inline unsigned int getNumThreadsToUse(int target) {
22 if (target >= 1) {
23 return static_cast<unsigned int>(target);
24 }
25 unsigned int res = std::thread::hardware_concurrency();
26 if (res > rdcast<unsigned int>(-target)) {
27 return res + target;
28 } else {
29 return 1;
30 }
31}
32} // namespace RDKit
33
34#else
35
36namespace RDKit {
37 inline unsigned int getNumThreadsToUse(int target) {
38 RDUNUSED_PARAM(target);
39 return 1;
40}
41} // namespace RDKit
42#endif
43
44#endif
Invariant.h
rdcast
#define rdcast
Definition Invariant.h:191
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition Invariant.h:196
export.h
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::getNumThreadsToUse
unsigned int getNumThreadsToUse(int target)
Definition RDThreads.h:37