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