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