GADGET-4
logs.h
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#ifndef LOGS_H
13#define LOGS_H
14
15#include <stdio.h>
16
17#include "../main/simulation.h"
18#include "../mpi_utils/setcomm.h"
19
20#define CPU_STRING_LEN 120
21
22#define TIMER_STACK_DEPTH 30
23
24class simparticles;
25class lcparticles;
26
27class logs : public setcomm
28{
29 public:
30 logs() : setcomm("delayed init") // constructor
31 {
32
33#define TIMER_STRUCT
34#include "../logs/timer.h"
35#undef TIMER_STRUCT
36
37 }
38
39
40
42
43 double CPUThisRun;
45 FILE *FdInfo,
55 FILE *FdCPUCSV;
57#ifdef MEASURE_TOTAL_MOMENTUM
58 FILE *FdMomentum;
59#endif
60
61#ifdef STARFORMATION
62 FILE *FdSfr;
63#endif
64
65#ifdef DEBUG_MD5
66 FILE *FdDebug;
67#endif
68
69#ifdef FORCETEST
70 FILE *FdForceTest;
71#endif
72
73 void init_cpu_log(simparticles *Sp_ptr);
74 void open_logfiles(void);
75 void write_cpu_log(void);
76 void output_log_messages(void);
77 void compute_statistics(void);
80 void log_debug_md5(const char *msg);
81 void calc_memory_checksum(const char *msg, void *base, size_t bytes);
82 void block_checksum(void *base, size_t bytes, int res[4]);
83 int flush_everything(void);
85
86 double measure_time(void);
87 double timediff(double t0, double t1);
88 double second(void);
89
90 enum timers
91 {
92 CPU_NONE = -2,
93 CPU_ROOT = -1,
95#define TIMER_ENUM
96#include "../logs/timer.h"
97#undef TIMER_ENUM
98
99 };
100
104 struct timer_d
105 {
106 int parent;
107 char shortname[30];
108 char longname[30];
109 char symb;
111 char depth;
112 };
113 timer_d Timer_data[CPU_LAST + 1];
114
115 double CPU_Step[CPU_LAST];
116 double CPU_Step_Stored[CPU_LAST];
117 double CPU_Sum[CPU_LAST];
121
122 private:
123 double StartOfRun;
125 double WallclockTime;
127 void put_symbol(char *string, double t0, double t1, char c);
128
129 /* global state of system */
130 struct state_of_system
131 {
132 double Mass, EnergyKin, EnergyPot, EnergyInt, EnergyTot, Momentum[4], AngMomentum[4], CenterOfMass[4], MassComp[NTYPES],
133 EnergyKinComp[NTYPES], EnergyPotComp[NTYPES], EnergyIntComp[NTYPES], EnergyTotComp[NTYPES], MomentumComp[NTYPES][4],
134 AngMomentumComp[NTYPES][4], CenterOfMassComp[NTYPES][4];
135 };
136 state_of_system SysState;
137
138 void compute_global_quantities_of_system(void);
139
140 public:
141 void timer_stop(enum timers counter)
142 {
143 if(TimerStack[TimerStackPos] != counter)
144 Terminate("Wrong use of timer_stop(), you must stop the timer started last");
145
147
148 if(TimerStackPos < 0)
149 Terminate("Do not stop the out CPU_MISC timer");
150 }
151
152 void timer_start(enum timers counter)
153 {
155
156 for(int itimer = 0; itimer <= TimerStackPos; itimer++)
157 if(counter == TimerStack[itimer])
158 Terminate("Try to start timer %d, but it is already running.\n", counter);
159
161 {
162 Terminate("Run out of timer stack space, increase TIMER_STACK_DEPTH");
163 }
164 else
165 TimerStack[TimerStackPos] = counter;
166 }
167};
168
169#include "../data/simparticles.h"
170
171#define TIMER_START_INTERNAL(counter) \
172 { \
173 Logs.CPU_Step[Logs.TimerStack[Logs.TimerStackPos]] += Logs.measure_time(); \
174 for(int itimer = 0; itimer <= Logs.TimerStackPos; itimer++) \
175 if(logs::counter == Logs.TimerStack[itimer]) \
176 { \
177 Terminate("Try to start timer %d, but it is already running.\n", logs::counter); \
178 }; \
179 if(++Logs.TimerStackPos >= TIMER_STACK_DEPTH) \
180 { \
181 Terminate("Run out of timer stack space, increase TIMER_STACK_DEPTH"); \
182 } \
183 else \
184 { \
185 Logs.TimerStack[Logs.TimerStackPos] = logs::counter; \
186 } \
187 }
188
197#define TIMER_START(counter) TIMER_START_INTERNAL(counter)
198
199#define TIMER_STOP_INTERNAL(counter) \
200 { \
201 if(Logs.TimerStack[Logs.TimerStackPos] != logs::counter) \
202 { \
203 Terminate("Wrong use of TIMER_STOP, you must stop the timer started last"); \
204 } \
205 Logs.CPU_Step[Logs.TimerStack[Logs.TimerStackPos--]] += Logs.measure_time(); \
206 if(Logs.TimerStackPos < 0) \
207 { \
208 Terminate("Do not stop the out CPU_MISC timer"); \
209 } \
210 }
211
220#define TIMER_STOP(counter) TIMER_STOP_INTERNAL(counter)
221
231#define TIMER_STOPSTART(stop, start) \
232 { \
233 TIMER_STOP_INTERNAL(stop); \
234 TIMER_START_INTERNAL(start); \
235 }
236
243#define TIMER_ADD(counter, amount) Logs.CPU_Step[counter] += (amount);
244
250#define TIMER_DIFF(counter) (Logs.CPU_Step[logs::counter] - Logs.CPU_Step_Stored[logs::counter])
251
257#define TIMER_STORE memcpy(Logs.CPU_Step_Stored, Logs.CPU_Step, sizeof(Logs.CPU_Step));
258
259extern logs Logs;
260
261#endif
Definition: logs.h:28
void timer_stop(enum timers counter)
Definition: logs.h:141
int flush_everything(void)
Definition: logs.cc:129
void block_checksum(void *base, size_t bytes, int res[4])
void init_cpu_log(simparticles *Sp_ptr)
Definition: logs.cc:296
timer_d Timer_data[CPU_LAST+1]
Definition: logs.h:113
void write_cpu_log(void)
Write the FdBalance and FdCPU files.
Definition: logs.cc:330
double CPUThisRun
Definition: logs.h:43
FILE * FdHydro
Definition: logs.h:49
void open_logfiles(void)
Open files for logging.
Definition: logs.cc:35
double CPU_Step[CPU_LAST]
Definition: logs.h:115
logs()
Definition: logs.h:30
void print_particle_info_from_ID(MyIDType ID)
simparticles * Sp
Definition: logs.h:41
double CPU_Sum[CPU_LAST]
Definition: logs.h:117
double CPU_Step_Stored[CPU_LAST]
Definition: logs.h:116
double measure_time(void)
Definition: logs.cc:458
FILE * FdEnergy
Definition: logs.h:46
FILE * FdTimebin
Definition: logs.h:51
void output_log_messages(void)
Write the FdInfo and FdTimeBin files.
Definition: logs.cc:175
double timediff(double t0, double t1)
Definition: logs.cc:488
int TimerStackPos
Definition: logs.h:120
FILE * FdTimings
Definition: logs.h:47
void calc_memory_checksum(const char *msg, void *base, size_t bytes)
void compute_statistics(void)
Computes new global statistics if needed (done by energy_statistics())
Definition: logs.cc:501
void print_particle_info(int i)
void log_debug_md5(const char *msg)
enum timers TimerStack[TIMER_STACK_DEPTH]
Definition: logs.h:119
timers
Definition: logs.h:91
@ CPU_NONE
Definition: logs.h:92
@ CPU_ROOT
Definition: logs.h:93
FILE * FdCPUCSV
Definition: logs.h:55
double second(void)
Definition: logs.cc:471
FILE * FdDomain
Definition: logs.h:52
FILE * FdCPU
Definition: logs.h:53
FILE * FdInfo
Definition: logs.h:45
void compute_total_momentum(void)
FILE * FdDensity
Definition: logs.h:48
void timer_start(enum timers counter)
Definition: logs.h:152
FILE * FdBalance
Definition: logs.h:50
#define NTYPES
Definition: constants.h:308
unsigned int MyIDType
Definition: dtypes.h:68
logs Logs
Definition: main.cc:43
#define TIMER_STACK_DEPTH
Definition: logs.h:22
#define Terminate(...)
Definition: macros.h:15
struct containing the information of a CPU timer
Definition: logs.h:105
int parent
Definition: logs.h:106
char symb
Definition: logs.h:109
char symbImbal
Definition: logs.h:110
char shortname[30]
Definition: logs.h:107
char depth
Definition: logs.h:111
char longname[30]
Definition: logs.h:108