Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_BLProfiler.H
Go to the documentation of this file.
1#ifndef BL_PROFILER_H_
2#define BL_PROFILER_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Extension.H>
6
7#define BL_PROFILE_PASTE2(x, y) x##y
8#define BL_PROFILE_PASTE(x, y) BL_PROFILE_PASTE2(x, y)
9
10#ifdef BL_PROFILING
11
12#include <AMReX_REAL.H>
13#include <AMReX_Array.H>
14#include <AMReX_Vector.H>
15#ifndef BL_AMRPROF
16#include <AMReX_IntVect.H>
17#include <AMReX_Box.H>
18#endif
19
20#include <list>
21#include <map>
22#include <iosfwd>
23#include <string>
24#include <stack>
25#include <set>
26#include <typeinfo>
27#include <utility>
28
29namespace amrex {
30
31class BLProfiler
32{
33 public:
34 struct ProfStats {
35 ProfStats() : nCalls(0), totalTime(0.0), minTime(0.0),
36 maxTime(0.0), avgTime(0.0), variance(0.0) { }
37 Long nCalls;
38 Real totalTime, minTime, maxTime, avgTime, variance;
39 };
40
41 struct CallStats {
42 CallStats() : callStackDepth(-2), csFNameNumber(-2),
43 nCSCalls(0), totalTime(0.0),
44 stackTime(0.0), callTime(0.0) { }
45 CallStats(int depth, int fnamenumber) : callStackDepth(depth),
46 csFNameNumber(fnamenumber),
47 nCSCalls(0), totalTime(0.0),
48 stackTime(0.0), callTime(0.0) { }
49 CallStats(int depth, int fnamenumber, int ncalls, Real totaltime,
50 Real stacktime, Real calltime) : callStackDepth(depth),
51 csFNameNumber(fnamenumber),
52 nCSCalls(ncalls), totalTime(totaltime),
53 stackTime(stacktime), callTime(calltime) { }
54 int callStackDepth, csFNameNumber;
55 Long nCSCalls;
56 Real totalTime, stackTime, callTime;
57
58 static int cstatsVersion;
59 static Real minCallTime, maxCallTime;
60 };
61
62 struct CallStatsStack {
63 CallStatsStack() : bFlushed(false), index(-1) { }
64 CallStatsStack(int idx) : bFlushed(false), index(idx) { }
65 bool bFlushed;
66 int index;
67 };
68
69 struct CallStatsPatch {
70 CallStatsPatch() : seekPos(-1), callStats(), fileName("") { }
71 CallStatsPatch(Long spos, const CallStats &cs, const std::string &fname)
72 : seekPos(spos), callStats(cs), fileName(fname) { }
73 Long seekPos;
74 CallStats callStats;
75 std::string fileName;
76 };
77
78 struct RStartStop {
79 RStartStop()
80 : rssTime(0.0), rssRNumber(-2), rssStart(false) { }
81 RStartStop(Real t, int r, bool s)
82 : rssTime(t), rssRNumber(r), rssStart(s) { }
83 Real rssTime;
84 int rssRNumber;
85 int rssStart; // Used as a bool. Set to int to remove padding in this object (13 bytes -> 16 bytes).
86 // Eliminates a valgrind complaint when writing these objects to files.
87 };
88
89 enum CommFuncType {
90 InvalidCFT = 0, // 0
91 AllReduceT, // 1
92 AllReduceR, // 2
93 AllReduceL, // 3
94 AllReduceI, // 4
95 AsendTsii, // 5
96 AsendTsiiM, // 6
97 AsendvTii, // 7
98 SendTsii, // 8
99 SendvTii, // 9
100 ArecvTsii, // 10
101 ArecvTsiiM, // 11
102 ArecvTii, // 12
103 ArecvvTii, // 13
104 RecvTsii, // 14
105 RecvvTii, // 15
106 ReduceT, // 16
107 ReduceR, // 17
108 ReduceL, // 18
109 ReduceI, // 19
110 BCastTsi, // 20
111 GatherTsT1Si, // 21
112 GatherTi, // 22
113 GatherRiRi, // 23
114 ScatterTsT1si, // 24
115 Barrier, // 25
116 Waitsome, // 26
117 NameTag, // 27
118 AllCFTypes, // 28
119 NoCFTypes, // 29
120 IOStart, // 30
121 IOEnd, // 31
122 TagWrap, // 32
123 Allgather, // 33
124 Alltoall, // 34
125 Alltoallv, // 35
126 Gatherv, // 36
127 Get_count, // 37
128 Iprobe, // 38
129 Test, // 39
130 Wait, // 40
131 Waitall, // 41
132 Waitany, // 42
133 NUMBER_OF_CFTS // 43
134 };
135
136 struct CommStats {
137 CommStats() : cfType(InvalidCFT), size(-2), commpid(-2), tag(-2),
138 timeStamp(-2.0) { }
139 CommStats(CommFuncType cft, int sz, int cpid, int tg, Real ts)
140 : cfType(cft), size(sz), commpid(cpid), tag(tg),
141 timeStamp(ts) { }
142
143 static std::string CFTToString(CommFuncType cft);
144 static CommFuncType StringToCFT(const std::string &s);
145 static void Filter(CommFuncType cft);
146 static void UnFilter(CommFuncType cft);
147
148 static std::map<std::string, CommFuncType> cftNames;
149 static std::set<CommFuncType> cftExclude;
150 static int barrierNumber;
151 static int reductionNumber;
152 static int tagWrapNumber;
153 static int tagMin;
154 static int tagMax;
155 static Vector<std::pair<std::string,int> > barrierNames; // [name, seek]
156 static Vector<std::pair<int,int> > nameTags; // [nameindex, seek]
157 static Vector<std::string> nameTagNames; // [name]
158 static Vector<int> tagWraps; // [index]
159 static int csVersion;
160
161 CommFuncType cfType;
162 int size, commpid, tag;
163 Real timeStamp;
164 };
165
166 static std::map<std::string, BLProfiler *> mFortProfs; // [fname, fortfunc]
167 static Vector<std::string> mFortProfsErrors; // [error string]
168 static Vector<BLProfiler *> mFortProfsInt; // [fortfuncindex]
169 static Vector<std::string> mFortProfsIntNames; // [fortfuncindex name]
170
171 explicit BLProfiler(const std::string &funcname);
172 BLProfiler(const std::string &funcname, bool bstart);
173
174 ~BLProfiler();
175
176 static void Initialize();
177 static void InitParams();
178 static void Finalize(bool bFlushing = false, bool memCheck = false);
179
180 static void WriteBaseProfile(bool bFlushing = false, bool memCheck = false);
181 static void WriteCallTrace(bool bFlushing = false, bool memCheck = false);
182 static void WriteCommStats(bool bFlushing = false, bool memCheck = false);
183 static void WriteFortProfErrors();
184
185 static void AddCommStat(const CommFuncType cft, const int size,
186 const int pid, const int tag);
187 static void AddWait(const CommFuncType cft, const MPI_Request &reqs,
188 const MPI_Status &status, const bool bc);
189 static void AddWaitsome(const CommFuncType cft, const Vector<MPI_Request> &reqs,
190 const int completed, const Vector<MPI_Status> &status,
191 const bool bc);
192 static void AddBarrier(const std::string &message, const bool bc);
193 static void AddNameTag(const std::string &name);
194 static void AddAllReduce(const CommFuncType cft, const int size, const bool bc);
195 static void TagRange(const int tagmin, const int tagmax);
196 static void AddTagWrap();
197#ifndef BL_AMRPROF
198 static void InitAMR(const int flev, const int mlev, const Vector<IntVect> &rr,
199 const Vector<Box> pd);
200#endif
201
202 void start();
203 void stop();
204 void PStart();
205 void PStop();
206 static void ChangeFortIntName(const std::string &fname, int intname);
207
208 static void InitParams(const Real ptl, const bool writeall,
209 const bool writefabs);
210 static void AddStep(const int snum);
211 static Real GetRunTime() { return calcRunTime; }
212 static void SetRunTime(Real rtime) { calcRunTime = rtime; }
213
214 static void RegionStart(const std::string &rname);
215 static void RegionStop(const std::string &rname);
216
217 static inline int NoTag() { return -3; }
218 static inline int BeforeCall() { return -5; }
219 static inline int AfterCall() { return -7; }
220
221 static inline int ProcNumber() { return procNumber; }
222 static void SetBlProfDirName(const std::string &name) { blProfDirName = name; }
223 static void SetNoOutput() { bNoOutput = true; }
224
225 static int GetBaseFlushSize() { return baseFlushSize; }
226 static void SetBaseFlushSize(int fsize) { baseFlushSize = fsize; }
227 static int GetCSFlushSize() { return csFlushSize; }
228 static void SetCSFlushSize(int fsize) { csFlushSize = fsize; }
229 static int GetTraceFlushSize() { return traceFlushSize; }
230 static void SetTraceFlushSize(int fsize) { traceFlushSize = fsize; }
231
232 static int GetFlushInterval() { return flushInterval; }
233 static void SetFlushInterval(int finterval) { flushInterval = finterval; }
234 static Real GetFlushTimeInterval() { return flushTimeInterval; }
235 static void SetFlushTimeInterval(Real ftinterval) { flushTimeInterval = ftinterval; }
236
237 static void SetNFiles(int nfiles) { nProfFiles = nfiles; }
238 static int GetNFiles() { return nProfFiles; }
239
240 private:
241 Real bltstart, bltelapsed;
242 std::string fname;
243 bool bRunning;
244
245 static bool bWriteAll, bWriteFabs, groupSets;
246 static bool bFirstCommWrite;
247 static bool bInitialized, bNoOutput;
248 static bool bFlushPrint;
249 static int currentStep, nProfFiles;
250 static int baseFlushSize, csFlushSize, traceFlushSize;
251 static int baseFlushCount, csFlushCount, traceFlushCount, flushInterval;
252 static int finestLevel, maxLevel;
253 static Real pctTimeLimit;
254 static Real calcRunTime;
255 static Real startTime;
256 static Real timerTime;
257 static Real flushTimeInterval;
258#ifndef BL_AMRPROF
259 static Vector<IntVect> refRatio;
260 static Vector<Box> probDomain;
261#endif
262 static std::stack<Real> nestedTimeStack;
263 static std::map<int, Real> mStepMap;
264 static std::map<std::string, ProfStats> mProfStats;
265 static Vector<CommStats> vCommStats;
266 static std::string procName;
267 static int procNumber;
268 static bool blProfDirCreated;
269 static std::string blProfDirName;
270 static int BLProfVersion;
271
272 static bool OnExcludeList(CommFuncType cft);
273 static int NameTagNameIndex(const std::string &name);
274
275 static std::map<std::string, int> mFNameNumbers;
276 static Vector<CallStats> vCallTrace;
277
279 static std::map<std::string, int> mRegionNameNumbers;
280 static int inNRegions;
281 static Vector<RStartStop> rStartStop;
282 static const std::string noRegionName;
283
284 static bool bFirstTraceWrite;
285
286 static Vector<CallStatsStack> callIndexStack;
287 static Vector<CallStatsPatch> callIndexPatch;
288
289#ifdef BL_TRACE_PROFILING
290 static int callStackDepth;
291 static int prevCallStackDepth;
292
293 public:
294 using RIpair = std::pair<Real, int>;
295 struct fTTComp {
296 bool operator()(const RIpair &lhs, const RIpair &rhs) const {
297 return lhs.first > rhs.first;
298 }
299 };
300#endif
301
302};
303
304
305class BLProfileRegion
306{
307public:
308 BLProfileRegion (const std::string& a_regname)
309 : regname(a_regname)
310 {
311 BLProfiler::RegionStart(regname);
312 }
313
314 ~BLProfileRegion () { BLProfiler::RegionStop(regname); }
315private:
316 std::string regname;
317};
318
319
320namespace BLProfilerUtils {
321 void WriteHeader(std::ostream &os, const int colWidth,
322 const Real maxlen, const bool bwriteavg);
323
324 void WriteRow(std::ostream &os, const std::string &fname,
325 const BLProfiler::ProfStats &pstats, const Real percent,
326 const int colWidth, const Real maxlen,
327 const bool bwriteavg);
328
329 void WriteStats(std::ostream &os,
330 const std::map<std::string, BLProfiler::ProfStats> &mpStats,
331 const std::map<std::string, int> &fnameNumbers,
332 const Vector<BLProfiler::CallStats> &callTraces,
333 bool bwriteavg = false, bool bwriteinclusivetimes = false);
334}
335
336
337std::ostream &operator<< (std::ostream &os, const BLProfiler::CommStats &cs);
338
339
340inline std::string BLProfiler::CommStats::CFTToString(CommFuncType cft) {
341 switch(cft) {
342 case InvalidCFT: return "InvalidCFT";
343 case AllReduceT: return "AllReduceT";
344 case AllReduceR: return "AllReduceR";
345 case AllReduceL: return "AllReduceL";
346 case AllReduceI: return "AllReduceI";
347 case AsendTsii: return "AsendTsii";
348 case AsendTsiiM: return "AsendTsiiM";
349 case AsendvTii: return "AsendvTii";
350 case SendTsii: return "SendTsii";
351 case SendvTii: return "SendvTii";
352 case ArecvTsii: return "ArecvTsii";
353 case ArecvTsiiM: return "ArecvTsiiM";
354 case ArecvTii: return "ArecvTii";
355 case ArecvvTii: return "ArecvvTii";
356 case RecvTsii: return "RecvTsii";
357 case RecvvTii: return "RecvvTii";
358 case ReduceT: return "ReduceT";
359 case ReduceR: return "ReduceR";
360 case ReduceL: return "ReduceL";
361 case ReduceI: return "ReduceI";
362 case BCastTsi: return "BCastTsi";
363 case GatherTsT1Si: return "GatherTsT1Si";
364 case GatherTi: return "GatherTi";
365 case GatherRiRi: return "GatherRiRi";
366 case ScatterTsT1si: return "ScatterTsT1si";
367 case Barrier: return "Barrier";
368 case Waitsome: return "Waitsome";
369 case NameTag: return "NameTag";
370 case AllCFTypes: return "AllCFTypes";
371 case NoCFTypes: return "NoCFTypes";
372 case IOStart: return "IOStart";
373 case IOEnd: return "IOEnd";
374 case TagWrap: return "TagWrap";
375 case Allgather: return "Allgather";
376 case Alltoall: return "Alltoall";
377 case Alltoallv: return "Alltoallv";
378 case Gatherv: return "Gatherv";
379 case Get_count: return "Get_count";
380 case Iprobe: return "Iprobe";
381 case Test: return "Test";
382 case Wait: return "Wait";
383 case Waitall: return "Waitall";
384 case Waitany: return "Waitany";
385 case NUMBER_OF_CFTS: return "NUMBER_OF_CFTS";
386 }
387 return "*** Error: Bad CommFuncType.";
388}
389
390}
391
392#define BL_PROFILE_INITIALIZE() amrex::BLProfiler::Initialize();
393#define BL_PROFILE_INITPARAMS() amrex::BLProfiler::InitParams(); amrex::BLProfileSync::InitParams()
394#define BL_PROFILE_FINALIZE() amrex::BLProfiler::Finalize();
395
396#define BL_TINY_PROFILE_INITIALIZE()
397#define BL_TINY_PROFILE_FINALIZE()
398
399#define BL_TINY_PROFILE_MEMORYINITIALIZE()
400#define BL_TINY_PROFILE_MEMORYFINALIZE()
401
402#define BL_PROFILE(fname) amrex::BLProfiler bl_profiler_((fname));
403#define BL_PROFILE_T(fname, T) amrex::BLProfiler bl_profiler_((std::string(fname) + typeid(T).name()));
404#ifdef BL_PROFILING_SPECIAL
405#define BL_PROFILE_S(fname) amrex::BLProfiler bl_profiler_((fname));
406#define BL_PROFILE_T_S(fname, T) amrex::BLProfiler bl_profiler_((std::string(fname) + typeid(T).name()));
407#else
408#define BL_PROFILE_S(fname)
409#define BL_PROFILE_T_S(fname, T)
410#endif
411
412#define BL_PROFILE_VAR(fname, vname) amrex::BLProfiler bl_profiler_##vname((fname));
413#define BL_PROFILE_VAR_NS(fname, vname) amrex::BLProfiler bl_profiler_##vname(fname, false);
414#define BL_PROFILE_VAR_START(vname) bl_profiler_##vname.start();
415#define BL_PROFILE_VAR_STOP(vname) bl_profiler_##vname.stop();
416
417#define BL_PROFILE_INIT_PARAMS(ptl,wall,wfabs) \
418 amrex::BLProfiler::InitParams(ptl,wall, wfabs);
419#define BL_PROFILE_ADD_STEP(snum) amrex::BLProfiler::AddStep(snum);
420#define BL_PROFILE_SET_RUN_TIME(rtime) amrex::BLProfiler::SetRunTime(rtime);
421
422#define BL_PROFILE_REGION(rname) \
423 AMREX_WARNING_PUSH_COUNTER \
424 amrex::BLProfileRegion BL_PROFILE_PASTE(bl_profile_region_, __COUNTER__)((rname)); \
425 AMREX_WARNING_POP
426
427#define BL_PROFILE_REGION_START(rname) amrex::BLProfiler::RegionStart(rname);
428#define BL_PROFILE_REGION_STOP(rname) amrex::BLProfiler::RegionStop(rname);
429
430// these combine regions with profile variables
431#define BL_PROFILE_REGION_VAR(fname, rvname) amrex::BLProfiler::RegionStart(fname); \
432 amrex::BLProfiler bl_profiler_##rvname((fname));
433#define BL_PROFILE_REGION_VAR_START(fname, rvname) amrex::BLProfiler::RegionStart(fname); \
434 bl_profiler_##rvname.start();
435#define BL_PROFILE_REGION_VAR_STOP(fname, rvname) bl_profiler_##rvname.stop(); \
436 amrex::BLProfiler::RegionStop(fname);
437
438#define BL_PROFILE_TINY_FLUSH()
439#define BL_PROFILE_FLUSH() { amrex::BLProfiler::Finalize(true); }
440
441#define BL_TRACE_PROFILE_FLUSH() { amrex::BLProfiler::WriteCallTrace(true, true); }
442#define BL_TRACE_PROFILE_SETFLUSHSIZE(fsize) { amrex::BLProfiler::SetTraceFlushSize(fsize); }
443
444#define BL_PROFILE_CHANGE_FORT_INT_NAME(fname, intname) { amrex::BLProfiler::ChangeFortIntName(fname, intname); }
445
446#ifdef BL_COMM_PROFILING
447
448#define BL_COMM_PROFILE(cft, size, pid, tag) { \
449 amrex::BLProfiler::AddCommStat(cft, size, pid, tag); \
450}
451#define BL_COMM_PROFILE_BARRIER(message, bc) { amrex::BLProfiler::AddBarrier(message, bc); }
452#define BL_COMM_PROFILE_ALLREDUCE(cft, size, bc) { amrex::BLProfiler::AddAllReduce(cft, size, bc); }
453#define BL_COMM_PROFILE_REDUCE(cft, size, pid) { \
454 amrex::BLProfiler::AddCommStat(cft, size, pid, amrex::BLProfiler::NoTag()); }
455#define BL_COMM_PROFILE_WAIT(cft, reqs, status, bc) { \
456 amrex::BLProfiler::AddWait(cft, reqs, status, bc); \
457}
458#define BL_COMM_PROFILE_WAITSOME(cft, reqs, completed, status, bc) { \
459 amrex::BLProfiler::AddWaitsome(cft, reqs, completed, status, bc); \
460}
461#define BL_COMM_PROFILE_NAMETAG(message) { amrex::BLProfiler::AddNameTag(message); }
462#define BL_COMM_PROFILE_FILTER(cft) { amrex::BLProfiler::CommStats::Filter(cft); }
463#define BL_COMM_PROFILE_UNFILTER(cft) { amrex::BLProfiler::CommStats::UnFilter(cft); }
464#define BL_COMM_PROFILE_FLUSH() { amrex::BLProfiler::WriteCommStats(true, true); }
465#define BL_COMM_PROFILE_SETFLUSHSIZE(fsize) { amrex::BLProfiler::SetCSFlushSize(fsize); }
466#define BL_COMM_PROFILE_TAGRANGE(tagmin, tagmax) { \
467 amrex::BLProfiler::TagRange(tagmin, tagmax); }
468#define BL_COMM_PROFILE_TAGWRAP() { amrex::BLProfiler::AddTagWrap(); }
469#define BL_COMM_PROFILE_INITAMR(flev, mlev, rr, pd) { \
470 amrex::BLProfiler::InitAMR(flev, mlev, rr, pd); \
471}
472
473#endif
474
475
476// --------------------------------------------
477#elif defined(AMREX_TINY_PROFILING)
478
479#include <AMReX.H>
480#include <AMReX_TinyProfiler.H>
481
482#define BL_PROFILE_INITIALIZE()
483#define BL_PROFILE_INITPARAMS()
484#define BL_PROFILE_FINALIZE()
485
486#define BL_TINY_PROFILE_INITIALIZE() amrex::TinyProfiler::Initialize(); amrex::BLProfileSync::InitParams()
487#define BL_TINY_PROFILE_FINALIZE() amrex::TinyProfiler::Finalize()
488
489#define BL_TINY_PROFILE_MEMORYINITIALIZE() amrex::TinyProfiler::MemoryInitialize()
490#define BL_TINY_PROFILE_MEMORYFINALIZE() amrex::TinyProfiler::MemoryFinalize()
491
492#define BL_PROFILE(fname) \
493 AMREX_WARNING_PUSH_COUNTER \
494 BL_PROFILE_IMPL(fname, __COUNTER__) \
495 AMREX_WARNING_POP
496#define BL_PROFILE_IMPL(funame, counter) amrex::TinyProfiler BL_PROFILE_PASTE(tiny_profiler_, counter)((funame)); \
497 amrex::ignore_unused(BL_PROFILE_PASTE(tiny_profiler_, counter));
498
499#define BL_PROFILE_T(a, T)
500#define BL_PROFILE_S(fname)
501#define BL_PROFILE_T_S(fname, T)
502
503#define BL_PROFILE_VAR(fname, vname) amrex::TinyProfiler tiny_profiler_##vname((fname))
504#define BL_PROFILE_VAR_NS(fname, vname) amrex::TinyProfiler tiny_profiler_##vname(fname, false)
505#define BL_PROFILE_VAR_START(vname) tiny_profiler_##vname.start()
506#define BL_PROFILE_VAR_STOP(vname) tiny_profiler_##vname.stop()
507#define BL_PROFILE_INIT_PARAMS(ptl,wall,wfabs)
508#define BL_PROFILE_ADD_STEP(snum)
509#define BL_PROFILE_SET_RUN_TIME(rtime)
510#define BL_PROFILE_REGION(rname) \
511 AMREX_WARNING_PUSH_COUNTER \
512 amrex::TinyProfileRegion BL_PROFILE_PASTE(tiny_profile_region_, __COUNTER__)((rname)); \
513 AMREX_WARNING_POP
514#define BL_PROFILE_REGION_START(rname)
515#define BL_PROFILE_REGION_STOP(rname)
516//#define BL_PROFILE_REGION_START(rname) amrex::TinyProfiler::StartRegion(rname)
517//#define BL_PROFILE_REGION_STOP(rname) amrex::TinyProfiler::StopRegion(rname)
518#define BL_PROFILE_REGION_VAR(fname, rvname)
519#define BL_PROFILE_REGION_VAR_START(fname, rvname)
520#define BL_PROFILE_REGION_VAR_STOP(fname, rvname)
521#define BL_PROFILE_TINY_FLUSH() amrex::TinyProfiler::Finalize(true); amrex::TinyProfiler::MemoryFinalize(true)
522#define BL_PROFILE_FLUSH()
523#define BL_TRACE_PROFILE_FLUSH()
524#define BL_TRACE_PROFILE_SETFLUSHSIZE(fsize)
525#define BL_PROFILE_CHANGE_FORT_INT_NAME(fname, intname)
526
527#else
528
529#include <string>
530#include <AMReX_REAL.H>
531
532namespace amrex {
533
535{
536 public:
537 explicit BLProfiler(const std::string &/*funcname*/) { }
538 static void Initialize() { }
539 static void InitParams() { }
540 static void Finalize() { }
541 static void WriteStats(std::ostream &/*os*/) { }
542 static void WriteCommStats() { }
543 void start() { }
544 void stop() { }
545 static void InitParams(const Real /*ptl*/, const bool /*writeall*/,
546 const bool /*writefabs*/) { }
547 static void AddStep(const int /*snum*/) { }
548};
549
550}
551
552#define BL_PROFILE_INITIALIZE()
553#define BL_PROFILE_INITPARAMS()
554#define BL_PROFILE_FINALIZE()
555
556#define BL_TINY_PROFILE_INITIALIZE()
557#define BL_TINY_PROFILE_FINALIZE()
558
559#define BL_TINY_PROFILE_MEMORYINITIALIZE()
560#define BL_TINY_PROFILE_MEMORYFINALIZE()
561
562#define BL_PROFILE(a)
563#define BL_PROFILE_T(a, T)
564#define BL_PROFILE_S(fname)
565#define BL_PROFILE_T_S(fname, T)
566#define BL_PROFILE_TIMER(var, a)
567#define BL_PROFILE_START(var)
568#define BL_PROFILE_STOP(var)
569#define BL_PROFILE_THIS_NAME()
570
571#define BL_PROFILE_VAR(fname, vname)
572#define BL_PROFILE_VAR_NS(fname, vname)
573#define BL_PROFILE_VAR_START(vname)
574#define BL_PROFILE_VAR_STOP(vname)
575#define BL_PROFILE_INIT_PARAMS(ptl,wall,wfabs)
576#define BL_PROFILE_ADD_STEP(snum)
577#define BL_PROFILE_SET_RUN_TIME(rtime)
578#define BL_PROFILE_REGION(rname)
579#define BL_PROFILE_REGION_START(rname)
580#define BL_PROFILE_REGION_STOP(rname)
581#define BL_PROFILE_REGION_VAR(fname, rvname)
582#define BL_PROFILE_REGION_VAR_START(fname, rvname)
583#define BL_PROFILE_REGION_VAR_STOP(fname, rvname)
584#define BL_PROFILE_TINY_FLUSH()
585#define BL_PROFILE_FLUSH()
586#define BL_TRACE_PROFILE_FLUSH()
587#define BL_TRACE_PROFILE_SETFLUSHSIZE(fsize)
588#define BL_PROFILE_CHANGE_FORT_INT_NAME(fname, intname)
589
590#endif
591
592// ============================================================
593// If applicable, turn off comm profiling
594// ============================================================
595
596#ifndef BL_COMM_PROFILING
597
598#define BL_COMM_PROFILE(cft, size, pid, tag)
599#define BL_COMM_PROFILE_BARRIER(message, bc)
600#define BL_COMM_PROFILE_ALLREDUCE(cft, size, bc)
601#define BL_COMM_PROFILE_REDUCE(cft, size, pid)
602#define BL_COMM_PROFILE_WAIT(cft, reqs, status, bc)
603#define BL_COMM_PROFILE_WAITSOME(cft, reqs, completed, status, bc)
604#define BL_COMM_PROFILE_NAMETAG(message)
605#define BL_COMM_PROFILE_FILTER(cft)
606#define BL_COMM_PROFILE_UNFILTER(cft)
607#define BL_COMM_PROFILE_FLUSH()
608#define BL_COMM_PROFILE_SETFLUSHSIZE(fsize)
609#define BL_COMM_PROFILE_TAGRANGE(tagmin, tagmax)
610#define BL_COMM_PROFILE_TAGWRAP()
611#define BL_COMM_PROFILE_INITAMR(flev, mlev, rr, pd)
612
613#endif
614
615// ============================================================
616// Sync macros
617// ============================================================
618
619#if (defined(BL_PROFILING) || defined(AMREX_TINY_PROFILING))
620
621namespace amrex {
622
623 class BLProfileSync {
624
625 public:
626 static void Sync() noexcept;
627 static void Sync(const std::string& name) noexcept;
628 static void Sync(const char* name) noexcept;
629
630 static void InitParams();
631
632 static void StartSyncRegion() noexcept;
633 static void StartSyncRegion(const std::string& name) noexcept;
634 static void StartSyncRegion(const char* name) noexcept;
635 static void EndSyncRegion() noexcept;
636
637 private:
638 static int sync_counter;
639 static int use_prof_syncs;
640 };
641
642}
643
644#define BL_PROFILE_SYNC() amrex::BLProfileSync::Sync()
645#define BL_PROFILE_SYNC_TIMED(fname) amrex::BLProfileSync::Sync(fname)
646#define BL_PROFILE_SYNC_START() amrex::BLProfileSync::StartSyncRegion()
647#define BL_PROFILE_SYNC_START_TIMED(fname) amrex::BLProfileSync::StartSyncRegion(fname)
648#define BL_PROFILE_SYNC_STOP() amrex::BLProfileSync::EndSyncRegion()
649
650#else
651
652#define BL_PROFILE_SYNC()
653#define BL_PROFILE_SYNC_TIMED(fname)
654#define BL_PROFILE_SYNC_START()
655#define BL_PROFILE_SYNC_START_TIMED(fname)
656#define BL_PROFILE_SYNC_STOP()
657
658#endif
659
660// ============================================================
661// Third party macros.
662// Mutually exclusive, including from BL_PROFILE.
663// May be turned on with BL_profiling
664// to allow profiling the BL_PROFILE with additional flag.
665// ============================================================
666
667#if defined(AMREX_VTUNE)
668
669#define BL_TP_PROFILE_REGION_START() __itt_resume(); \
670amrex::Print() << "VTune regional recording has begun.\n";
671#define BL_TP_PROFILE_REGION_STOP() __itt_pause(); \
672amrex::Print() << "VTune regional recording has been stopped.\n";
673
674#elif defined(AMREX_CRAYPAT)
675
676#define BL_TP_PROFILE_REGION_START() PAT_record(PAT_STATE_ON); \
677amrex::Print() << "CrayPat regional recording has begun.\n";
678#define BL_TP_PROFILE_REGION_STOP() PAT_record(PAT_STATE_OFF); \
679amrex::Print() << "CrayPat regional recording has been stopped.\n";
680
681#elif defined(AMREX_FORGE)
682
683#define BL_TP_PROFILE_REGION_START() allinea_start_sampling(); \
684amrex::Print() << "MAP regional recording has begun.\n";
685#define BL_TP_PROFILE_REGION_STOP() allinea_stop_sampling(); \
686amrex::Print() << "MAP regional recording has begun.\n";
687
688#else
689
690#define BL_TP_PROFILE_REGION_START()
691#define BL_TP_PROFILE_REGION_STOP()
692
693#endif
694
695#endif
Runtime initialization/finalization helpers and global diagnostics.
Fixed-size array types for use on GPU and CPU.
Integer-lattice boxes and helpers for defining index-space regions.
Compiler- and backend-specific extension macros (e.g., restrict, SIMD, inline).
Definition AMReX_BLProfiler.H:535
BLProfiler(const std::string &)
Definition AMReX_BLProfiler.H:537
void start()
Definition AMReX_BLProfiler.H:543
static void Initialize()
Definition AMReX_BLProfiler.H:538
static void InitParams(const Real, const bool, const bool)
Definition AMReX_BLProfiler.H:545
static void WriteCommStats()
Definition AMReX_BLProfiler.H:542
static void AddStep(const int)
Definition AMReX_BLProfiler.H:547
static void Finalize()
Definition AMReX_BLProfiler.H:540
void stop()
Definition AMReX_BLProfiler.H:544
static void WriteStats(std::ostream &)
Definition AMReX_BLProfiler.H:541
static void InitParams()
Definition AMReX_BLProfiler.H:539
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
int MPI_Request
Definition AMReX_ccse-mpi.H:54
Definition AMReX_Amr.cpp:50
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream helper; forwards to the friend declared inside AmrMesh.
Definition AMReX_AmrMesh.cpp:1372