26 #include <kvikio/shim/cufile.hpp>
33 T getenv_or(std::string_view env_var_name, T default_val)
35 const auto* env_val = std::getenv(env_var_name.data());
36 if (env_val ==
nullptr) {
return default_val; }
38 std::stringstream sstream(env_val);
40 sstream >> converted_val;
42 throw std::invalid_argument(
"unknown config value " + std::string{env_var_name} +
"=" +
43 std::string{env_val});
49 inline bool getenv_or(std::string_view env_var_name,
bool default_val)
51 const auto* env_val = std::getenv(env_var_name.data());
52 if (env_val ==
nullptr) {
return default_val; }
55 return static_cast<bool>(std::stoi(env_val));
56 }
catch (
const std::invalid_argument&) {
59 std::string str{env_val};
60 std::transform(str.begin(), str.end(), str.begin(), ::tolower);
62 std::stringstream trimmer;
67 if (str ==
"true" || str ==
"on" || str ==
"yes") {
return true; }
68 if (str ==
"false" || str ==
"off" || str ==
"no") {
return false; }
69 throw std::invalid_argument(
"unknown config value " + std::string{env_var_name} +
"=" +
70 std::string{env_val});
83 std::size_t _task_size;
84 std::size_t _gds_threshold;
86 static unsigned int get_num_threads_from_env()
88 const int ret = detail::getenv_or(
"KVIKIO_NTHREADS", 1);
89 if (ret <= 0) {
throw std::invalid_argument(
"KVIKIO_NTHREADS has to be a positive integer"); }
97 if (std::getenv(
"KVIKIO_COMPAT_MODE") !=
nullptr) {
99 _compat_mode = detail::getenv_or(
"KVIKIO_COMPAT_MODE",
false);
102 _compat_mode = !is_cufile_available();
107 const ssize_t env = detail::getenv_or(
"KVIKIO_TASK_SIZE", 4 * 1024 * 1024);
109 throw std::invalid_argument(
"KVIKIO_TASK_SIZE has to be a positive integer");
115 const ssize_t env = detail::getenv_or(
"KVIKIO_GDS_THRESHOLD", 1024 * 1024);
117 throw std::invalid_argument(
"KVIKIO_GDS_THRESHOLD has to be a positive integer");
119 _gds_threshold = env;
148 [[nodiscard]]
static bool compat_mode() {
return instance()->_compat_mode; }
171 return instance()->_thread_pool;
206 [[nodiscard]]
static std::size_t
task_size() {
return instance()->_task_size; }
226 [[nodiscard]]
static std::size_t
gds_threshold() {
return instance()->_gds_threshold; }
Singleton class of default values used thoughtout KvikIO.
static std::size_t task_size()
Get the default task size used for parallel IO operations.
static void gds_threshold_reset(std::size_t nbytes)
Reset the default GDS threshold, which is the minimum size to use GDS (in bytes).
static void compat_mode_reset(bool enable)
Reset the value of kvikio::defaults::compat_mode()
static void task_size_reset(std::size_t nbytes)
Reset the default task size used for parallel IO operations.
static bool compat_mode()
Return whether the KvikIO library is running in compatibility mode or not.
static void thread_pool_nthreads_reset(unsigned int nthreads)
Reset the number of threads in the default thread pool. Waits for all currently running tasks to be c...
static kvikio::third_party::thread_pool & thread_pool()
Get the default thread pool.
static std::size_t gds_threshold()
Get the default GDS threshold, which is the minimum size to use GDS (in bytes).
static unsigned int thread_pool_nthreads()
Get the number of threads in the default thread pool.
A C++17 thread pool class. The user submits tasks to be executed into a queue. Whenever a thread beco...
void reset(const ui32 &_thread_count=std::thread::hardware_concurrency())
Reset the number of threads in the pool. Waits for all currently running tasks to be completed,...
ui32 get_thread_count() const
Get the number of threads in the pool.
A C++17 thread pool for high-performance scientific computing.