Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_Behavior.cpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Tpetra: Templated Linear Algebra Services Package
6 // Copyright (2008) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // ************************************************************************
39 // @HEADER
40 */
41 // clang-format on
42 #include <algorithm> // std::transform
43 #include <array>
44 #include <cctype> // std::toupper
45 #include <cstdlib> // std::getenv
46 #include <functional>
47 #include <map>
48 #include <stdexcept>
49 #include <string>
50 #include <string_view>
51 #include <vector>
52 
53 #include "Teuchos_OrdinalTraits.hpp"
54 #include "Teuchos_TestForException.hpp"
55 #include "TpetraCore_config.h"
57 #include "KokkosKernels_config.h" // for TPL enable macros
58 
93 // environ should be available on posix platforms
94 #if not(defined(WIN) && (_MSC_VER >= 1900))
95 // needs to be in the global namespace
96 extern char **environ;
97 #endif
98 
99 namespace Tpetra {
100 namespace Details {
101 
102 namespace BehaviorDetails {
103 
104 constexpr const std::string_view RESERVED_PREFIX = "TPETRA_";
105 constexpr const std::string_view ASSUME_GPU_AWARE_MPI =
106  "TPETRA_ASSUME_GPU_AWARE_MPI";
107 constexpr const std::string_view CUDA_LAUNCH_BLOCKING = "CUDA_LAUNCH_BLOCKING";
108 constexpr const std::string_view MM_TAFC_OptimizationCoreCount =
109  "MM_TAFC_OptimizationCoreCount";
110 constexpr const std::string_view VERBOSE_PRINT_COUNT_THRESHOLD =
111  "TPETRA_VERBOSE_PRINT_COUNT_THRESHOLD";
112 constexpr const std::string_view ROW_IMBALANCE_THRESHOLD =
113  "TPETRA_ROW_IMBALANCE_THRESHOLD";
114 constexpr const std::string_view MULTIVECTOR_USE_MERGE_PATH =
115  "TPETRA_MULTIVECTOR_USE_MERGE_PATH";
116 constexpr const std::string_view VECTOR_DEVICE_THRESHOLD =
117  "TPETRA_VECTOR_DEVICE_THRESHOLD";
118 constexpr const std::string_view HIERARCHICAL_UNPACK_BATCH_SIZE =
119  "TPETRA_HIERARCHICAL_UNPACK_BATCH_SIZE";
120 constexpr const std::string_view HIERARCHICAL_UNPACK_TEAM_SIZE =
121  "TPETRA_HIERARCHICAL_UNPACK_TEAM_SIZE";
122 constexpr const std::string_view USE_TEUCHOS_TIMERS =
123  "TPETRA_USE_TEUCHOS_TIMERS";
124 constexpr const std::string_view USE_KOKKOS_PROFILING =
125  "TPETRA_USE_KOKKOS_PROFILING";
126 constexpr const std::string_view DEBUG = "TPETRA_DEBUG";
127 constexpr const std::string_view VERBOSE = "TPETRA_VERBOSE";
128 constexpr const std::string_view TIMING = "TPETRA_TIMING";
129 constexpr const std::string_view HIERARCHICAL_UNPACK =
130  "TPETRA_HIERARCHICAL_UNPACK";
131 constexpr const std::string_view SKIP_COPY_AND_PERMUTE =
132  "TPETRA_SKIP_COPY_AND_PERMUTE";
133 constexpr const std::string_view FUSED_RESIDUAL = "TPETRA_FUSED_RESIDUAL";
134 constexpr const std::string_view OVERLAP = "TPETRA_OVERLAP";
135 constexpr const std::string_view SPACES_ID_WARN_LIMIT =
136  "TPETRA_SPACES_ID_WARN_LIMIT";
137 constexpr const std::string_view TIME_KOKKOS_DEEP_COPY =
138  "TPETRA_TIME_KOKKOS_DEEP_COPY";
139 constexpr const std::string_view TIME_KOKKOS_DEEP_COPY_VERBOSE1 =
140  "TPETRA_TIME_KOKKOS_DEEP_COPY_VERBOSE1";
141 constexpr const std::string_view TIME_KOKKOS_DEEP_COPY_VERBOSE2 =
142  "TPETRA_TIME_KOKKOS_DEEP_COPY_VERBOSE2";
143 constexpr const std::string_view TIME_KOKKOS_FENCE = "TPETRA_TIME_KOKKOS_FENCE";
144 constexpr const std::string_view TIME_KOKKOS_FUNCTIONS =
145  "TPETRA_TIME_KOKKOS_FUNCTIONS";
146 
147 // construct an std::array of string_view with any number of provided
148 // string_views
149 template <typename... Elems>
150 constexpr std::array<std::string_view, sizeof...(Elems)>
151 make_array(Elems &&... elems) {
152  return {std::forward<Elems>(elems)...};
153 }
154 
155 constexpr const auto RECOGNIZED_VARS = make_array(
156  ASSUME_GPU_AWARE_MPI, CUDA_LAUNCH_BLOCKING, MM_TAFC_OptimizationCoreCount,
157  VERBOSE_PRINT_COUNT_THRESHOLD, ROW_IMBALANCE_THRESHOLD,
158  MULTIVECTOR_USE_MERGE_PATH, VECTOR_DEVICE_THRESHOLD,
159  HIERARCHICAL_UNPACK_BATCH_SIZE, HIERARCHICAL_UNPACK_TEAM_SIZE,
160  USE_TEUCHOS_TIMERS, USE_KOKKOS_PROFILING, DEBUG, VERBOSE, TIMING,
161  HIERARCHICAL_UNPACK, SKIP_COPY_AND_PERMUTE, FUSED_RESIDUAL, OVERLAP,
162  SPACES_ID_WARN_LIMIT, TIME_KOKKOS_DEEP_COPY, TIME_KOKKOS_DEEP_COPY_VERBOSE1,
163  TIME_KOKKOS_DEEP_COPY_VERBOSE2, TIME_KOKKOS_FENCE, TIME_KOKKOS_FUNCTIONS);
164 
165 // clang-format off
166 std::map<std::string, std::map<std::string, bool> > namedVariableMap_;
167 bool verboseDisabled_ = false;
168 bool timingDisabled_ = false;
169 }
170 
171 namespace { // (anonymous)
172 
173  enum EnvironmentVariableState
174  {
175  EnvironmentVariableIsSet_ON,
176  EnvironmentVariableIsSet_OFF,
177  EnvironmentVariableIsSet,
178  EnvironmentVariableIsNotSet
179  };
180 
181  // See example here:
182  //
183  // http://en.cppreference.com/w/cpp/string/byte/toupper
184  std::string stringToUpper (std::string s)
185  {
186  std::transform (s.begin (), s.end (), s.begin (),
187  [] (unsigned char c) { return std::toupper (c); });
188  return s;
189  }
190 
191  void
192  split(const std::string_view s,
193  std::function<void(const std::string&)> f,
194  const char sep=',')
195  {
196  typedef std::string::size_type size_type;
197  size_type cur_pos, last_pos=0, length=s.length();
198  while(last_pos < length + 1)
199  {
200  cur_pos = s.find_first_of(sep, last_pos);
201  if(cur_pos == std::string::npos)
202  {
203  cur_pos = length;
204  }
205  if(cur_pos!=last_pos) {
206  auto token = std::string(s.data()+last_pos, (size_type)cur_pos-last_pos);
207  f(token);
208  }
209  last_pos = cur_pos + 1;
210  }
211  return;
212  }
213 
214  EnvironmentVariableState
215  environmentVariableState(const std::string& environmentVariableValue)
216  {
217  std::string v = stringToUpper(environmentVariableValue);
218  if (v == "1" || v == "YES" || v == "TRUE" || v == "ON")
219  // Environment variable is "ON"
220  return EnvironmentVariableIsSet_ON;
221  else if (v == "0" || v == "NO" || v == "FALSE" || v == "OFF")
222  // Environment variable is "OFF"
223  return EnvironmentVariableIsSet_OFF;
224  // Environment has some other non-boolean value
225  return EnvironmentVariableIsSet;
226  }
227 
228  void
229  setEnvironmentVariableMap (const char environmentVariableName[],
230  std::map<std::string,std::map<std::string, bool> >& valsMap,
231  const bool defaultValue)
232  {
233  using std::map;
234  using std::getenv;
235  using std::string;
236  using std::vector;
237 
238  // Set the default value for this variable
239  valsMap[environmentVariableName] = map<string,bool>{{"DEFAULT", defaultValue}};
240 
241  const char* varVal = getenv (environmentVariableName);
242  if (varVal == nullptr) {
243  // Environment variable is not set, use the default value for any named
244  // variants
245  return;
246  }
247 
248  // Variable is not empty.
249  const string varStr(varVal);
250  vector<string> names;
251  split(varStr, [&](const string& x){names.push_back(x);});
252  for (auto const& name: names) {
253  auto state = environmentVariableState(name);
254  if (state == EnvironmentVariableIsSet_ON) {
255  // Environment variable was set as ENVAR_NAME=[1,YES,TRUE,ON]
256  // Global value takes precedence
257  valsMap[environmentVariableName]["DEFAULT"] = true;
258  }
259  else if (state == EnvironmentVariableIsSet_OFF) {
260  // Environment variable was set as ENVAR_NAME=[0,NO,FALSE,OFF]
261  // Global value takes precedence
262  valsMap[environmentVariableName]["DEFAULT"] = false;
263  }
264  else {
265  // Environment variable was set as ENVAR_NAME=...:name:...
266  // So we set the mapping true for this named variant
267  valsMap[environmentVariableName][name] = true;
268  }
269  }
270  return;
271  }
272 
273  bool
274  idempotentlyGetNamedEnvironmentVariableAsBool (const char name[],
275  bool& initialized,
276  const char environmentVariableName[],
277  const bool defaultValue)
278  {
279  using BehaviorDetails::namedVariableMap_;
280  if (! initialized) {
281  setEnvironmentVariableMap (environmentVariableName,
282  namedVariableMap_,
283  defaultValue);
284  initialized = true;
285  }
286  auto thisEnvironmentVariableMap = namedVariableMap_[environmentVariableName];
287  auto thisEnvironmentVariable = thisEnvironmentVariableMap.find(name);
288  if (thisEnvironmentVariable != thisEnvironmentVariableMap.end())
289  return thisEnvironmentVariable->second;
290  return thisEnvironmentVariableMap["DEFAULT"];
291  }
292 // clang-format on
293 
294 template <typename T>
295 T getEnvironmentVariable(const std::string_view environmentVariableName,
296  const T defaultValue) {
297  const char prefix[] = "Tpetra::Details::Behavior: ";
298 
299  const char *varVal = std::getenv(environmentVariableName.data());
300  if (varVal == nullptr) {
301  return defaultValue;
302  } else {
303  std::stringstream ss(varVal);
304  T parsed;
305  ss >> parsed;
306 
307  TEUCHOS_TEST_FOR_EXCEPTION(!ss, std::out_of_range,
308  prefix << "Environment "
309  "variable \""
310  << environmentVariableName
311  << "\" has a "
312  "value "
313  << varVal
314  << " that cannot be parsed as a "
315  << typeid(T).name() << ".");
316 
317  return parsed;
318  }
319 }
320 
321 // full specialization of bool to preserve historical Tpetra parsing behavior
322 template <>
323 bool getEnvironmentVariable<bool>(
324  const std::string_view environmentVariableName, const bool defaultValue) {
325  const char *varVal = std::getenv(environmentVariableName.data());
326  bool retVal = defaultValue;
327  if (varVal != nullptr) {
328  auto state = environmentVariableState(std::string(varVal));
329  if (state == EnvironmentVariableIsSet_ON)
330  retVal = true;
331  else if (state == EnvironmentVariableIsSet_OFF)
332  retVal = false;
333  }
334  return retVal;
335 }
336 
342 template <>
343 size_t
344 getEnvironmentVariable<size_t>(const std::string_view environmentVariableName,
345  const size_t defaultValue) {
346  const char prefix[] = "Tpetra::Details::Behavior: ";
347 
348  const char *varVal = std::getenv(environmentVariableName.data());
349  if (varVal == nullptr) {
350  return defaultValue;
351  } else {
352  long long val = std::stoll(stringToUpper(varVal));
353  if (val < static_cast<long long>(0)) {
354  // If negative - user has requested threshold be lifted
355  return std::numeric_limits<size_t>::max();
356  }
357  if (sizeof(long long) > sizeof(size_t)) {
358  // It's hard to test this code, but I want to try writing it
359  // at least, in case we ever have to run on 32-bit machines or
360  // machines with sizeof(long long)=16 and sizeof(size_t)=8.
361  constexpr long long maxSizeT =
362  static_cast<long long>(std::numeric_limits<size_t>::max());
363  TEUCHOS_TEST_FOR_EXCEPTION(
364  val > maxSizeT, std::out_of_range,
365  prefix << "Environment "
366  "variable \""
367  << environmentVariableName
368  << "\" has a "
369  "value "
370  << val << " larger than the largest size_t value " << maxSizeT
371  << ".");
372  }
373  return static_cast<size_t>(val);
374  }
375 }
376 
377 template <typename T>
378 T idempotentlyGetEnvironmentVariable(
379  T &value, bool &initialized, const std::string_view environmentVariableName,
380  const T defaultValue) {
381  if (!initialized) {
382  value = getEnvironmentVariable<T>(environmentVariableName, defaultValue);
383  initialized = true;
384  }
385  return value;
386 }
387 
388 // clang-format off
389  constexpr bool debugDefault () {
390 #ifdef HAVE_TPETRA_DEBUG
391  return true;
392 #else
393  return false;
394 #endif // HAVE_TPETRA_DEBUG
395  }
396 
397  constexpr bool verboseDefault () {
398  return false;
399  }
400 
401  constexpr bool timingDefault () {
402  return false;
403  }
404 
405  constexpr bool assumeMpiIsGPUAwareDefault () {
406 #ifdef TPETRA_ASSUME_GPU_AWARE_MPI
407  return true;
408 #else
409  return false;
410 #endif // TPETRA_ASSUME_GPU_AWARE_MPI
411  }
412 
413  constexpr bool cudaLaunchBlockingDefault () {
414  return false;
415  }
416 
417  constexpr bool hierarchicalUnpackDefault () {
418  return true;
419  }
420 
421 } // namespace (anonymous)
422 // clang-format on
423 
425 
426  static bool once = false;
427 
428  if (!once) {
429  const char prefix[] = "Tpetra::Details::Behavior: ";
430  char **env;
431 #if defined(WIN) && (_MSC_VER >= 1900)
432  env = *__p__environ();
433 #else
434  env = environ; // defined at the top of this file as extern char **environ;
435 #endif
436  for (; *env; ++env) {
437 
438  std::string name;
439  std::string value;
440  const std::string_view ev(*env);
441 
442  // split name=value on the first =, everything before = is name
443  split(
444  ev,
445  [&](const std::string &s) {
446  if (name.empty()) {
447  name = s;
448  } else {
449  value = s;
450  }
451  },
452  '=');
453 
454  if (name.size() >= BehaviorDetails::RESERVED_PREFIX.size() &&
455  name.substr(0, BehaviorDetails::RESERVED_PREFIX.size()) ==
456  BehaviorDetails::RESERVED_PREFIX) {
457  const auto it = std::find(BehaviorDetails::RECOGNIZED_VARS.begin(),
458  BehaviorDetails::RECOGNIZED_VARS.end(), name);
459  TEUCHOS_TEST_FOR_EXCEPTION(
460  it == BehaviorDetails::RECOGNIZED_VARS.end(), std::out_of_range,
461  prefix << "Environment "
462  "variable \""
463  << name << "\" (prefixed with \""
464  << BehaviorDetails::RESERVED_PREFIX
465  << "\") is not a recognized Tpetra variable.");
466  }
467  }
468 
469  once = true;
470  }
471 }
472 
474  constexpr bool defaultValue = debugDefault();
475 
476  static bool value_ = defaultValue;
477  static bool initialized_ = false;
478  return idempotentlyGetEnvironmentVariable(
479  value_, initialized_, BehaviorDetails::DEBUG, defaultValue);
480 }
481 
483  if (BehaviorDetails::verboseDisabled_)
484  return false;
485 
486  constexpr bool defaultValue = verboseDefault();
487 
488  static bool value_ = defaultValue;
489  static bool initialized_ = false;
490  return idempotentlyGetEnvironmentVariable(
491  value_, initialized_, BehaviorDetails::VERBOSE, defaultValue);
492 }
493 
495  if (BehaviorDetails::timingDisabled_)
496  return false;
497 
498  constexpr bool defaultValue = timingDefault();
499 
500  static bool value_ = defaultValue;
501  static bool initialized_ = false;
502  return idempotentlyGetEnvironmentVariable(
503  value_, initialized_, BehaviorDetails::TIMING, defaultValue);
504 }
505 
507  constexpr bool defaultValue = assumeMpiIsGPUAwareDefault();
508 
509  static bool value_ = defaultValue;
510  static bool initialized_ = false;
511  return idempotentlyGetEnvironmentVariable(
512  value_, initialized_, BehaviorDetails::ASSUME_GPU_AWARE_MPI,
513  defaultValue);
514 }
515 
517  constexpr bool defaultValue = cudaLaunchBlockingDefault();
518 
519  static bool value_ = defaultValue;
520  static bool initialized_ = false;
521  return idempotentlyGetEnvironmentVariable(
522  value_, initialized_, BehaviorDetails::CUDA_LAUNCH_BLOCKING,
523  defaultValue);
524 }
525 
527  constexpr int _default = 3000;
528  static int value_ = _default;
529  static bool initialized_ = false;
530  return idempotentlyGetEnvironmentVariable(
531  value_, initialized_, BehaviorDetails::MM_TAFC_OptimizationCoreCount,
532  _default);
533 }
534 
536  constexpr size_t defaultValue(200);
537 
538  static size_t value_ = defaultValue;
539  static bool initialized_ = false;
540  return idempotentlyGetEnvironmentVariable(
541  value_, initialized_, BehaviorDetails::VERBOSE_PRINT_COUNT_THRESHOLD,
542  defaultValue);
543 }
544 
546  constexpr size_t defaultValue(256);
547 
548  static size_t value_ = defaultValue;
549  static bool initialized_ = false;
550  return idempotentlyGetEnvironmentVariable(
551  value_, initialized_, BehaviorDetails::ROW_IMBALANCE_THRESHOLD,
552  defaultValue);
553 }
554 
556  constexpr bool defaultValue = false;
557 
558  static bool value_ = defaultValue;
559  static bool initialized_ = false;
560  return idempotentlyGetEnvironmentVariable(
561  value_, initialized_, BehaviorDetails::MULTIVECTOR_USE_MERGE_PATH,
562  defaultValue);
563 }
564 
566  constexpr size_t defaultValue(22000);
567 
568  static size_t value_ = defaultValue;
569  static bool initialized_ = false;
570  return idempotentlyGetEnvironmentVariable(
571  value_, initialized_, BehaviorDetails::VECTOR_DEVICE_THRESHOLD,
572  defaultValue);
573 }
574 
576 
577 #ifdef HAVE_TPETRA_INST_CUDA
578  constexpr size_t defaultValue(16);
579 #else
580  constexpr size_t defaultValue(256);
581 #endif
582 
583  static size_t value_ = defaultValue;
584  static bool initialized_ = false;
585  return idempotentlyGetEnvironmentVariable(
586  value_, initialized_, BehaviorDetails::HIERARCHICAL_UNPACK_BATCH_SIZE,
587  defaultValue);
588 }
589 
591 #ifdef HAVE_TPETRA_INST_CUDA
592  const size_t defaultValue(16);
593 #else
594  const size_t defaultValue(Teuchos::OrdinalTraits<size_t>::invalid());
595 #endif
596 
597  static size_t value_ = defaultValue;
598  static bool initialized_ = false;
599  return idempotentlyGetEnvironmentVariable(
600  value_, initialized_, BehaviorDetails::HIERARCHICAL_UNPACK_TEAM_SIZE,
601  defaultValue);
602 }
603 
605  constexpr bool defaultValue(false);
606 
607  static bool value_ = defaultValue;
608  static bool initialized_ = false;
609  return idempotentlyGetEnvironmentVariable(
610  value_, initialized_, BehaviorDetails::USE_TEUCHOS_TIMERS, defaultValue);
611 }
612 
614  constexpr bool defaultValue(false);
615 
616  static bool value_ = defaultValue;
617  static bool initialized_ = false;
618  return idempotentlyGetEnvironmentVariable(
619  value_, initialized_, BehaviorDetails::USE_KOKKOS_PROFILING,
620  defaultValue);
621 }
622 
623 bool Behavior::debug(const char name[]) {
624  constexpr bool defaultValue = false;
625 
626  static bool initialized_ = false;
627  return idempotentlyGetNamedEnvironmentVariableAsBool(
628  name, initialized_, BehaviorDetails::DEBUG.data(), defaultValue);
629 }
630 
631 bool Behavior::verbose(const char name[]) {
632  if (BehaviorDetails::verboseDisabled_)
633  return false;
634 
635  constexpr bool defaultValue = false;
636 
637  static bool initialized_ = false;
638  return idempotentlyGetNamedEnvironmentVariableAsBool(
639  name, initialized_, BehaviorDetails::VERBOSE.data(), defaultValue);
640 }
641 
643  BehaviorDetails::verboseDisabled_ = false;
644 }
645 
647  BehaviorDetails::verboseDisabled_ = true;
648 }
649 
650 bool Behavior::timing(const char name[]) {
651  if (BehaviorDetails::timingDisabled_)
652  return false;
653 
654  constexpr bool defaultValue = false;
655 
656  static bool initialized_ = false;
657  return idempotentlyGetNamedEnvironmentVariableAsBool(
658  name, initialized_, BehaviorDetails::TIMING.data(), defaultValue);
659 }
660 
661 void Behavior::enable_timing() { BehaviorDetails::timingDisabled_ = false; }
662 
663 void Behavior::disable_timing() { BehaviorDetails::timingDisabled_ = true; }
664 
666  constexpr bool defaultValue = hierarchicalUnpackDefault();
667 
668  static bool value_ = defaultValue;
669  static bool initialized_ = false;
670  return idempotentlyGetEnvironmentVariable(
671  value_, initialized_, BehaviorDetails::HIERARCHICAL_UNPACK, defaultValue);
672 }
673 
675  constexpr bool defaultValue(false);
676 
677  static bool value_ = defaultValue;
678  static bool initialized_ = false;
679  return idempotentlyGetEnvironmentVariable(
680  value_, initialized_, BehaviorDetails::SKIP_COPY_AND_PERMUTE,
681  defaultValue);
682 }
683 
685 #if defined(KOKKOSKERNELS_ENABLE_TPL_CUSPARSE) || \
686  defined(KOKKOSKERNELS_ENABLE_TPL_ROCSPARSE) || \
687  defined(KOKKOSKERNELS_ENABLE_TPL_MKL)
688  constexpr bool defaultValue(false);
689 #else
690  constexpr bool defaultValue(true);
691 #endif
692 
693  static bool value_ = defaultValue;
694  static bool initialized_ = false;
695  return idempotentlyGetEnvironmentVariable(
696  value_, initialized_, BehaviorDetails::FUSED_RESIDUAL, defaultValue);
697 }
698 
700  constexpr bool defaultValue(false);
701 
702  static bool value_ = defaultValue;
703  static bool initialized_ = false;
704  return idempotentlyGetEnvironmentVariable(
705  value_, initialized_, BehaviorDetails::OVERLAP, defaultValue);
706 }
707 
709  constexpr size_t defaultValue(16);
710 
711  static size_t value_ = defaultValue;
712  static bool initialized_ = false;
713  return idempotentlyGetEnvironmentVariable(
714  value_, initialized_, BehaviorDetails::SPACES_ID_WARN_LIMIT,
715  defaultValue);
716 }
717 
719  constexpr bool defaultValue(false);
720 
721  static bool value_ = defaultValue;
722  static bool initialized_ = false;
723  return idempotentlyGetEnvironmentVariable(
724  value_, initialized_, BehaviorDetails::TIME_KOKKOS_DEEP_COPY,
725  defaultValue);
726 }
727 
729  constexpr bool defaultValue(false);
730 
731  static bool value_ = defaultValue;
732  static bool initialized_ = false;
733  return idempotentlyGetEnvironmentVariable(
734  value_, initialized_, BehaviorDetails::TIME_KOKKOS_DEEP_COPY_VERBOSE1,
735  defaultValue);
736 }
737 
739  constexpr bool defaultValue(false);
740 
741  static bool value_ = defaultValue;
742  static bool initialized_ = false;
743  return idempotentlyGetEnvironmentVariable(
744  value_, initialized_, BehaviorDetails::TIME_KOKKOS_DEEP_COPY_VERBOSE2,
745  defaultValue);
746 }
747 
749  constexpr bool defaultValue(false);
750 
751  static bool value_ = defaultValue;
752  static bool initialized_ = false;
753  return idempotentlyGetEnvironmentVariable(
754  value_, initialized_, BehaviorDetails::TIME_KOKKOS_FENCE, defaultValue);
755 }
756 
758  constexpr bool defaultValue(false);
759 
760  static bool value_ = defaultValue;
761  static bool initialized_ = false;
762  return idempotentlyGetEnvironmentVariable(
763  value_, initialized_, BehaviorDetails::TIME_KOKKOS_FUNCTIONS,
764  defaultValue);
765 }
766 
767 } // namespace Details
768 } // namespace Tpetra
static bool useMergePathMultiVector()
Whether to use the cuSPARSE merge path algorithm to perform sparse matrix-multivector products...
static int TAFC_OptimizationCoreCount()
MPI process count above which Tpetra::CrsMatrix::transferAndFillComplete will attempt to do advanced ...
static bool overlapCommunicationAndComputation()
Overlap communication and computation.
static bool timing()
Whether Tpetra is in timing mode.
static void disable_verbose_behavior()
Disable verbose mode, programatically.
static size_t multivectorKernelLocationThreshold()
the threshold for transitioning from device to host
static bool assumeMpiIsGPUAware()
Whether to assume that MPI is CUDA aware.
static size_t spacesIdWarnLimit()
Warn if more than this many Kokkos spaces are accessed.
static bool debug()
Whether Tpetra is in debug mode.
static size_t hierarchicalUnpackTeamSize()
Size of team for hierarchical unpacking.
static void reject_unrecognized_env_vars()
Search the environment for TPETRA_ variables and reject unrecognized ones.
static bool timeKokkosFunctions()
Add Teuchos timers for all host calls to Kokkos::parallel_for(), Kokkos::parallel_reduce() and Kokkos...
static bool fusedResidual()
Fusing SpMV and update in residual instead of using 2 kernel launches. Fusing kernels implies that no...
static bool profilingRegionUseTeuchosTimers()
Use Teuchos::Timer in Tpetra::ProfilingRegion.
static void disable_timing()
Disable timing, programatically.
static bool hierarchicalUnpack()
Unpack rows of a matrix using hierarchical unpacking.
static void enable_timing()
Enable timing, programatically.
static bool verbose()
Whether Tpetra is in verbose mode.
static size_t rowImbalanceThreshold()
Threshold for deciding if a local matrix is &quot;imbalanced&quot; in the number of entries per row...
static size_t hierarchicalUnpackBatchSize()
Size of batch for hierarchical unpacking.
static bool timeKokkosDeepCopyVerbose2()
Adds verbose output to Kokkos deep_copy timers by appending source, destination, and size...
static bool timeKokkosDeepCopyVerbose1()
Adds verbose output to Kokkos deep_copy timers by appending source and destination. This is especially useful for identifying host/device data transfers.
static bool skipCopyAndPermuteIfPossible()
Skip copyAndPermute if possible.
static void enable_verbose_behavior()
Enable verbose mode, programatically.
static size_t verbosePrintCountThreshold()
Number of entries below which arrays, lists, etc. will be printed in debug mode.
static bool timeKokkosFence()
Add Teuchos timers for all host calls to Kokkos::fence().
static bool cudaLaunchBlocking()
Whether the CUDA_LAUNCH_BLOCKING environment variable has been set.
static bool timeKokkosDeepCopy()
Add Teuchos timers for all host calls to Kokkos::deep_copy(). This is especially useful for identifyi...
static bool profilingRegionUseKokkosProfiling()
Use Kokkos::Profiling in Tpetra::ProfilingRegion.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra&#39;s behavior.