source: issm/oecreview/Archive/24684-25833/ISSM-25529-25530.diff@ 25834

Last change on this file since 25834 was 25834, checked in by Mathieu Morlighem, 4 years ago

CHG: added 24684-25833

File size: 13.1 KB
  • ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp

     
     1/*!\file:  Marshalling.cpp
     2 * \brief implement marshall
     3 */
     4
     5#ifdef HAVE_CONFIG_H
     6#include <config.h>
     7#else
     8#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
     9#endif
     10
     11#include "./Marshalling.h"
     12
     13WriteCheckpointFunctor::WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE){/*{{{*/
     14        this->pmarshalled_data = pmarshalled_data_in;
     15}/*}}}*/
     16void WriteCheckpointFunctor::Echo(void){/*{{{*/
     17        printf("WriteCheckpointFunctor Echo:\n");
     18        printf("   pmarshalled_data: %p\n",pmarshalled_data);
     19}/*}}}*/
     20void WriteCheckpointFunctor::call(char* & value){/*{{{*/
     21        int size = strlen(value)+1;
     22        this->call(size);
     23        this->call(value,size);
     24};/*}}}*/
     25
     26LoadCheckpointFunctor::LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD){/*{{{*/
     27        this->pmarshalled_data = pmarshalled_data_in;
     28}/*}}}*/
     29void LoadCheckpointFunctor::Echo(void){/*{{{*/
     30        printf("LoadCheckpointFunctor Echo:\n");
     31        printf("   pmarshalled_data: %p\n",pmarshalled_data);
     32}/*}}}*/
     33void LoadCheckpointFunctor::call(char* & value){/*{{{*/
     34        int size;
     35        this->call(size);
     36        this->call(value,size);
     37};/*}}}*/
     38
     39SizeCheckpointFunctor::SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE){/*{{{*/
     40        this->marshalled_data_size = 0;
     41}/*}}}*/
     42int  SizeCheckpointFunctor::MarshalledSize(void){/*{{{*/
     43        return this->marshalled_data_size;
     44};/*}}}*/
     45void SizeCheckpointFunctor::Echo(void){/*{{{*/
     46        printf("SizeCheckpointFunctor Echo:\n");
     47        printf("   marshalled_data_size: %i\n",marshalled_data_size);
     48}/*}}}*/
     49void SizeCheckpointFunctor::call(char* & value){/*{{{*/
     50        int size = strlen(value)+1;
     51        this->call(size);
     52        this->call(value,size);
     53};/*}}}*/
     54
     55#if defined(_HAVE_CODIPACK_) && !defined(_WRAPPERS_)
     56CountDoublesFunctor::CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES){/*{{{*/
     57        this->double_count= 0;
     58}/*}}}*/
     59int  CountDoublesFunctor::DoubleCount(void){/*{{{*/
     60        return this->double_count;
     61};/*}}}*/
     62void CountDoublesFunctor::Echo(void){/*{{{*/
     63        printf("CountDoublesFunctor Echo:\n");
     64        printf("   double_count: %i\n",double_count);
     65}/*}}}*/
     66void CountDoublesFunctor::call(IssmDouble value){/*{{{*/
     67        this->double_count++;
     68}/*}}}*/
     69void CountDoublesFunctor::call(IssmDouble* value,int size){/*{{{*/
     70        if(value) this->double_count+= size;
     71}/*}}}*/
     72
     73RegisterInputFunctor::RegisterInputFunctor(int* identifiers_in,int size_max_in) : MarshallHandle(AD_REGISTERINPUT){/*{{{*/
     74        this->double_count = 0;
     75        this->identifiers  = identifiers_in;
     76        this->size_max         = size_max_in;
     77        this->tape_codi    = &(IssmDouble::getGlobalTape());
     78}/*}}}*/
     79void RegisterInputFunctor::Echo(void){/*{{{*/
     80        printf("RegisterInputFunctor Echo:\n");
     81        printf("   double_count: %i\n",double_count);
     82}/*}}}*/
     83void RegisterInputFunctor::call(IssmDouble value){/*{{{*/
     84        _assert_(this->double_count<size_max);
     85        this->tape_codi->registerInput(value);
     86        this->identifiers[this->double_count] = value.getGradientData();
     87        this->double_count++;
     88}/*}}}*/
     89void RegisterInputFunctor::call(IssmDouble* value,int size){/*{{{*/
     90        if(value){
     91                for(int i=0;i<size;i++){
     92                        _assert_(this->double_count<size_max);
     93                        this->tape_codi->registerInput(value[i]);
     94                        this->identifiers[this->double_count] = value[i].getGradientData();
     95                        this->double_count++;
     96                }
     97        }
     98}/*}}}*/
     99
     100RegisterOutputFunctor::RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){/*{{{*/
     101        this->double_count = 0;
     102        this->tape_codi    = &(IssmDouble::getGlobalTape());
     103}/*}}}*/
     104void RegisterOutputFunctor::Echo(void){/*{{{*/
     105        printf("RegisterOutputFunctor Echo:\n");
     106        printf("   double_count: %i\n",double_count);
     107}/*}}}*/
     108void RegisterOutputFunctor::call(IssmDouble value){/*{{{*/
     109        this->tape_codi->registerOutput(value);
     110        this->double_count++;
     111}/*}}}*/
     112void RegisterOutputFunctor::call(IssmDouble* value,int size){/*{{{*/
     113        if(value){
     114                for(int i=0;i<size;i++){
     115                        this->tape_codi->registerOutput(value[i]);
     116                        this->double_count++;
     117                }
     118        }
     119}/*}}}*/
     120
     121SetAdjointFunctor::SetAdjointFunctor(double* adjoint_in,int size_max_in) : MarshallHandle(AD_SETADJOINT){/*{{{*/
     122        this->double_count = 0;
     123        this->tape_codi    = &(IssmDouble::getGlobalTape());
     124        this->adjoint      = adjoint_in;
     125        this->size_max     = size_max_in;
     126}/*}}}*/
     127void SetAdjointFunctor::Echo(void){/*{{{*/
     128        printf("SetAdjointFunctor Echo:\n");
     129        printf("   double_count: %i\n",double_count);
     130}/*}}}*/
     131void SetAdjointFunctor::call(IssmDouble value){/*{{{*/
     132        _assert_(this->double_count<size_max);
     133        value.gradient() = this->adjoint[this->double_count];
     134        this->double_count++;
     135}/*}}}*/
     136void SetAdjointFunctor::call(IssmDouble* value,int size){/*{{{*/
     137        if(value){
     138                for(int i=0;i<size;i++){
     139                        _assert_(this->double_count<size_max);
     140                        value[i].gradient() = this->adjoint[this->double_count];
     141                        this->double_count++;
     142                }
     143        }
     144}/*}}}*/
     145#endif
  • ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h

     
    4141                char** pmarshalled_data;
    4242
    4343        public:
    44                 WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE),pmarshalled_data(pmarshalled_data_in){}
    45                 void Echo(void){
    46                         printf("WriteCheckpointFunctor Echo:\n");
    47                         printf("   pmarshalled_data: %p\n",pmarshalled_data);
    48                 }
     44                WriteCheckpointFunctor(char** pmarshalled_data_in);
     45                void Echo(void);
    4946                template<typename T> void call(T & value){
    5047                        memcpy(*pmarshalled_data,&value,sizeof(T));
    5148                        *pmarshalled_data+=sizeof(T);
    5249                }
    53                 void call(char* & value){
    54                         int size = strlen(value)+1;
    55                         this->call(size);
    56                         this->call(value,size);
    57                 };
     50                void call(char* & value);
    5851                template<typename T> void call(T* & value,int size){
    5952                        bool pointer_null = true;
    6053                        if(value) pointer_null = false;
     
    7164                char** pmarshalled_data;
    7265
    7366        public:
    74                 LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD),pmarshalled_data(pmarshalled_data_in){}
    75                 void Echo(void){
    76                         printf("LoadCheckpointFunctor Echo:\n");
    77                         printf("   pmarshalled_data: %p\n",pmarshalled_data);
    78                 }
     67                LoadCheckpointFunctor(char** pmarshalled_data_in);
     68                void Echo(void);
     69                void call(char* & value);
    7970                template<typename T> void call(T & value){
    8071                        memcpy(&value,*pmarshalled_data,sizeof(T));
    8172                        *pmarshalled_data+=sizeof(T);
    8273                }
    83                 void call(char* & value){
    84                         int size;
    85                         this->call(size);
    86                         this->call(value,size);
    87                 };
    8874                template<typename T> void call(T* & value,int size){
    8975                        bool pointer_null;
    9076                        call(pointer_null);
     
    10490                int marshalled_data_size;
    10591
    10692        public:
    107                 SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE),marshalled_data_size(0){}
    108                 int MarshalledSize(void){return this->marshalled_data_size;};
    109                 void Echo(void){
    110                         printf("SizeCheckpointFunctor Echo:\n");
    111                         printf("   marshalled_data_size: %i\n",marshalled_data_size);
    112                 }
     93                SizeCheckpointFunctor(void);
     94                int MarshalledSize(void);
     95                void Echo(void);
    11396                template<typename T> void call(T & value){
    11497                        marshalled_data_size+=sizeof(T);
    11598                }
    116                 void call(char* & value){
    117                         int size = strlen(value)+1;
    118                         this->call(size);
    119                         this->call(value,size);
    120                 };
     99                void call(char* & value);
    121100                template<typename T> void call(T* & value,int size){
    122101                        bool pointer_null = true;
    123102                        if(value) pointer_null = false;
     
    134113                int double_count;
    135114
    136115        public:
    137                 CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES),double_count(0){}
    138                 int DoubleCount(void){return this->double_count;};
    139                 void Echo(void){
    140                         printf("CountDoublesFunctor Echo:\n");
    141                         printf("   double_count: %i\n",double_count);
    142                 }
    143                 template<typename T> void call(T & value){
    144                         /*General case: do nothing*/
    145                 }
    146                 template<typename T> void call(T* & value,int size){
    147                         /*General case: do nothing*/
    148                 }
    149                 void call(IssmDouble value){
    150                         this->double_count++;
    151                 }
    152                 void call(IssmDouble* value,int size){
    153                         if(value) this->double_count+= size;
    154                 }
     116                CountDoublesFunctor(void);
     117                int  DoubleCount(void);
     118                void Echo(void);
     119                template<typename T> void call(T & value){/*General case: do nothing*/}
     120                template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
     121                void call(IssmDouble value);
     122                void call(IssmDouble* value,int size);
    155123}; /*}}}*/
    156124class RegisterInputFunctor:   public MarshallHandle{ /*{{{*/
    157125
    158126        private:
    159                 int   double_count;
    160                 int*  identifiers;
    161                 IssmDouble::TapeType* tape_codi;
     127                int  double_count;
     128                int *identifiers;
     129                int  size_max;
     130                IssmDouble::TapeType *tape_codi;
    162131
    163132        public:
    164                 RegisterInputFunctor(int* identifiers_in) : MarshallHandle(AD_REGISTERINPUT){
    165                         this->double_count = 0;
    166                         this->identifiers  = identifiers_in;
    167                         this->tape_codi    = &(IssmDouble::getGlobalTape());
    168                 }
    169                 void Echo(void){
    170                         printf("RegisterInputFunctor Echo:\n");
    171                         printf("   double_count: %i\n",double_count);
    172                 }
    173                 template<typename T> void call(T & value){
    174                         /*General case: do nothing*/
    175                 }
    176                 template<typename T> void call(T* & value,int size){
    177                         /*General case: do nothing*/
    178                 }
    179                 void call(IssmDouble value){
    180                         this->tape_codi->registerInput(value);
    181                         this->identifiers[this->double_count] = value.getGradientData();
    182                         this->double_count++;
    183                 }
    184                 void call(IssmDouble* value,int size){
    185                         if(value){
    186                                 for(int i=0;i<size;i++){
    187                                         this->tape_codi->registerInput(value[i]);
    188                                         this->identifiers[this->double_count] = value[i].getGradientData();
    189                                         this->double_count++;
    190                                 }
    191                         }
    192                 }
     133                RegisterInputFunctor(int* identifiers_in,int size_max_in);
     134                void Echo(void);
     135                template<typename T> void call(T & value){/*General case: do nothing*/}
     136                template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
     137                void call(IssmDouble value);
     138                void call(IssmDouble* value,int size);
    193139}; /*}}}*/
    194140class RegisterOutputFunctor:  public MarshallHandle{ /*{{{*/
    195141
     
    198144                IssmDouble::TapeType* tape_codi;
    199145
    200146        public:
    201                 RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){
    202                         this->double_count = 0;
    203                         this->tape_codi    = &(IssmDouble::getGlobalTape());
    204                 }
    205                 void Echo(void){
    206                         printf("RegisterOutputFunctor Echo:\n");
    207                         printf("   double_count: %i\n",double_count);
    208                 }
    209                 template<typename T> void call(T & value){
    210                         /*General case: do nothing*/
    211                 }
    212                 template<typename T> void call(T* & value,int size){
    213                         /*General case: do nothing*/
    214                 }
    215                 void call(IssmDouble value){
    216                         this->tape_codi->registerOutput(value);
    217                         this->double_count++;
    218                 }
    219                 void call(IssmDouble* value,int size){
    220                         if(value){
    221                                 for(int i=0;i<size;i++){
    222                                         this->tape_codi->registerOutput(value[i]);
    223                                         this->double_count++;
    224                                 }
    225                         }
    226                 }
     147                RegisterOutputFunctor(void);
     148                void Echo(void);
     149                template<typename T> void call(T & value){/*General case: do nothing*/}
     150                template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
     151                void call(IssmDouble value);
     152                void call(IssmDouble* value,int size);
    227153}; /*}}}*/
    228154class SetAdjointFunctor:      public MarshallHandle{ /*{{{*/
    229155
    230156        private:
    231157                int                   double_count;
     158                int                   size_max;
    232159                IssmDouble::TapeType* tape_codi;
    233160                double*               adjoint;
    234161
    235162        public:
    236                 SetAdjointFunctor(double* adjoint_in) : MarshallHandle(AD_SETADJOINT){
    237                         this->double_count = 0;
    238                         this->tape_codi    = &(IssmDouble::getGlobalTape());
    239                         this->adjoint      = adjoint_in;
    240                 }
    241                 void Echo(void){
    242                         printf("SetAdjointFunctor Echo:\n");
    243                         printf("   double_count: %i\n",double_count);
    244                 }
    245                 template<typename T> void call(T & value){
    246                         /*General case: do nothing*/
    247                 }
    248                 template<typename T> void call(T* & value,int size){
    249                         /*General case: do nothing*/
    250                 }
    251                 void call(IssmDouble value){
    252                         value.gradient() = this->adjoint[this->double_count];
    253                         this->double_count++;
    254                 }
    255                 void call(IssmDouble* value,int size){
    256                         if(value){
    257                                 for(int i=0;i<size;i++){
    258                                         value[i].gradient() = this->adjoint[this->double_count];
    259                                         this->double_count++;
    260                                 }
    261                         }
    262                 }
     163                SetAdjointFunctor(double* adjoint_in,int size_max_in);
     164                void Echo(void);
     165                template<typename T> void call(T & value){/*General case: do nothing*/}
     166                template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
     167                void call(IssmDouble value);
     168                void call(IssmDouble* value,int size);
    263169}; /*}}}*/
    264170#endif
    265171
     
    292198        }
    293199}
    294200
    295 #endif 
     201#endif
  • ../trunk-jpl/src/c/Makefile.am

     
    146146        ./shared/io/Print/PrintfFunction.cpp \
    147147        ./shared/io/Comm/IssmComm.cpp \
    148148        ./shared/io/Marshalling/IoCodeConversions.cpp \
     149        ./shared/io/Marshalling/Marshalling.cpp \
    149150        ./shared/LatLong/Ll2xyx.cpp \
    150151        ./shared/LatLong/Xy2llx.cpp \
    151152        ./shared/FSanalyticals/fsanalyticals.cpp \
Note: See TracBrowser for help on using the repository browser.