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

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

NEW and CHG:
added new enums in src/m/enum. Please run source Synchronize.sh when adding new enums in EnumDefinitions.h
new Profiler object that stores unlimited number of tags. easier to handle time profiling anywhere in the
code.
debugged EnvironmentInit, which was duplicating external symbols.
new EnvironmentFinalize, to simplify finalization of environment variables like Petsc and MPI.
simplified issm.cpp accordingly with new Profiler capabilitlie.s

File size: 2.8 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->timetags=new Parameters();
19}
20/*}}}*/
21/*FUNCTION Profiler::~Profiler(){{{*/
22Profiler::~Profiler(){
23 delete timetags;
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->timetags->Echo();
34
35}
36/*}}}*/
37/*FUNCTION Profiler::DeepEcho{{{*/
38void Profiler::DeepEcho(void){
39
40 _printLine_("Profiler:");
41 _printLine_(" time tags: ");
42 this->timetags->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 double time;
62
63 /*If mpisync requested, make sure all the cpus are at the same point
64 *in the execution: */
65 if(!dontmpisync){
66 #ifdef _HAVE_MPI_
67 MPI_Barrier(MPI_COMM_WORLD);
68 #endif
69 }
70
71 /*Now capture time: */
72 #ifdef _HAVE_MPI_
73 time=MPI_Wtime();
74 #else
75 time=(IssmPDouble)clock();
76 #endif
77
78 /*Plug into this->timetags: */
79 this->timetags->AddObject(new DoubleParam(tagenum,time));
80
81}
82/*}}}*/
83/*FUNCTION Profiler::Delta {{{*/
84double Profiler::Delta(int inittag, int finaltag){
85
86 double init, final;
87 this->timetags->FindParam(&init,inittag);
88 this->timetags->FindParam(&final,finaltag);
89
90 #ifdef _HAVE_MPI_
91 return final-init;
92 #else
93 return (final-init)/CLOCKS_PER_SEC;
94 #endif
95}
96/*}}}*/
97/*FUNCTION Profiler::DeltaModHour {{{*/
98int Profiler::DeltaModHour(int inittag, int finishtag){
99
100 double init, finish;
101 this->timetags->FindParam(&init,inittag);
102 this->timetags->FindParam(&finish,finishtag);
103
104 #ifdef _HAVE_MPI_
105 return int((finish-init)/3600);
106 #else
107 return int((finish-init)/CLOCKS_PER_SEC/3600);
108 #endif
109
110}
111/*}}}*/
112/*FUNCTION Profiler::DeltaModMin {{{*/
113int Profiler::DeltaModMin(int inittag, int finishtag){
114
115 double init, finish;
116 this->timetags->FindParam(&init,inittag);
117 this->timetags->FindParam(&finish,finishtag);
118
119 #ifdef _HAVE_MPI_
120 return int(int(finish-init)%3600/60);
121 #else
122 return int(int(finish-init)/CLOCKS_PER_SEC%3600/60);
123 #endif
124}
125/*}}}*/
126/*FUNCTION Profiler::DeltaModSec {{{*/
127int Profiler::DeltaModSec(int inittag, int finishtag){
128
129 double init, finish;
130 this->timetags->FindParam(&init,inittag);
131 this->timetags->FindParam(&finish,finishtag);
132
133 #ifdef _HAVE_MPI_
134 return int(finish-init)%60;
135 #else
136 return int(finish-init)/CLOCKS_PER_SEC%60;
137 #endif
138}
139/*}}}*/
Note: See TracBrowser for help on using the repository browser.