Loading...
Searching...
No Matches
LogManager.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
5/*
6 * Log.h
7 *
8 * Created on: 17 Jun 2020
9 * Author: Maxim Masterov
10 * Company: SURFSara
11 */
12
13#ifndef MANAGERS_IO_LOGMANAGER_H_
14#define MANAGERS_IO_LOGMANAGER_H_
15
16#include <iostream>
17
18#ifdef GPR_LINALG_SCALAPACK
19#include <mpi.h>
20#endif
21
22namespace gpr {
23namespace io {
24
29public:
32
37 inline void setEnabled(bool enabled) noexcept
38 {
39 enabled_ = enabled;
40 }
41
42 [[nodiscard]] inline bool enabled() const noexcept
43 {
44 return enabled_;
45 }
46
52 template <typename T>
53 inline LogManager& operator<<(const T& data)
54 {
55 if (!enabled_) return *this;
56#ifdef GPR_LINALG_SCALAPACK
57 int rank = 0;
58 int init = 0;
59 MPI_Initialized(&init);
60 if (init) MPI_Comm_rank(MPI_COMM_WORLD, &rank);
61 if (rank != 0) return *this;
62#endif
63 std::clog << data;
64 return *this;
65 }
66
67private:
68 bool enabled_ = true;
69};
70
71} /* namespace io */
72} /* namespace gpr */
73
74#endif /* MANAGERS_IO_LOGMANAGER_H_ */
LogManager & operator<<(const T &data)
Writes data to the log.
Definition LogManager.h:53
bool enabled() const noexcept
Definition LogManager.h:42
void setEnabled(bool enabled) noexcept
Switch the log on or off. A log starts enabled. A disabled log discards what is written to it.
Definition LogManager.h:37
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16