milupHPC documentation
  • include
  • utils
h5profiler.h
Go to the documentation of this file.
1
11#ifndef MILUPHPC_H5PROFILER_H
12#define MILUPHPC_H5PROFILER_H
13
14
15#include <string>
16#include <unordered_map>
17#include <vector>
18
19#include <mpi.h>
20#include <highfive/H5File.hpp>
21#include <highfive/H5DataSet.hpp>
22#include <highfive/H5DataSpace.hpp>
23
24#include "logger.h"
25
27namespace ProfilerIds {
28
29 const char* const numParticles { "/general/numParticles" };
30 const char* const numParticlesLocal { "/general/numParticlesLocal" };
31 const char* const ranges { "/general/ranges" };
32
34 namespace SendLengths {
35 const char* const gravityParticles { "/sending/gravityParticles" };
36 const char* const gravityPseudoParticles { "/sending/gravityPseudoParticles" };
37 const char* const sph { "/sending/sph" };
38 };
39
41 namespace ReceiveLengths {
42 const char* const gravityParticles { "/receiving/gravityParticles" };
43 const char* const gravityPseudoParticles { "/receiving/gravityPseudoParticles" };
44 const char* const sph { "/receiving/sph" };
45 };
46
48 namespace Time {
49
50 const char *const rhs { "/time/rhs" };
51 const char *const rhsElapsed { "/time/rhsElapsed" };
52 const char *const loadBalancing { "/time/loadBalancing" };
53 const char *const reset { "/time/reset" };
54 const char *const removeParticles { "/time/removeParticles" };
55 const char *const boundingBox { "/time/boundingBox" };
56 const char *const assignParticles { "/time/assignParticles" };
57 const char *const tree { "/time/tree" };
58 const char *const pseudoParticle { "/time/pseudoParticle"};
59 const char *const gravity { "/time/gravity" };
60 const char *const sph { "/time/sph" };
61 const char *const integrate { "/time/integrate" };
62 const char *const IO { "/time/IO" };
63
64 namespace Reset {
65
66 }
67
68 namespace BoundingBox {
69
70 }
71
72 namespace AssignParticles {
73
74 }
75
76 namespace Tree {
77 const char *const createDomain { "/time/tree_createDomainList" };
78 const char *const tree { "/time/tree_buildTree" };
79 const char *const buildDomain { "/time/tree_buildDomainTree" };
80 }
81
82 namespace PseudoParticles {
83
84 }
85
86 namespace Gravity {
87 const char *const compTheta { "/time/gravity_compTheta" };
88 const char *const symbolicForce { "/time/gravity_symbolicForce" };
89 const char *const sending { "/time/gravity_gravitySendingParticles" };
90 const char *const insertReceivedPseudoParticles { "/time/gravity_insertReceivedPseudoParticles" };
91 const char *const insertReceivedParticles { "/time/gravity_insertReceivedParticles" };
92 const char *const force { "/time/gravity_force" };
93 const char *const repairTree { "/time/gravity_repairTree" };
94 }
95
96 namespace SPH {
97 const char *const compTheta { "/time/sph_compTheta" };
98 const char *const determineSearchRadii { "time/sph_determineSearchRadii" };
99 const char *const symbolicForce { "/time/sph_symbolicForce" };
100 const char *const sending { "/time/sph_sendingParticles" };
101 const char *const insertReceivedParticles { "/time/sph_insertReceivedParticles" };
102 const char *const fixedRadiusNN { "/time/sph_fixedRadiusNN" };
103 const char *const density { "/time/sph_density" };
104 const char *const soundSpeed { "/time/sph_soundSpeed" };
105 const char *const pressure { "/time/sph_pressure" };
106 const char *const resend { "/time/sph_resendingParticles" };
107 const char *const internalForces { "/time/sph_internalForces" };
108 const char *const repairTree { "/time/sph_repairTree" };
109 }
110
111 }
112
113}
114
118class H5Profiler {
119public:
120
130 static H5Profiler& getInstance(const std::string& outfile = ""){
131 static H5Profiler instance_(outfile);
132 return instance_;
133 }
134
135 // deleting methods we don't want for the singleton design pattern (c++11)
136 H5Profiler(H5Profiler const&) = delete;
137 void operator=(H5Profiler const&) = delete;
138
144 void const setStep(const int& _step) { step = _step; }
150 void const setRank(const int& _myRank) { myRank = _myRank; }
156 void const setNumProcs(const int& _numProcs) { numProcs = _numProcs; }
160 void const disableWrite() { disabled = true; }
164 void const enableWrite() { disabled = false; }
165
166 int currentMaxLength = 0;
167
168 /*void createTimeDataSet(const std::string& path, int steps);
169 void time(const std::string &path);
170 void timePause(const std::string &path);
171 void time2file(const std::string &path, int myRank, bool onlyWrite=false);*/
172
173 // TEMPLATE FUNCTIONS
174
175 // track single values
184 template<typename T>
185 void createValueDataSet(const std::string& path, int steps, std::size_t maxSteps=HighFive::DataSpace::UNLIMITED){
186 HighFive::DataSetCreateProps props;
187 props.add(HighFive::Chunking(std::vector<hsize_t>{1, 1}));
188 dataSets[path] = h5file.createDataSet<T>(path, HighFive::DataSpace({std::size_t(steps), std::size_t(numProcs)},
189 {maxSteps, std::size_t(numProcs)}), props);
190 totalSteps[path] = steps;
191 currentSteps[path] = 0;
192 }
193
201 template<typename T>
202 void value2file(const std::string& path, T value) {
203
204 if (!disabled) {
205 if (currentSteps[path] >= totalSteps[path]) {
206 totalSteps[path] += 1;
207 //Logger(INFO) << "resizing: " << totalSteps[path];
208 dataSets[path].resize({std::size_t(totalSteps[path]), std::size_t(numProcs)});
209 }
210 dataSets[path].select({std::size_t(currentSteps[path]), std::size_t(myRank)}, {1, 1}).write(value);
211 }
212 currentSteps[path] += 1;
213 }
214
215 // track vector values
225 template<typename T>
226 void createVectorDataSet(const std::string& path, int steps, std::size_t size,
227 std::size_t maxSteps=HighFive::DataSpace::UNLIMITED){
228 HighFive::DataSetCreateProps props;
229 props.add(HighFive::Chunking(std::vector<hsize_t>{1, 1, size}));
230 dataSets[path] = h5file.createDataSet<T>(path, HighFive::DataSpace({std::size_t(steps),
231 std::size_t(numProcs), size},
232 {maxSteps, std::size_t(numProcs), size}),
233 props);
234 vectorSizes[path] = size;
235 currentSteps[path] = 0;
236 }
237
245 template<typename T>
246 void vector2file(const std::string& path, std::vector<T> data){
247 if (!disabled) {
248 if (currentSteps[path] >= totalSteps[path]) {
249 totalSteps[path] += 1;
250 //Logger(INFO) << "resizing: " << totalSteps[path];
251 dataSets[path].resize({std::size_t(totalSteps[path]), std::size_t(numProcs), vectorSizes[path]});
252 }
253 dataSets[path].select({std::size_t(currentSteps[path]), std::size_t(myRank), 0},
254 {1, 1, vectorSizes[path]}).write(data);
255 }
256 currentSteps[path] += 1;
257 }
258
266 template<typename T>
267 void vector2file(const std::string& path, T *data) {
268 if (!disabled) {
269 std::vector<T> dataVector;
270 for (int i=0; i<vectorSizes[path]; i++) {
271 dataVector.push_back(data[i]);
272 }
273 vector2file(path, dataVector);
274 }
275 }
276
277private:
283 H5Profiler(const std::string& outfile);
284
285 // basic containers for meta information
286 HighFive::File h5file;
287 std::unordered_map<std::string, HighFive::DataSet> dataSets;
288 int numProcs;
289 int step;
290 int myRank;
291 bool disabled;
292
293 // timing variables
294 std::unordered_map<std::string, double> timeStart;
295 std::unordered_map<std::string, double> timeElapsed;
296
297 std::unordered_map<std::string, int> currentSteps;
298 std::unordered_map<std::string, int> totalSteps;
299 // vector sizes
300 std::unordered_map<std::string, std::size_t> vectorSizes;
301
302};
303
304
305#endif //MILUPHPC_H5PROFILER_H
H5Profiler
Singleton class for HDF5 profiler.
Definition: h5profiler.h:118
H5Profiler::operator=
void operator=(H5Profiler const &)=delete
H5Profiler::disabled
bool disabled
Definition: h5profiler.h:291
H5Profiler::H5Profiler
H5Profiler(H5Profiler const &)=delete
H5Profiler::vectorSizes
std::unordered_map< std::string, std::size_t > vectorSizes
Definition: h5profiler.h:300
H5Profiler::getInstance
static H5Profiler & getInstance(const std::string &outfile="")
Constructor/Instance getter for HDF5 profiler.
Definition: h5profiler.h:130
H5Profiler::vector2file
void vector2file(const std::string &path, T *data)
Definition: h5profiler.h:267
H5Profiler::currentMaxLength
int currentMaxLength
Definition: h5profiler.h:166
H5Profiler::totalSteps
std::unordered_map< std::string, int > totalSteps
Definition: h5profiler.h:298
H5Profiler::setNumProcs
void const setNumProcs(const int &_numProcs)
Set number of MPI processes.
Definition: h5profiler.h:156
H5Profiler::vector2file
void vector2file(const std::string &path, std::vector< T > data)
Definition: h5profiler.h:246
H5Profiler::createVectorDataSet
void createVectorDataSet(const std::string &path, int steps, std::size_t size, std::size_t maxSteps=HighFive::DataSpace::UNLIMITED)
Track vector values (per MPI rank).
Definition: h5profiler.h:226
H5Profiler::createValueDataSet
void createValueDataSet(const std::string &path, int steps, std::size_t maxSteps=HighFive::DataSpace::UNLIMITED)
Track single value (per MPI rank).
Definition: h5profiler.h:185
H5Profiler::numProcs
int numProcs
Definition: h5profiler.h:288
H5Profiler::myRank
int myRank
Definition: h5profiler.h:290
H5Profiler::step
int step
Definition: h5profiler.h:289
H5Profiler::h5file
HighFive::File h5file
Definition: h5profiler.h:286
H5Profiler::setStep
void const setStep(const int &_step)
Set current step of profiler.
Definition: h5profiler.h:144
H5Profiler::setRank
void const setRank(const int &_myRank)
Set MPI rank.
Definition: h5profiler.h:150
H5Profiler::timeStart
std::unordered_map< std::string, double > timeStart
Definition: h5profiler.h:294
H5Profiler::dataSets
std::unordered_map< std::string, HighFive::DataSet > dataSets
Definition: h5profiler.h:287
H5Profiler::currentSteps
std::unordered_map< std::string, int > currentSteps
Definition: h5profiler.h:297
H5Profiler::disableWrite
void const disableWrite()
Disable write to output file.
Definition: h5profiler.h:160
H5Profiler::timeElapsed
std::unordered_map< std::string, double > timeElapsed
Definition: h5profiler.h:295
H5Profiler::value2file
void value2file(const std::string &path, T value)
Write value to single value data set.
Definition: h5profiler.h:202
H5Profiler::enableWrite
void const enableWrite()
Enable write to output file.
Definition: h5profiler.h:164
Tree
Tree class.
Definition: tree.cuh:140
density
Definition: density.cuh:19
pressure
Definition: pressure.cuh:20
logger.h
C++ style logger.
Gravity
Gravity related kernels/functions.
Definition: gravity.cuh:23
ProfilerIds::ReceiveLengths::gravityParticles
const char *const gravityParticles
Definition: h5profiler.h:42
ProfilerIds::ReceiveLengths::gravityPseudoParticles
const char *const gravityPseudoParticles
Definition: h5profiler.h:43
ProfilerIds::ReceiveLengths::sph
const char *const sph
Definition: h5profiler.h:44
ProfilerIds::SendLengths::gravityPseudoParticles
const char *const gravityPseudoParticles
Definition: h5profiler.h:36
ProfilerIds::SendLengths::gravityParticles
const char *const gravityParticles
Definition: h5profiler.h:35
ProfilerIds::SendLengths::sph
const char *const sph
Definition: h5profiler.h:37
ProfilerIds::Time::Gravity::compTheta
const char *const compTheta
Definition: h5profiler.h:87
ProfilerIds::Time::Gravity::force
const char *const force
Definition: h5profiler.h:92
ProfilerIds::Time::Gravity::repairTree
const char *const repairTree
Definition: h5profiler.h:93
ProfilerIds::Time::Gravity::symbolicForce
const char *const symbolicForce
Definition: h5profiler.h:88
ProfilerIds::Time::Gravity::insertReceivedParticles
const char *const insertReceivedParticles
Definition: h5profiler.h:91
ProfilerIds::Time::Gravity::insertReceivedPseudoParticles
const char *const insertReceivedPseudoParticles
Definition: h5profiler.h:90
ProfilerIds::Time::Gravity::sending
const char *const sending
Definition: h5profiler.h:89
ProfilerIds::Time::SPH::insertReceivedParticles
const char *const insertReceivedParticles
Definition: h5profiler.h:101
ProfilerIds::Time::SPH::internalForces
const char *const internalForces
Definition: h5profiler.h:107
ProfilerIds::Time::SPH::soundSpeed
const char *const soundSpeed
Definition: h5profiler.h:104
ProfilerIds::Time::SPH::symbolicForce
const char *const symbolicForce
Definition: h5profiler.h:99
ProfilerIds::Time::SPH::sending
const char *const sending
Definition: h5profiler.h:100
ProfilerIds::Time::SPH::fixedRadiusNN
const char *const fixedRadiusNN
Definition: h5profiler.h:102
ProfilerIds::Time::SPH::determineSearchRadii
const char *const determineSearchRadii
Definition: h5profiler.h:98
ProfilerIds::Time::SPH::repairTree
const char *const repairTree
Definition: h5profiler.h:108
ProfilerIds::Time::SPH::compTheta
const char *const compTheta
Definition: h5profiler.h:97
ProfilerIds::Time::SPH::resend
const char *const resend
Definition: h5profiler.h:106
ProfilerIds::Time::Tree::tree
const char *const tree
Definition: h5profiler.h:78
ProfilerIds::Time::Tree::buildDomain
const char *const buildDomain
Definition: h5profiler.h:79
ProfilerIds::Time::Tree::createDomain
const char *const createDomain
Definition: h5profiler.h:77
ProfilerIds::Time::pseudoParticle
const char *const pseudoParticle
Definition: h5profiler.h:58
ProfilerIds::Time::gravity
const char *const gravity
Definition: h5profiler.h:59
ProfilerIds::Time::IO
const char *const IO
Definition: h5profiler.h:62
ProfilerIds::Time::removeParticles
const char *const removeParticles
Definition: h5profiler.h:54
ProfilerIds::Time::rhs
const char *const rhs
Definition: h5profiler.h:50
ProfilerIds::Time::reset
const char *const reset
Definition: h5profiler.h:53
ProfilerIds::Time::tree
const char *const tree
Definition: h5profiler.h:57
ProfilerIds::Time::loadBalancing
const char *const loadBalancing
Definition: h5profiler.h:52
ProfilerIds::Time::assignParticles
const char *const assignParticles
Definition: h5profiler.h:56
ProfilerIds::Time::boundingBox
const char *const boundingBox
Definition: h5profiler.h:55
ProfilerIds::Time::integrate
const char *const integrate
Definition: h5profiler.h:61
ProfilerIds::Time::sph
const char *const sph
Definition: h5profiler.h:60
ProfilerIds::Time::rhsElapsed
const char *const rhsElapsed
Definition: h5profiler.h:51
ProfilerIds
profiler identifiers
Definition: h5profiler.h:27
ProfilerIds::numParticlesLocal
const char *const numParticlesLocal
Definition: h5profiler.h:30
ProfilerIds::ranges
const char *const ranges
Definition: h5profiler.h:31
ProfilerIds::numParticles
const char *const numParticles
Definition: h5profiler.h:29
SPH
SPH related functions and kernels.
Definition: density.cuh:23

milupHPC - include/utils/h5profiler.h Source File
Generated on Wed Aug 31 2022 12:16:52 by Doxygen 1.9.3