Ice Sheet System Model  4.18
Code documentation
Profiler.cpp
Go to the documentation of this file.
1 
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 "../toolkits/toolkits.h"
14 
15 /*Profiler constructors and destructors:*/
17  for(int i=0;i<MAXPROFSIZE;i++){
18  this->time[i] = 0.;
19  this->time_start[i] = 0.;
20  this->flops[i] = 0.;
21  this->flops_start[i] = 0.;
22  this->memory[i] = 0.;
23  this->memory_start[i] = 0.;
24  this->running[i] = false;
25  this->used[i] = false;
26  }
27 } /*}}}*/
29  /*Nothing to delete, everything is statically allocated*/
30 } /*}}}*/
32  /*First do simple copy: */
33  Profiler* output=new Profiler();
34 
35  for(int i=0;i<MAXPROFSIZE;i++){
36  output->time[i] =this->time[i];
37  output->flops[i] =this->flops[i];
38  output->memory[i]=this->memory[i];
39  }
40 
41  return (Object*)output;
42 }
43 /*}}}*/
44 
45 /*Object virtual functions definitions:*/
46 void Profiler::DeepEcho(void){/*{{{*/
47  this->Echo();
48 }/*}}}*/
49 void Profiler::Echo(void){/*{{{*/
50 
51  _printf_("Profiler:\n");
52  for(int i=0;i<MAXPROFSIZE;i++){
53  _printf_(" Tag "<<i<<":\n");
54  _printf_(" flops: "<<this->flops[i]<<"\n");
55  _printf_(" memory: "<<this->memory[i]<<"\n");
56  _printf_(" time: "<<this->time[i]<<"\n");
57  _printf_(" running: "<<this->time[i]<<"\n");
58  }
59 
60 }
61 /*}}}*/
62 int Profiler::Id(void){ /*{{{*/
63  return -1;
64 }
65 /*}}}*/
66 void Profiler::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
67 
68  IssmPDouble* pointer = NULL;
69  bool* bpointer = NULL;
70 
72  pointer = &this->time[0];
74  pointer = &this->flops[0];
76  pointer = &this->memory[0];
78  bpointer = &this->running[0];
79  MARSHALLING_DYNAMIC(bpointer,bool,MAXPROFSIZE);
80 
81 } /*}}}*/
82 int Profiler::ObjectEnum(void){/*{{{*/
83  return ProfilerEnum;
84 }/*}}}*/
85 
86 /*Profiler routines:*/
88 
89  /*Get tag*/
90  _assert_(tag>=0);
91  _assert_(tag<MAXPROFSIZE);
92  if(this->running[tag]) _error_("Tag "<<tag<<" has not been stopped");
93 
94  return this->flops[tag];
95 }/*}}}*/
97 
98  /*Get tag*/
99  _assert_(tag>=0);
100  _assert_(tag<MAXPROFSIZE);
101  if(this->running[tag]) _error_("Tag "<<tag<<" has not been stopped");
102 
103  #ifdef _HAVE_MPI_
104  return this->time[tag];
105  #else
106  return this->time[tag]/CLOCKS_PER_SEC;
107  #endif
108 }
109 /*}}}*/
110 int Profiler::TotalTimeModHour(int tag){/*{{{*/
111 
112  IssmPDouble delta = this->TotalTime(tag);
113  return int((reCast<int,IssmPDouble>(delta))/3600);
114 
115 }
116 /*}}}*/
117 int Profiler::TotalTimeModMin(int tag){/*{{{*/
118 
119  IssmPDouble delta = this->TotalTime(tag);
120  return int(int(reCast<int,IssmPDouble>(delta))%3600/60);
121 }
122 /*}}}*/
123 int Profiler::TotalTimeModSec(int tag){/*{{{*/
124 
125  IssmPDouble delta = this->TotalTime(tag);
126  return int(reCast<int,IssmPDouble>(delta)%60);
127 }
128 /*}}}*/
130 
131  /*Get initial flops*/
132  _assert_(tag>=0);
133  _assert_(tag<MAXPROFSIZE);
134  if(this->running[tag]) _error_("Tag "<<tag<<" has not been stopped");
135 
136  return this->memory[tag];
137 }
138 /*}}}*/
139 void Profiler::Start(int tag,bool dontmpisync){/*{{{*/
140 
141  /*Check tag*/
142  _assert_(tag>=0);
143  _assert_(tag<MAXPROFSIZE);
144  if(this->running[tag]) _error_("Tag "<<tag<<" is already running");
145 
146  /*If mpisync requested, make sure all the cpus are at the same point in the execution: */
147  if(!dontmpisync){
149  }
150 
151  /*Capture time: */
152  #ifdef _HAVE_MPI_
154  #else
155  IssmPDouble t=(IssmPDouble)clock();
156  #endif
157 
158  /*Capture flops: */
159  IssmPDouble f = 0.;
160  IssmPDouble m = 0.;
161  #ifdef _HAVE_PETSC_
162  PetscGetFlops(&f);
163  PetscMemoryGetCurrentUsage(&m);
164  #else
165  /*do nothing for now:*/
166  #endif
167 
168  /*Plug into this->time: */
169  _assert_(tag>=0);
170  _assert_(tag<MAXPROFSIZE);
171  this->time_start[tag] = t;
172  this->flops_start[tag] = f;
173  this->memory_start[tag] = m;
174 
175  /*turn on running*/
176  this->running[tag] = true;
177  this->used[tag] = true;
178 }/*}}}*/
179 void Profiler::Stop(int tag,bool dontmpisync){/*{{{*/
180 
181  /*Check tag*/
182  _assert_(tag>=0);
183  _assert_(tag<MAXPROFSIZE);
184  if(!this->running[tag]) _error_("Tag "<<tag<<" is not running");
185 
186  /*If mpisync requested, make sure all the cpus are at the same point in the execution: */
187  if(!dontmpisync){
189  }
190 
191  /*Capture time: */
192  #ifdef _HAVE_MPI_
194  #else
195  IssmPDouble t=(IssmPDouble)clock();
196  #endif
197 
198  /*Capture flops: */
199  IssmPDouble f = 0.;
200  IssmPDouble m = 0.;
201  #ifdef _HAVE_PETSC_
202  PetscGetFlops(&f);
203  PetscMemoryGetCurrentUsage(&m);
204  #else
205  /*do nothing for now:*/
206  #endif
207 
208  /*Plug into this->time: */
209  _assert_(tag>=0);
210  _assert_(tag<MAXPROFSIZE);
211  this->time[tag] += t - this->time_start[tag];
212  this->flops[tag] += f - this->flops_start[tag];
213  this->memory[tag] += m - this->memory_start[tag];
214 
215  /*turn off running*/
216  this->running[tag] = false;
217 }/*}}}*/
218 bool Profiler::Used(int tag){/*{{{*/
219 
220  /*Check tag*/
221  _assert_(tag>=0);
222  _assert_(tag<MAXPROFSIZE);
223  return this->used[tag];
224 }/*}}}*/
Profiler::TotalTimeModSec
int TotalTimeModSec(int tag)
Definition: Profiler.cpp:123
Profiler::memory_start
IssmPDouble memory_start[MAXPROFSIZE]
Definition: Profiler.h:39
Profiler::Memory
IssmPDouble Memory(int tag)
Definition: Profiler.cpp:129
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
ProfilerEnum
@ ProfilerEnum
Definition: EnumDefinitions.h:1233
Profiler::TotalFlops
IssmPDouble TotalFlops(int tag)
Definition: Profiler.cpp:87
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
Profiler::time_start
IssmPDouble time_start[MAXPROFSIZE]
Definition: Profiler.h:41
Profiler::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Profiler.cpp:66
Profiler::memory
IssmPDouble memory[MAXPROFSIZE]
Definition: Profiler.h:38
MARSHALLING_DYNAMIC
#define MARSHALLING_DYNAMIC(FIELD, TYPE, SIZE)
Definition: Marshalling.h:61
Profiler::time
IssmPDouble time[MAXPROFSIZE]
Definition: Profiler.h:40
Object
Definition: Object.h:13
Profiler::ObjectEnum
int ObjectEnum()
Definition: Profiler.cpp:82
Profiler
Definition: Profiler.h:33
Profiler::Id
int Id()
Definition: Profiler.cpp:62
MAXPROFSIZE
#define MAXPROFSIZE
Definition: Profiler.h:30
Profiler::flops
IssmPDouble flops[MAXPROFSIZE]
Definition: Profiler.h:36
Profiler::used
bool used[MAXPROFSIZE]
Definition: Profiler.h:43
Profiler::Stop
void Stop(int tagenum, bool dontmpisync=true)
Definition: Profiler.cpp:179
Profiler::Used
bool Used(int tagenum)
Definition: Profiler.cpp:218
Profiler::~Profiler
~Profiler()
Definition: Profiler.cpp:28
Profiler::Profiler
Profiler()
Definition: Profiler.cpp:16
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Profiler.h
: header file for node object
Profiler::Start
void Start(int tagenum, bool dontmpisync=true)
Definition: Profiler.cpp:139
Profiler::flops_start
IssmPDouble flops_start[MAXPROFSIZE]
Definition: Profiler.h:37
Profiler::TotalTimeModHour
int TotalTimeModHour(int tag)
Definition: Profiler.cpp:110
ISSM_MPI_Wtime
double ISSM_MPI_Wtime(void)
Definition: issmmpi.cpp:511
Profiler::running
bool running[MAXPROFSIZE]
Definition: Profiler.h:42
Profiler::TotalTimeModMin
int TotalTimeModMin(int tag)
Definition: Profiler.cpp:117
Profiler::DeepEcho
void DeepEcho()
Definition: Profiler.cpp:46
ISSM_MPI_Barrier
int ISSM_MPI_Barrier(ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:148
Profiler::Echo
void Echo()
Definition: Profiler.cpp:49
IssmPDouble
IssmDouble IssmPDouble
Definition: types.h:38
Profiler::TotalTime
IssmPDouble TotalTime(int tag)
Definition: Profiler.cpp:96
Profiler::copy
Object * copy()
Definition: Profiler.cpp:31