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
RevLine 
[13534]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(){
[13539]18 this->time=new Parameters();
[13534]19}
20/*}}}*/
21/*FUNCTION Profiler::~Profiler(){{{*/
22Profiler::~Profiler(){
[13539]23 delete time;
[13534]24}
25/*}}}*/
26
27/*Object virtual functions definitions:*/
28/*FUNCTION Profiler::Echo{{{*/
29void Profiler::Echo(void){
30
31 _printLine_("Profiler:");
32 _printLine_(" time tags: ");
[13539]33 this->time->Echo();
[13534]34
35}
36/*}}}*/
37/*FUNCTION Profiler::DeepEcho{{{*/
38void Profiler::DeepEcho(void){
39
40 _printLine_("Profiler:");
41 _printLine_(" time tags: ");
[13539]42 this->time->DeepEcho();
[13534]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
[13539]61 IssmDouble t;
62 IssmDouble f;
63 IssmDouble m;
[13534]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
[13539]73 /*Capture time: */
[13534]74 #ifdef _HAVE_MPI_
[13539]75 t=MPI_Wtime();
[13534]76 #else
[13539]77 t=(IssmPDouble)clock();
[13534]78 #endif
79
[13539]80 /*Capture flops: */
81 #ifdef _HAVE_PETSC_
82 PetscGetFlops(&f);
83 PetscMemoryGetCurrentUsage(&m);
84 #else
85 /*do nothing for now:*/
86 #endif
[13534]87
[13539]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
[13534]93}
94/*}}}*/
[13539]95/*FUNCTION Profiler::DeltaTime {{{*/
96IssmDouble Profiler::DeltaTime(int inittag, int finaltag){
[13534]97
[13539]98 IssmDouble init, final;
99 this->time->FindParam(&init,inittag);
100 this->time->FindParam(&final,finaltag);
[13534]101
102 #ifdef _HAVE_MPI_
103 return final-init;
104 #else
105 return (final-init)/CLOCKS_PER_SEC;
106 #endif
107}
108/*}}}*/
[13539]109/*FUNCTION Profiler::DeltaFlops {{{*/
110IssmDouble Profiler::DeltaFlops(int inittag, int finaltag){
[13534]111
[13539]112 IssmDouble init, final;
113 this->flops->FindParam(&init,inittag);
114 this->flops->FindParam(&final,finaltag);
[13534]115
[13539]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
[13534]126 #ifdef _HAVE_MPI_
[13539]127 return int((reCast<int,IssmDouble>(finish-init))/3600);
[13534]128 #else
[13539]129 return int((reCast<int,IssmDouble>(finish-init))/CLOCKS_PER_SEC/3600);
[13534]130 #endif
131
132}
133/*}}}*/
[13539]134/*FUNCTION Profiler::DeltaTimeModMin {{{*/
135int Profiler::DeltaTimeModMin(int inittag, int finishtag){
[13534]136
[13539]137 IssmDouble init, finish;
138 this->time->FindParam(&init,inittag);
139 this->time->FindParam(&finish,finishtag);
[13534]140
141 #ifdef _HAVE_MPI_
[13539]142 return int(int(reCast<int,IssmDouble>(finish-init))%3600/60);
[13534]143 #else
[13539]144 return int(int(reCast<int,IssmDouble>(finish-init))/CLOCKS_PER_SEC%3600/60);
[13534]145 #endif
146}
147/*}}}*/
[13539]148/*FUNCTION Profiler::DeltaTimeModSec {{{*/
149int Profiler::DeltaTimeModSec(int inittag, int finishtag){
[13534]150
[13539]151 IssmDouble init, finish;
152 this->time->FindParam(&init,inittag);
153 this->time->FindParam(&finish,finishtag);
[13534]154
155 #ifdef _HAVE_MPI_
[13539]156 return int(reCast<int,IssmDouble>(finish-init))%60;
[13534]157 #else
[13539]158 return int(reCast<int,IssmDouble>(finish-init))/CLOCKS_PER_SEC%60;
[13534]159 #endif
160}
161/*}}}*/
[13539]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.