Ignore:
Timestamp:
03/16/18 15:48:35 (7 years ago)
Author:
Mathieu Morlighem
Message:

CHG: revised how profiling is done and added solver time to see how much time we spend solver linear systems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/Profiler.cpp

    r20955 r22551  
    33 */
    44
    5 /*Include files: {{{*/
     5/*Include files*/
    66#ifdef HAVE_CONFIG_H
    77        #include <config.h>
     
    1111
    1212#include "./Profiler.h"
    13 #include "./Params/DoubleParam.h"
    1413#include "../toolkits/toolkits.h"
    15 /*}}}*/
    1614
    1715/*Profiler constructors and destructors:*/
    1816Profiler::Profiler(){/*{{{*/
    1917        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;
    2325        }
    2426} /*}}}*/
     
    4244/*Object virtual functions definitions:*/
    4345void Profiler::DeepEcho(void){/*{{{*/
    44 
    4546        this->Echo();
    46 
    47 }
    48 /*}}}*/
     47}/*}}}*/
    4948void Profiler::Echo(void){/*{{{*/
    5049
     
    5251        for(int i=0;i<MAXIMUMSIZE;i++){
    5352                _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/*}}}*/
     61int  Profiler::Id(void){ /*{{{*/
     62        return -1;
     63}
    6264/*}}}*/
    6365void Profiler::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
    6466
    6567        IssmDouble* pointer = NULL;
     68        bool*       bpointer = NULL;
    6669
    6770        MARSHALLING_ENUM(ProfilerEnum);
    6871        pointer = &this->time[0];
    69         MARSHALLING_DYNAMIC(pointer,IssmDouble,MAXIMUMSIZE);
     72        MARSHALLING_DYNAMIC(pointer,IssmPDouble,MAXIMUMSIZE);
    7073        pointer = &this->flops[0];
    71         MARSHALLING_DYNAMIC(pointer,IssmDouble,MAXIMUMSIZE);
     74        MARSHALLING_DYNAMIC(pointer,IssmPDouble,MAXIMUMSIZE);
    7275        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);
    7479
    7580} /*}}}*/
    7681int  Profiler::ObjectEnum(void){/*{{{*/
    77 
    7882        return ProfilerEnum;
    79 
    80 }
    81 /*}}}*/
     83}/*}}}*/
    8284
    8385/*Profiler routines:*/
    84 IssmDouble  Profiler::DeltaFlops(int inittag, int finaltag){/*{{{*/
     86IssmPDouble  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}/*}}}*/
     95IssmPDouble  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/*}}}*/
     110int Profiler::TotalTimeModHour(int tag){/*{{{*/
     111
     112        IssmPDouble delta = this->TotalTime(tag);
     113        return int((reCast<int,IssmPDouble>(delta))/3600);
     114
     115}
     116/*}}}*/
     117int Profiler::TotalTimeModMin(int tag){/*{{{*/
     118
     119        IssmPDouble delta = this->TotalTime(tag);
     120        return int(int(reCast<int,IssmPDouble>(delta))%3600/60);
     121}
     122/*}}}*/
     123int Profiler::TotalTimeModSec(int tag){/*{{{*/
     124
     125        IssmPDouble delta = this->TotalTime(tag);
     126        return int(reCast<int,IssmPDouble>(delta)%60);
     127}
     128/*}}}*/
     129IssmDouble  Profiler::Memory(int tag){/*{{{*/
    85130
    86131        /*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
    147136        return this->memory[tag];
    148137}
    149138/*}}}*/
    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: */
     139void  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: */
    158148        if(!dontmpisync){
    159149                ISSM_MPI_Barrier(IssmComm::GetComm());
     
    162152        /*Capture time: */
    163153        #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();
    167157        #endif
    168158
    169159        /*Capture flops: */
     160        IssmPDouble f = 0.;
     161        IssmPDouble m = 0.;
    170162        #ifdef _HAVE_PETSC_
    171163                PetscGetFlops(&f);
     
    176168
    177169        /*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}/*}}}*/
     179void  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.