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

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

CHG: cleanup issm.cpp. Worked on homogeneizing solutioncore
returned by CorePointerFromSolutionEnum. Because we have wrappers (dakota, control),
created new PureCorePointerFromSolutionEnum, which only deals with analyses, not wrappers.
This new PureCorePointerFromSolutionEnum is called in control_core, controltao_core.
Also, CorePointerFromSolutionEnum can take in a nodakota flag, to allow for return of all
solution types except dakota itself. This is called in dakota_core.
Also move the AutodiffDriversx to ad_core.

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