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