ttg 1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
env.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// Created by Eduard Valeyev on 11/6/21.
4//
5
6#include "ttg/util/env.h"
7
8#include <thread>
9#include <stdexcept>
10
11#include <cstdlib>
12
13namespace ttg {
14 namespace detail {
15
17 std::size_t result = 0;
18 const char* ttg_num_threads_cstr = std::getenv("TTG_NUM_THREADS");
19 if (ttg_num_threads_cstr) {
20 const auto result_long = std::atol(ttg_num_threads_cstr);
21 if (result_long >= 1)
22 result = static_cast<std::size_t>(result_long);
23 else
24 throw std::runtime_error("ttg: invalid value of environment variable TTG_NUM_THREADS");
25 } else {
26 result = std::thread::hardware_concurrency();
27 }
28 if (result > std::numeric_limits<int>::max())
29 throw std::runtime_error("ttg: number of threads exceeds the maximum limit");
30
31 return static_cast<int>(result);
32 }
33
35 bool result = false;
36 const char* ttg_force_device_comm_cstr = std::getenv("TTG_FORCE_DEVICE_COMM");
37 if (ttg_force_device_comm_cstr) {
38 const auto result_int = std::atoi(ttg_force_device_comm_cstr);
39 if (result_int) {
40 result = true;
41 }
42 }
43 return result;
44 }
45 } // namespace detail
46} // namespace ttg
bool force_device_comm()
Definition env.cpp:34
int num_threads()
Determine the number of compute threads to use by TTG when not given to ttg::initialize
Definition env.cpp:16
top-level TTG namespace contains runtime-neutral functionality
Definition keymap.h:9