logger.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2019 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Eduard Valeyev
19  * Department of Chemistry, Virginia Tech
20  *
21  * util/logger.h
22  * Mar 11, 2019
23  *
24  */
25 
26 #ifndef TILEDARRAY_UTIL_LOGGER_H__INCLUDED
27 #define TILEDARRAY_UTIL_LOGGER_H__INCLUDED
28 
29 #include <functional>
30 #include <ostream>
31 
32 #include <TiledArray/config.h>
33 #include <TiledArray/range.h>
35 
36 namespace TiledArray {
37 
38 template <typename T>
39 struct TileOpsLogger : public Singleton<TileOpsLogger<T>> {
40  using range_transform_t = std::function<Range(const Range&)>;
41  using range_filter_t = std::function<bool(const Range&)>;
43  std::function<void(std::ostream& os, const Range&, const T*, const Range&,
44  const T*, const Range&, const T*)>;
45 
46  // GEMM task logging
47  bool gemm = false;
56 
57  // logging
58  std::ostream* log = &std::cout;
59 
60  template <typename U>
62  *log << std::forward<U>(arg);
63  return *this;
64  }
65 
66  TileOpsLogger& operator<<(std::ostream& (*func)(std::ostream&)) {
67  *log << func;
68  return *this;
69  }
70 
71  private:
72  friend class Singleton<TileOpsLogger>;
73  TileOpsLogger(int log_level = TA_TILE_OPS_LOG_LEVEL) {
74  if (log_level > 0) {
75  gemm = true;
76  }
77  }
78 };
79 
80 } // namespace TiledArray
81 
82 #endif // TILEDARRAY_UTIL_LOGGER_H__INCLUDED
std::function< Range(const Range &)> range_transform_t
Definition: logger.h:40
std::function< bool(const Range &)> range_filter_t
Definition: logger.h:41
Singleton base class To create a singleton class A do:
Definition: singleton.h:55
std::function< void(std::ostream &os, const Range &, const T *, const Range &, const T *, const Range &, const T *)> gemm_printer_t
Definition: logger.h:44
range_filter_t gemm_left_range_filter
Definition: logger.h:52
std::ostream * log
Definition: logger.h:58
range_transform_t gemm_left_range_transform
Definition: logger.h:48
range_transform_t gemm_right_range_transform
Definition: logger.h:49
range_transform_t gemm_result_range_transform
Definition: logger.h:50
TileOpsLogger & operator<<(U &&arg)
Definition: logger.h:61
range_filter_t gemm_right_range_filter
Definition: logger.h:53
gemm_printer_t gemm_printer
Definition: logger.h:55
range_filter_t gemm_result_range_filter
Definition: logger.h:51
A (hyperrectangular) interval on , space of integer -indices.
Definition: range.h:46