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