Documentation of CSL
operations_monitor.h
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
16  #pragma once
17 
18 #ifdef MONITOR_OPERATIONS
19 
20 #include <ctime>
21 #include "enum.h"
22 #include "abstract.h"
23 
24 namespace csl {
25 
26 struct FileDeleter {
27  FileDeleter() {
28  [[maybe_unused]] int sysres = system("rm sum_monitor.txt prod_monitor.txt");
29  }
30 };
31 
32 inline const FileDeleter deleter;
33 
34 struct SumMonitor {
35 
36  SumMonitor(size_t t_nArgs, int t_mode)
37  :nArgs(t_nArgs),
38  mode(t_mode),
39  time(std::clock())
40  {}
41 
42  ~SumMonitor() {
43  std::fstream fout("sum_monitor.txt", std::ios::app);
44  fout.precision(6);
45  fout << (std::clock() - time) * 1000. / CLOCKS_PER_SEC << ' '
46  << nArgs << ' '
47  << mode << ' '
48  // << static_cast<int>(type) << ' '
49  << indicial << ' '
50  << simple << '\n';
51  }
52 
53  size_t nArgs;
54  int mode;
56  bool indicial { false };
57  bool simple { false };
58  std::clock_t time;
59 };
60 
61 struct ProdMonitor {
62 
63  ProdMonitor(size_t t_nArgs, int t_mode)
64  :nArgs(t_nArgs),
65  mode(t_mode),
66  time(std::clock())
67  {}
68 
69  ProdMonitor(size_t t_nArgs, int t_mode, csl::Expr const &a, csl::Expr const &b)
70  :nArgs(t_nArgs),
71  mode(t_mode),
72  time(std::clock())
73  {
74  if (a->getPrimaryType() == csl::PrimaryType::Numerical)
75  ++n;
76  if (b->getPrimaryType() == csl::PrimaryType::Numerical)
77  ++n;
78  }
79 
80  ~ProdMonitor() {
81  std::fstream fout("prod_monitor.txt", std::ios::app);
82  fout.precision(6);
83  fout << (std::clock() - time) * 1000. / CLOCKS_PER_SEC << ' '
84  << nArgs << ' '
85  << mode << ' '
86  //<< static_cast<int>(type) << ' '
87  << indicial << ' '
88  << simple << ' '
89  << op << ' '
90  << n << '\n';
91  }
92 
93  size_t nArgs;
94  int mode;
96  bool indicial { false };
97  bool op { false };
98  bool simple { false };
99  size_t n { 0 };
100  std::clock_t time;
101 };
102 
103 }
104 
105 #endif
Namespace for csl library.
Definition: abreviation.h:34
Type
Enum of the different types of Abstract (i.e. list of all possible specializations).
Definition: enum.h:47
Definition: diagonalization.h:32
Some of csl enumerations.
Base classes for all exprs in the program.
Expression type/.
Definition: abstract.h:1573