Changeset 22551 for issm/trunk-jpl/src/c/classes/Profiler.cpp
- Timestamp:
- 03/16/18 15:48:35 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/Profiler.cpp
r20955 r22551 3 3 */ 4 4 5 /*Include files : {{{*/5 /*Include files*/ 6 6 #ifdef HAVE_CONFIG_H 7 7 #include <config.h> … … 11 11 12 12 #include "./Profiler.h" 13 #include "./Params/DoubleParam.h"14 13 #include "../toolkits/toolkits.h" 15 /*}}}*/16 14 17 15 /*Profiler constructors and destructors:*/ 18 16 Profiler::Profiler(){/*{{{*/ 19 17 for(int i=0;i<MAXIMUMSIZE;i++){ 20 this->time[i] =NAN; 21 this->flops[i] =NAN; 22 this->memory[i]=NAN; 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; 23 25 } 24 26 } /*}}}*/ … … 42 44 /*Object virtual functions definitions:*/ 43 45 void Profiler::DeepEcho(void){/*{{{*/ 44 45 46 this->Echo(); 46 47 } 48 /*}}}*/ 47 }/*}}}*/ 49 48 void Profiler::Echo(void){/*{{{*/ 50 49 … … 52 51 for(int i=0;i<MAXIMUMSIZE;i++){ 53 52 _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 } 58 59 } 60 /*}}}*/ 61 int Profiler::Id(void){ return -1; }/*{{{*/ 53 _printf_(" flops: "<<this->flops[i]<<"\n"); 54 _printf_(" memory: "<<this->memory[i]<<"\n"); 55 _printf_(" time: "<<this->time[i]<<"\n"); 56 _printf_(" running: "<<this->time[i]<<"\n"); 57 } 58 59 } 60 /*}}}*/ 61 int Profiler::Id(void){ /*{{{*/ 62 return -1; 63 } 62 64 /*}}}*/ 63 65 void Profiler::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/ 64 66 65 67 IssmDouble* pointer = NULL; 68 bool* bpointer = NULL; 66 69 67 70 MARSHALLING_ENUM(ProfilerEnum); 68 71 pointer = &this->time[0]; 69 MARSHALLING_DYNAMIC(pointer,Issm Double,MAXIMUMSIZE);72 MARSHALLING_DYNAMIC(pointer,IssmPDouble,MAXIMUMSIZE); 70 73 pointer = &this->flops[0]; 71 MARSHALLING_DYNAMIC(pointer,Issm Double,MAXIMUMSIZE);74 MARSHALLING_DYNAMIC(pointer,IssmPDouble,MAXIMUMSIZE); 72 75 pointer = &this->memory[0]; 73 MARSHALLING_DYNAMIC(pointer,IssmDouble,MAXIMUMSIZE); 76 MARSHALLING_DYNAMIC(pointer,IssmPDouble,MAXIMUMSIZE); 77 bpointer = &this->running[0]; 78 MARSHALLING_DYNAMIC(bpointer,bool,MAXIMUMSIZE); 74 79 75 80 } /*}}}*/ 76 81 int Profiler::ObjectEnum(void){/*{{{*/ 77 78 82 return ProfilerEnum; 79 80 } 81 /*}}}*/ 83 }/*}}}*/ 82 84 83 85 /*Profiler routines:*/ 84 IssmDouble Profiler::DeltaFlops(int inittag, int finaltag){/*{{{*/ 86 IssmPDouble Profiler::TotalFlops(int tag){/*{{{*/ 87 88 /*Get tag*/ 89 _assert_(tag>=0); 90 _assert_(tag<MAXIMUMSIZE); 91 if(this->running[tag]) _error_("Tag "<<tag<<" has not been stopped"); 92 93 return this->flops[tag]; 94 }/*}}}*/ 95 IssmPDouble Profiler::TotalTime(int tag){/*{{{*/ 96 97 /*Get tag*/ 98 _assert_(tag>=0); 99 _assert_(tag<MAXIMUMSIZE); 100 if(this->running[tag]) _error_("Tag "<<tag<<" has not been stopped"); 101 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 /*}}}*/ 129 IssmDouble Profiler::Memory(int tag){/*{{{*/ 85 130 86 131 /*Get initial flops*/ 87 _assert_(inittag>=0); 88 _assert_(inittag<MAXIMUMSIZE); 89 if(xIsNan<IssmDouble>(this->flops[inittag])) _error_("Tag not set"); 90 IssmDouble init = this->flops[inittag]; 91 92 /*Get final flops*/ 93 _assert_(finaltag>=0); 94 _assert_(finaltag<MAXIMUMSIZE); 95 if(xIsNan<IssmDouble>(this->flops[finaltag])) _error_("Tag not set"); 96 IssmDouble final = this->flops[finaltag]; 97 98 return final-init; 99 } 100 /*}}}*/ 101 IssmDouble Profiler::DeltaTime(int inittag, int finaltag){/*{{{*/ 102 103 /*Get initial time*/ 104 _assert_(inittag>=0); 105 _assert_(inittag<MAXIMUMSIZE); 106 if(xIsNan<IssmDouble>(this->time[inittag])) _error_("Tag "<<inittag<<" not set"); 107 IssmDouble init = this->time[inittag]; 108 109 /*Get final time*/ 110 _assert_(finaltag>=0); 111 _assert_(finaltag<MAXIMUMSIZE); 112 if(xIsNan<IssmDouble>(this->time[finaltag])) _error_("Tag "<<finaltag<<" not set"); 113 IssmDouble final = this->time[finaltag]; 114 115 #ifdef _HAVE_MPI_ 116 return final-init; 117 #else 118 return (final-init)/CLOCKS_PER_SEC; 119 #endif 120 } 121 /*}}}*/ 122 int Profiler::DeltaTimeModHour(int inittag, int finishtag){/*{{{*/ 123 124 IssmDouble delta = this->DeltaTime(inittag,finishtag); 125 return int((reCast<int,IssmDouble>(delta))/3600); 126 127 } 128 /*}}}*/ 129 int Profiler::DeltaTimeModMin(int inittag, int finishtag){/*{{{*/ 130 131 IssmDouble delta = this->DeltaTime(inittag,finishtag); 132 return int(int(reCast<int,IssmDouble>(delta))%3600/60); 133 } 134 /*}}}*/ 135 int Profiler::DeltaTimeModSec(int inittag, int finishtag){/*{{{*/ 136 137 IssmDouble delta = this->DeltaTime(inittag,finishtag); 138 return int(reCast<int,IssmDouble>(delta)%60); 139 } 140 /*}}}*/ 141 IssmDouble Profiler::Memory(int tag){/*{{{*/ 142 143 /*Get initial flops*/ 144 _assert_(tag>=0); 145 _assert_(tag<MAXIMUMSIZE); 146 if(xIsNan<IssmDouble>(this->flops[tag])) _error_("Tag not set"); 132 _assert_(tag>=0); 133 _assert_(tag<MAXIMUMSIZE); 134 if(this->running[tag]) _error_("Tag "<<tag<<" has not been stopped"); 135 147 136 return this->memory[tag]; 148 137 } 149 138 /*}}}*/ 150 void Profiler::Tag(int tagenum,bool dontmpisync){/*{{{*/ 151 152 IssmDouble t; 153 IssmDouble f; 154 IssmDouble m; 155 156 /*If mpisync requested, make sure all the cpus are at the same point 157 *in the execution: */ 139 void Profiler::Start(int tag,bool dontmpisync){/*{{{*/ 140 141 /*Check tag*/ 142 _assert_(tag>=0); 143 _assert_(tag<MAXIMUMSIZE); 144 if(this->running[tag]) _error_("Tag "<<tag<<" is already running"); 145 146 147 /*If mpisync requested, make sure all the cpus are at the same point in the execution: */ 158 148 if(!dontmpisync){ 159 149 ISSM_MPI_Barrier(IssmComm::GetComm()); … … 162 152 /*Capture time: */ 163 153 #ifdef _HAVE_MPI_ 164 t=ISSM_MPI_Wtime();165 #else 166 t=(IssmPDouble)clock();154 IssmPDouble t=ISSM_MPI_Wtime(); 155 #else 156 IssmPDouble t=(IssmPDouble)clock(); 167 157 #endif 168 158 169 159 /*Capture flops: */ 160 IssmPDouble f = 0.; 161 IssmPDouble m = 0.; 170 162 #ifdef _HAVE_PETSC_ 171 163 PetscGetFlops(&f); … … 176 168 177 169 /*Plug into this->time: */ 178 _assert_(tagenum>=0); 179 _assert_(tagenum<MAXIMUMSIZE); 180 if(!xIsNan<IssmDouble>(this->time[tagenum])) _error_("Tag already exists"); 181 this->time[tagenum] = t; 182 if(!xIsNan<IssmDouble>(this->flops[tagenum])) _error_("Tag already exists"); 183 this->flops[tagenum] = f; 184 if(!xIsNan<IssmDouble>(this->memory[tagenum])) _error_("Tag already exists"); 185 this->memory[tagenum]= m; 186 187 } 188 /*}}}*/ 170 _assert_(tag>=0); 171 _assert_(tag<MAXIMUMSIZE); 172 this->time_start[tag] = t; 173 this->flops_start[tag] = f; 174 this->memory_start[tag] = m; 175 176 /*turn on running*/ 177 this->running[tag] = true; 178 }/*}}}*/ 179 void Profiler::Stop(int tag,bool dontmpisync){/*{{{*/ 180 181 /*Check tag*/ 182 _assert_(tag>=0); 183 _assert_(tag<MAXIMUMSIZE); 184 if(!this->running[tag]) _error_("Tag "<<tag<<" is not running"); 185 186 187 /*If mpisync requested, make sure all the cpus are at the same point in the execution: */ 188 if(!dontmpisync){ 189 ISSM_MPI_Barrier(IssmComm::GetComm()); 190 } 191 192 /*Capture time: */ 193 #ifdef _HAVE_MPI_ 194 IssmPDouble t=ISSM_MPI_Wtime(); 195 #else 196 IssmPDouble t=(IssmPDouble)clock(); 197 #endif 198 199 /*Capture flops: */ 200 IssmPDouble f = 0.; 201 IssmPDouble m = 0.; 202 #ifdef _HAVE_PETSC_ 203 PetscGetFlops(&f); 204 PetscMemoryGetCurrentUsage(&m); 205 #else 206 /*do nothing for now:*/ 207 #endif 208 209 /*Plug into this->time: */ 210 _assert_(tag>=0); 211 _assert_(tag<MAXIMUMSIZE); 212 this->time[tag] += t - this->time_start[tag]; 213 this->flops[tag] += f - this->flops_start[tag]; 214 this->memory[tag] += m - this->memory_start[tag]; 215 216 /*turn off running*/ 217 this->running[tag] = false; 218 }/*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.