source:
issm/oecreview/Archive/24684-25833/ISSM-25529-25530.diff@
25834
Last change on this file since 25834 was 25834, checked in by , 4 years ago | |
---|---|
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 13 WriteCheckpointFunctor::WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE){/*{{{*/ 14 this->pmarshalled_data = pmarshalled_data_in; 15 }/*}}}*/ 16 void WriteCheckpointFunctor::Echo(void){/*{{{*/ 17 printf("WriteCheckpointFunctor Echo:\n"); 18 printf(" pmarshalled_data: %p\n",pmarshalled_data); 19 }/*}}}*/ 20 void WriteCheckpointFunctor::call(char* & value){/*{{{*/ 21 int size = strlen(value)+1; 22 this->call(size); 23 this->call(value,size); 24 };/*}}}*/ 25 26 LoadCheckpointFunctor::LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD){/*{{{*/ 27 this->pmarshalled_data = pmarshalled_data_in; 28 }/*}}}*/ 29 void LoadCheckpointFunctor::Echo(void){/*{{{*/ 30 printf("LoadCheckpointFunctor Echo:\n"); 31 printf(" pmarshalled_data: %p\n",pmarshalled_data); 32 }/*}}}*/ 33 void LoadCheckpointFunctor::call(char* & value){/*{{{*/ 34 int size; 35 this->call(size); 36 this->call(value,size); 37 };/*}}}*/ 38 39 SizeCheckpointFunctor::SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE){/*{{{*/ 40 this->marshalled_data_size = 0; 41 }/*}}}*/ 42 int SizeCheckpointFunctor::MarshalledSize(void){/*{{{*/ 43 return this->marshalled_data_size; 44 };/*}}}*/ 45 void SizeCheckpointFunctor::Echo(void){/*{{{*/ 46 printf("SizeCheckpointFunctor Echo:\n"); 47 printf(" marshalled_data_size: %i\n",marshalled_data_size); 48 }/*}}}*/ 49 void 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_) 56 CountDoublesFunctor::CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES){/*{{{*/ 57 this->double_count= 0; 58 }/*}}}*/ 59 int CountDoublesFunctor::DoubleCount(void){/*{{{*/ 60 return this->double_count; 61 };/*}}}*/ 62 void CountDoublesFunctor::Echo(void){/*{{{*/ 63 printf("CountDoublesFunctor Echo:\n"); 64 printf(" double_count: %i\n",double_count); 65 }/*}}}*/ 66 void CountDoublesFunctor::call(IssmDouble value){/*{{{*/ 67 this->double_count++; 68 }/*}}}*/ 69 void CountDoublesFunctor::call(IssmDouble* value,int size){/*{{{*/ 70 if(value) this->double_count+= size; 71 }/*}}}*/ 72 73 RegisterInputFunctor::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 }/*}}}*/ 79 void RegisterInputFunctor::Echo(void){/*{{{*/ 80 printf("RegisterInputFunctor Echo:\n"); 81 printf(" double_count: %i\n",double_count); 82 }/*}}}*/ 83 void 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 }/*}}}*/ 89 void 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 100 RegisterOutputFunctor::RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){/*{{{*/ 101 this->double_count = 0; 102 this->tape_codi = &(IssmDouble::getGlobalTape()); 103 }/*}}}*/ 104 void RegisterOutputFunctor::Echo(void){/*{{{*/ 105 printf("RegisterOutputFunctor Echo:\n"); 106 printf(" double_count: %i\n",double_count); 107 }/*}}}*/ 108 void RegisterOutputFunctor::call(IssmDouble value){/*{{{*/ 109 this->tape_codi->registerOutput(value); 110 this->double_count++; 111 }/*}}}*/ 112 void 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 121 SetAdjointFunctor::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 }/*}}}*/ 127 void SetAdjointFunctor::Echo(void){/*{{{*/ 128 printf("SetAdjointFunctor Echo:\n"); 129 printf(" double_count: %i\n",double_count); 130 }/*}}}*/ 131 void SetAdjointFunctor::call(IssmDouble value){/*{{{*/ 132 _assert_(this->double_count<size_max); 133 value.gradient() = this->adjoint[this->double_count]; 134 this->double_count++; 135 }/*}}}*/ 136 void 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
41 41 char** pmarshalled_data; 42 42 43 43 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); 49 46 template<typename T> void call(T & value){ 50 47 memcpy(*pmarshalled_data,&value,sizeof(T)); 51 48 *pmarshalled_data+=sizeof(T); 52 49 } 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); 58 51 template<typename T> void call(T* & value,int size){ 59 52 bool pointer_null = true; 60 53 if(value) pointer_null = false; … … 71 64 char** pmarshalled_data; 72 65 73 66 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); 79 70 template<typename T> void call(T & value){ 80 71 memcpy(&value,*pmarshalled_data,sizeof(T)); 81 72 *pmarshalled_data+=sizeof(T); 82 73 } 83 void call(char* & value){84 int size;85 this->call(size);86 this->call(value,size);87 };88 74 template<typename T> void call(T* & value,int size){ 89 75 bool pointer_null; 90 76 call(pointer_null); … … 104 90 int marshalled_data_size; 105 91 106 92 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); 113 96 template<typename T> void call(T & value){ 114 97 marshalled_data_size+=sizeof(T); 115 98 } 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); 121 100 template<typename T> void call(T* & value,int size){ 122 101 bool pointer_null = true; 123 102 if(value) pointer_null = false; … … 134 113 int double_count; 135 114 136 115 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); 155 123 }; /*}}}*/ 156 124 class RegisterInputFunctor: public MarshallHandle{ /*{{{*/ 157 125 158 126 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; 162 131 163 132 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); 193 139 }; /*}}}*/ 194 140 class RegisterOutputFunctor: public MarshallHandle{ /*{{{*/ 195 141 … … 198 144 IssmDouble::TapeType* tape_codi; 199 145 200 146 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); 227 153 }; /*}}}*/ 228 154 class SetAdjointFunctor: public MarshallHandle{ /*{{{*/ 229 155 230 156 private: 231 157 int double_count; 158 int size_max; 232 159 IssmDouble::TapeType* tape_codi; 233 160 double* adjoint; 234 161 235 162 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); 263 169 }; /*}}}*/ 264 170 #endif 265 171 … … 292 198 } 293 199 } 294 200 295 #endif 201 #endif -
../trunk-jpl/src/c/Makefile.am
146 146 ./shared/io/Print/PrintfFunction.cpp \ 147 147 ./shared/io/Comm/IssmComm.cpp \ 148 148 ./shared/io/Marshalling/IoCodeConversions.cpp \ 149 ./shared/io/Marshalling/Marshalling.cpp \ 149 150 ./shared/LatLong/Ll2xyx.cpp \ 150 151 ./shared/LatLong/Xy2llx.cpp \ 151 152 ./shared/FSanalyticals/fsanalyticals.cpp \
Note:
See TracBrowser
for help on using the repository browser.