source: issm/trunk-jpl/src/c/classes/objects/Profiler.cpp@ 13607

Last change on this file since 13607 was 13607, checked in by Eric.Larour, 12 years ago

CHG: more changes to switch from my_rank and num_procs to IssmComm::GetSize and IssmComm::GetRank

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