2 #include "TpetraCore_config.h"
14 namespace BehaviorDetails {
15 std::map<std::string, std::map<std::string, bool> > namedVariableMap_;
16 bool verboseDisabled_ =
false;
21 enum EnvironmentVariableState
23 EnvironmentVariableIsSet_ON,
24 EnvironmentVariableIsSet_OFF,
25 EnvironmentVariableIsSet,
26 EnvironmentVariableIsNotSet
32 std::string stringToUpper (std::string s)
34 std::transform (s.begin (), s.end (), s.begin (),
35 [] (
unsigned char c) {
return std::toupper (c); });
40 split(
const std::string& s,
41 std::function<
void(
const std::string&)> f,
44 typedef std::string::size_type size_type;
45 size_type cur_pos, last_pos=0, length=s.length();
46 while(last_pos < length + 1)
48 cur_pos = s.find_first_of(sep, last_pos);
49 if(cur_pos == std::string::npos)
53 if(cur_pos!=last_pos) {
54 auto token = std::string(s.data()+last_pos, (size_type)cur_pos-last_pos);
57 last_pos = cur_pos + 1;
62 EnvironmentVariableState
63 environmentVariableState(
const std::string& environmentVariableValue)
65 std::string v = stringToUpper(environmentVariableValue);
66 if (v ==
"1" || v ==
"YES" || v ==
"TRUE" || v ==
"ON")
68 return EnvironmentVariableIsSet_ON;
69 else if (v ==
"0" || v ==
"NO" || v ==
"FALSE" || v ==
"OFF")
71 return EnvironmentVariableIsSet_OFF;
73 return EnvironmentVariableIsSet;
77 setEnvironmentVariableMap (
const char environmentVariableName[],
78 std::map<std::string,std::map<std::string, bool> >& valsMap,
79 const bool defaultValue)
87 valsMap[environmentVariableName] = map<string,bool>{{
"DEFAULT", defaultValue}};
89 const char* varVal = getenv (environmentVariableName);
97 const string varStr(varVal);
99 split(varStr, [&](
const string& x){names.push_back(x);});
100 for (
auto const& name: names) {
101 auto state = environmentVariableState(name);
102 if (state == EnvironmentVariableIsSet_ON) {
105 valsMap[environmentVariableName][
"DEFAULT"] =
true;
107 else if (state == EnvironmentVariableIsSet_OFF) {
110 valsMap[environmentVariableName][
"DEFAULT"] =
false;
115 valsMap[environmentVariableName][name] =
true;
122 getEnvironmentVariableAsBool (
const char environmentVariableName[],
123 const bool defaultValue)
125 const char* varVal = std::getenv (environmentVariableName);
127 bool retVal = defaultValue;
128 if (varVal != NULL) {
129 auto state = environmentVariableState(std::string(varVal));
130 if (state == EnvironmentVariableIsSet_ON) retVal =
true;
131 else if (state == EnvironmentVariableIsSet_OFF) retVal =
false;
137 idempotentlyGetEnvironmentVariableAsBool (
bool& value,
139 const char environmentVariableName[],
140 const bool defaultValue)
143 value = getEnvironmentVariableAsBool (environmentVariableName,
151 idempotentlyGetNamedEnvironmentVariableAsBool (
const char name[],
153 const char environmentVariableName[],
154 const bool defaultValue)
156 using BehaviorDetails::namedVariableMap_;
158 setEnvironmentVariableMap (environmentVariableName,
163 auto thisEnvironmentVariableMap = namedVariableMap_[environmentVariableName];
164 auto thisEnvironmentVariable = thisEnvironmentVariableMap.find(name);
165 if (thisEnvironmentVariable != thisEnvironmentVariableMap.end())
166 return thisEnvironmentVariable->second;
167 return thisEnvironmentVariableMap[
"DEFAULT"];
170 constexpr
bool debugDefault () {
171 #ifdef HAVE_TPETRA_DEBUG
175 #endif // HAVE_TPETRA_DEBUG
178 constexpr
bool verboseDefault () {
182 constexpr
bool assumeMpiIsCudaAwareDefault () {
183 #ifdef TPETRA_ASSUME_CUDA_AWARE_MPI
187 #endif // TPETRA_ASSUME_CUDA_AWARE_MPI
194 constexpr
char envVarName[] =
"TPETRA_DEBUG";
195 constexpr
bool defaultValue = debugDefault ();
197 static bool value_ = defaultValue;
198 static bool initialized_ =
false;
199 return idempotentlyGetEnvironmentVariableAsBool (value_,
207 if (BehaviorDetails::verboseDisabled_)
return false;
209 constexpr
char envVarName[] =
"TPETRA_VERBOSE";
210 constexpr
bool defaultValue = verboseDefault ();
212 static bool value_ = defaultValue;
213 static bool initialized_ =
false;
214 return idempotentlyGetEnvironmentVariableAsBool (value_,
222 constexpr
char envVarName[] =
"TPETRA_ASSUME_CUDA_AWARE_MPI";
223 constexpr
bool defaultValue = assumeMpiIsCudaAwareDefault ();
225 static bool value_ = defaultValue;
226 static bool initialized_ =
false;
227 return idempotentlyGetEnvironmentVariableAsBool (value_,
236 static int savedval=-1;
237 if(savedval!=-1)
return savedval;
238 const char* varVal = std::getenv (
"MM_TAFC_OptimizationCoreCount");
239 if (varVal ==
nullptr) {
243 savedval = std::stoi(std::string(varVal));
250 constexpr
char envVarName[] =
"TPETRA_DEBUG";
251 constexpr
bool defaultValue =
false;
253 static bool initialized_ =
false;
254 return idempotentlyGetNamedEnvironmentVariableAsBool (name,
262 if (BehaviorDetails::verboseDisabled_)
return false;
264 constexpr
char envVarName[] =
"TPETRA_VERBOSE";
265 constexpr
bool defaultValue =
false;
267 static bool initialized_ =
false;
268 return idempotentlyGetNamedEnvironmentVariableAsBool (name,
275 BehaviorDetails::verboseDisabled_ =
false;
279 BehaviorDetails::verboseDisabled_ =
true;
static int TAFC_OptimizationCoreCount()
The core count above which Tpetra::CrsMatrix::transferAndFillComplere will attempt to do advanced nei...
static void disable_verbose_behavior()
Disable verbose mode, programatically.
static bool debug()
Whether Tpetra is in debug mode.
static bool assumeMpiIsCudaAware()
Whether to assume that MPI is CUDA aware.
static bool verbose()
Whether Tpetra is in verbose mode.
static void enable_verbose_behavior()
Enable verbose mode, programatically.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.