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