| 1 |
#include <pbcopper/parallel/ThreadCount.h> |
| 2 |
|
| 3 |
#include <algorithm> |
| 4 |
#include <thread> |
| 5 |
|
| 6 |
namespace PacBio { |
| 7 |
namespace Parallel { |
| 8 |
|
| 9 |
unsigned int NormalizedThreadCount(unsigned int requestedNumThreads) |
| 10 |
{ |
| 11 |
// Will be 0 if unknown |
| 12 |
const auto maxNumThreads = std::thread::hardware_concurrency(); |
| 13 |
|
| 14 |
// "auto-detect" requested |
| 15 |
if (requestedNumThreads == 0) { |
| 16 |
return std::max(1U, maxNumThreads); |
| 17 |
} |
| 18 |
|
| 19 |
// actual maximum is unknown, just use the requested count |
| 20 |
if (maxNumThreads == 0) { |
| 21 |
return requestedNumThreads; |
| 22 |
} |
| 23 |
|
| 24 |
return std::min(requestedNumThreads, maxNumThreads); |
| 25 |
} |
| 26 |
|
| 27 |
} // namespace Parallel |
| 28 |
} // namespace PacBio |