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