1 | /*!\file Profiler.c
|
---|
2 | * \brief: implementation of the Profiler object
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*Include files: {{{*/
|
---|
6 | #ifdef HAVE_CONFIG_H
|
---|
7 | #include <config.h>
|
---|
8 | #else
|
---|
9 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | #include "./Profiler.h"
|
---|
13 | #include "./Params/DoubleParam.h"
|
---|
14 | #include "../../Container/Parameters.h"
|
---|
15 | #include "../../toolkits/toolkits.h"
|
---|
16 | /*}}}*/
|
---|
17 |
|
---|
18 | /*Profiler constructors and destructors:*/
|
---|
19 | /*FUNCTION Profiler::Profiler() default constructor {{{*/
|
---|
20 | Profiler::Profiler(){
|
---|
21 | this->time=new Parameters();
|
---|
22 | this->flops=new Parameters();
|
---|
23 | this->memory=new Parameters();
|
---|
24 | }
|
---|
25 | /*}}}*/
|
---|
26 | /*FUNCTION Profiler::~Profiler(){{{*/
|
---|
27 | Profiler::~Profiler(){
|
---|
28 | delete time;
|
---|
29 | delete flops;
|
---|
30 | delete memory;
|
---|
31 | }
|
---|
32 | /*}}}*/
|
---|
33 |
|
---|
34 | /*Object virtual functions definitions:*/
|
---|
35 | /*FUNCTION Profiler::Echo{{{*/
|
---|
36 | void Profiler::Echo(void){
|
---|
37 |
|
---|
38 | _printLine_("Profiler:");
|
---|
39 | _printLine_(" time tags: ");
|
---|
40 | this->time->Echo();
|
---|
41 |
|
---|
42 | }
|
---|
43 | /*}}}*/
|
---|
44 | /*FUNCTION Profiler::DeepEcho{{{*/
|
---|
45 | void Profiler::DeepEcho(void){
|
---|
46 |
|
---|
47 | _printLine_("Profiler:");
|
---|
48 | _printLine_(" time tags: ");
|
---|
49 | this->time->DeepEcho();
|
---|
50 |
|
---|
51 | }
|
---|
52 | /*}}}*/
|
---|
53 | /*FUNCTION Profiler::Id{{{*/
|
---|
54 | int Profiler::Id(void){ return -1; }
|
---|
55 | /*}}}*/
|
---|
56 | /*FUNCTION Profiler::ObjectEnum{{{*/
|
---|
57 | int Profiler::ObjectEnum(void){
|
---|
58 |
|
---|
59 | return ProfilerEnum;
|
---|
60 |
|
---|
61 | }
|
---|
62 | /*}}}*/
|
---|
63 |
|
---|
64 | /*Profiler routines:*/
|
---|
65 | /*FUNCTION Profiler::Tag {{{*/
|
---|
66 | void Profiler::Tag(int tagenum,bool dontmpisync){
|
---|
67 |
|
---|
68 | IssmDouble t;
|
---|
69 | IssmDouble f;
|
---|
70 | IssmDouble m;
|
---|
71 |
|
---|
72 | /*If mpisync requested, make sure all the cpus are at the same point
|
---|
73 | *in the execution: */
|
---|
74 | if(!dontmpisync){
|
---|
75 | #ifdef _HAVE_MPI_
|
---|
76 | MPI_Barrier(IssmComm::GetComm());
|
---|
77 | #endif
|
---|
78 | }
|
---|
79 |
|
---|
80 | /*Capture time: */
|
---|
81 | #ifdef _HAVE_MPI_
|
---|
82 | t=MPI_Wtime();
|
---|
83 | #else
|
---|
84 | t=(IssmPDouble)clock();
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | /*Capture flops: */
|
---|
88 | #ifdef _HAVE_PETSC_
|
---|
89 | PetscGetFlops(&f);
|
---|
90 | PetscMemoryGetCurrentUsage(&m);
|
---|
91 | #else
|
---|
92 | /*do nothing for now:*/
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | /*Plug into this->time: */
|
---|
96 | this->time->AddObject(new DoubleParam(tagenum,t));
|
---|
97 | this->flops->AddObject(new DoubleParam(tagenum,f));
|
---|
98 | this->memory->AddObject(new DoubleParam(tagenum,m));
|
---|
99 |
|
---|
100 | }
|
---|
101 | /*}}}*/
|
---|
102 | /*FUNCTION Profiler::DeltaTime {{{*/
|
---|
103 | IssmDouble Profiler::DeltaTime(int inittag, int finaltag){
|
---|
104 |
|
---|
105 | IssmDouble init, final;
|
---|
106 | this->time->FindParam(&init,inittag);
|
---|
107 | this->time->FindParam(&final,finaltag);
|
---|
108 |
|
---|
109 | #ifdef _HAVE_MPI_
|
---|
110 | return final-init;
|
---|
111 | #else
|
---|
112 | return (final-init)/CLOCKS_PER_SEC;
|
---|
113 | #endif
|
---|
114 | }
|
---|
115 | /*}}}*/
|
---|
116 | /*FUNCTION Profiler::DeltaFlops {{{*/
|
---|
117 | IssmDouble Profiler::DeltaFlops(int inittag, int finaltag){
|
---|
118 |
|
---|
119 | IssmDouble init, final;
|
---|
120 | this->flops->FindParam(&init,inittag);
|
---|
121 | this->flops->FindParam(&final,finaltag);
|
---|
122 |
|
---|
123 | return final-init;
|
---|
124 | }
|
---|
125 | /*}}}*/
|
---|
126 | /*FUNCTION Profiler::DeltaTimeModHour {{{*/
|
---|
127 | int Profiler::DeltaTimeModHour(int inittag, int finishtag){
|
---|
128 |
|
---|
129 | IssmDouble init, finish;
|
---|
130 | this->time->FindParam(&init,inittag);
|
---|
131 | this->time->FindParam(&finish,finishtag);
|
---|
132 |
|
---|
133 | #ifdef _HAVE_MPI_
|
---|
134 | return int((reCast<int,IssmDouble>(finish-init))/3600);
|
---|
135 | #else
|
---|
136 | return int((reCast<int,IssmDouble>(finish-init))/CLOCKS_PER_SEC/3600);
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | }
|
---|
140 | /*}}}*/
|
---|
141 | /*FUNCTION Profiler::DeltaTimeModMin {{{*/
|
---|
142 | int Profiler::DeltaTimeModMin(int inittag, int finishtag){
|
---|
143 |
|
---|
144 | IssmDouble init, finish;
|
---|
145 | this->time->FindParam(&init,inittag);
|
---|
146 | this->time->FindParam(&finish,finishtag);
|
---|
147 |
|
---|
148 | #ifdef _HAVE_MPI_
|
---|
149 | return int(int(reCast<int,IssmDouble>(finish-init))%3600/60);
|
---|
150 | #else
|
---|
151 | return int(int(reCast<int,IssmDouble>(finish-init))/CLOCKS_PER_SEC%3600/60);
|
---|
152 | #endif
|
---|
153 | }
|
---|
154 | /*}}}*/
|
---|
155 | /*FUNCTION Profiler::DeltaTimeModSec {{{*/
|
---|
156 | int Profiler::DeltaTimeModSec(int inittag, int finishtag){
|
---|
157 |
|
---|
158 | IssmDouble init, finish;
|
---|
159 | this->time->FindParam(&init,inittag);
|
---|
160 | this->time->FindParam(&finish,finishtag);
|
---|
161 |
|
---|
162 | #ifdef _HAVE_MPI_
|
---|
163 | return int(reCast<int,IssmDouble>(finish-init))%60;
|
---|
164 | #else
|
---|
165 | return int(reCast<int,IssmDouble>(finish-init))/CLOCKS_PER_SEC%60;
|
---|
166 | #endif
|
---|
167 | }
|
---|
168 | /*}}}*/
|
---|
169 | /*FUNCTION Profiler::Memory {{{*/
|
---|
170 | IssmDouble Profiler::Memory(int tag){
|
---|
171 |
|
---|
172 | IssmDouble m;
|
---|
173 | this->memory->FindParam(&m,tag);
|
---|
174 |
|
---|
175 | return m;
|
---|
176 | }
|
---|
177 | /*}}}*/
|
---|