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

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

CHG:
simplified profiler further.
moved Dakotax to solution/dakota_core and cleanep up the modules/Dakotax code a lot.
also took care of reactivating sharedstring and DescriptorIndex.

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