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
RevLine 
[25834]1Index: ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp
2===================================================================
3--- ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp (nonexistent)
4+++ ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp (revision 25530)
5@@ -0,0 +1,145 @@
6+/*!\file: Marshalling.cpp
7+ * \brief implement marshall
8+ */
9+
10+#ifdef HAVE_CONFIG_H
11+#include <config.h>
12+#else
13+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
14+#endif
15+
16+#include "./Marshalling.h"
17+
18+WriteCheckpointFunctor::WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE){/*{{{*/
19+ this->pmarshalled_data = pmarshalled_data_in;
20+}/*}}}*/
21+void WriteCheckpointFunctor::Echo(void){/*{{{*/
22+ printf("WriteCheckpointFunctor Echo:\n");
23+ printf(" pmarshalled_data: %p\n",pmarshalled_data);
24+}/*}}}*/
25+void WriteCheckpointFunctor::call(char* & value){/*{{{*/
26+ int size = strlen(value)+1;
27+ this->call(size);
28+ this->call(value,size);
29+};/*}}}*/
30+
31+LoadCheckpointFunctor::LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD){/*{{{*/
32+ this->pmarshalled_data = pmarshalled_data_in;
33+}/*}}}*/
34+void LoadCheckpointFunctor::Echo(void){/*{{{*/
35+ printf("LoadCheckpointFunctor Echo:\n");
36+ printf(" pmarshalled_data: %p\n",pmarshalled_data);
37+}/*}}}*/
38+void LoadCheckpointFunctor::call(char* & value){/*{{{*/
39+ int size;
40+ this->call(size);
41+ this->call(value,size);
42+};/*}}}*/
43+
44+SizeCheckpointFunctor::SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE){/*{{{*/
45+ this->marshalled_data_size = 0;
46+}/*}}}*/
47+int SizeCheckpointFunctor::MarshalledSize(void){/*{{{*/
48+ return this->marshalled_data_size;
49+};/*}}}*/
50+void SizeCheckpointFunctor::Echo(void){/*{{{*/
51+ printf("SizeCheckpointFunctor Echo:\n");
52+ printf(" marshalled_data_size: %i\n",marshalled_data_size);
53+}/*}}}*/
54+void SizeCheckpointFunctor::call(char* & value){/*{{{*/
55+ int size = strlen(value)+1;
56+ this->call(size);
57+ this->call(value,size);
58+};/*}}}*/
59+
60+#if defined(_HAVE_CODIPACK_) && !defined(_WRAPPERS_)
61+CountDoublesFunctor::CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES){/*{{{*/
62+ this->double_count= 0;
63+}/*}}}*/
64+int CountDoublesFunctor::DoubleCount(void){/*{{{*/
65+ return this->double_count;
66+};/*}}}*/
67+void CountDoublesFunctor::Echo(void){/*{{{*/
68+ printf("CountDoublesFunctor Echo:\n");
69+ printf(" double_count: %i\n",double_count);
70+}/*}}}*/
71+void CountDoublesFunctor::call(IssmDouble value){/*{{{*/
72+ this->double_count++;
73+}/*}}}*/
74+void CountDoublesFunctor::call(IssmDouble* value,int size){/*{{{*/
75+ if(value) this->double_count+= size;
76+}/*}}}*/
77+
78+RegisterInputFunctor::RegisterInputFunctor(int* identifiers_in,int size_max_in) : MarshallHandle(AD_REGISTERINPUT){/*{{{*/
79+ this->double_count = 0;
80+ this->identifiers = identifiers_in;
81+ this->size_max = size_max_in;
82+ this->tape_codi = &(IssmDouble::getGlobalTape());
83+}/*}}}*/
84+void RegisterInputFunctor::Echo(void){/*{{{*/
85+ printf("RegisterInputFunctor Echo:\n");
86+ printf(" double_count: %i\n",double_count);
87+}/*}}}*/
88+void RegisterInputFunctor::call(IssmDouble value){/*{{{*/
89+ _assert_(this->double_count<size_max);
90+ this->tape_codi->registerInput(value);
91+ this->identifiers[this->double_count] = value.getGradientData();
92+ this->double_count++;
93+}/*}}}*/
94+void RegisterInputFunctor::call(IssmDouble* value,int size){/*{{{*/
95+ if(value){
96+ for(int i=0;i<size;i++){
97+ _assert_(this->double_count<size_max);
98+ this->tape_codi->registerInput(value[i]);
99+ this->identifiers[this->double_count] = value[i].getGradientData();
100+ this->double_count++;
101+ }
102+ }
103+}/*}}}*/
104+
105+RegisterOutputFunctor::RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){/*{{{*/
106+ this->double_count = 0;
107+ this->tape_codi = &(IssmDouble::getGlobalTape());
108+}/*}}}*/
109+void RegisterOutputFunctor::Echo(void){/*{{{*/
110+ printf("RegisterOutputFunctor Echo:\n");
111+ printf(" double_count: %i\n",double_count);
112+}/*}}}*/
113+void RegisterOutputFunctor::call(IssmDouble value){/*{{{*/
114+ this->tape_codi->registerOutput(value);
115+ this->double_count++;
116+}/*}}}*/
117+void RegisterOutputFunctor::call(IssmDouble* value,int size){/*{{{*/
118+ if(value){
119+ for(int i=0;i<size;i++){
120+ this->tape_codi->registerOutput(value[i]);
121+ this->double_count++;
122+ }
123+ }
124+}/*}}}*/
125+
126+SetAdjointFunctor::SetAdjointFunctor(double* adjoint_in,int size_max_in) : MarshallHandle(AD_SETADJOINT){/*{{{*/
127+ this->double_count = 0;
128+ this->tape_codi = &(IssmDouble::getGlobalTape());
129+ this->adjoint = adjoint_in;
130+ this->size_max = size_max_in;
131+}/*}}}*/
132+void SetAdjointFunctor::Echo(void){/*{{{*/
133+ printf("SetAdjointFunctor Echo:\n");
134+ printf(" double_count: %i\n",double_count);
135+}/*}}}*/
136+void SetAdjointFunctor::call(IssmDouble value){/*{{{*/
137+ _assert_(this->double_count<size_max);
138+ value.gradient() = this->adjoint[this->double_count];
139+ this->double_count++;
140+}/*}}}*/
141+void SetAdjointFunctor::call(IssmDouble* value,int size){/*{{{*/
142+ if(value){
143+ for(int i=0;i<size;i++){
144+ _assert_(this->double_count<size_max);
145+ value[i].gradient() = this->adjoint[this->double_count];
146+ this->double_count++;
147+ }
148+ }
149+}/*}}}*/
150+#endif
151Index: ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h
152===================================================================
153--- ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h (revision 25529)
154+++ ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h (revision 25530)
155@@ -41,20 +41,13 @@
156 char** pmarshalled_data;
157
158 public:
159- WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE),pmarshalled_data(pmarshalled_data_in){}
160- void Echo(void){
161- printf("WriteCheckpointFunctor Echo:\n");
162- printf(" pmarshalled_data: %p\n",pmarshalled_data);
163- }
164+ WriteCheckpointFunctor(char** pmarshalled_data_in);
165+ void Echo(void);
166 template<typename T> void call(T & value){
167 memcpy(*pmarshalled_data,&value,sizeof(T));
168 *pmarshalled_data+=sizeof(T);
169 }
170- void call(char* & value){
171- int size = strlen(value)+1;
172- this->call(size);
173- this->call(value,size);
174- };
175+ void call(char* & value);
176 template<typename T> void call(T* & value,int size){
177 bool pointer_null = true;
178 if(value) pointer_null = false;
179@@ -71,20 +64,13 @@
180 char** pmarshalled_data;
181
182 public:
183- LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD),pmarshalled_data(pmarshalled_data_in){}
184- void Echo(void){
185- printf("LoadCheckpointFunctor Echo:\n");
186- printf(" pmarshalled_data: %p\n",pmarshalled_data);
187- }
188+ LoadCheckpointFunctor(char** pmarshalled_data_in);
189+ void Echo(void);
190+ void call(char* & value);
191 template<typename T> void call(T & value){
192 memcpy(&value,*pmarshalled_data,sizeof(T));
193 *pmarshalled_data+=sizeof(T);
194 }
195- void call(char* & value){
196- int size;
197- this->call(size);
198- this->call(value,size);
199- };
200 template<typename T> void call(T* & value,int size){
201 bool pointer_null;
202 call(pointer_null);
203@@ -104,20 +90,13 @@
204 int marshalled_data_size;
205
206 public:
207- SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE),marshalled_data_size(0){}
208- int MarshalledSize(void){return this->marshalled_data_size;};
209- void Echo(void){
210- printf("SizeCheckpointFunctor Echo:\n");
211- printf(" marshalled_data_size: %i\n",marshalled_data_size);
212- }
213+ SizeCheckpointFunctor(void);
214+ int MarshalledSize(void);
215+ void Echo(void);
216 template<typename T> void call(T & value){
217 marshalled_data_size+=sizeof(T);
218 }
219- void call(char* & value){
220- int size = strlen(value)+1;
221- this->call(size);
222- this->call(value,size);
223- };
224+ void call(char* & value);
225 template<typename T> void call(T* & value,int size){
226 bool pointer_null = true;
227 if(value) pointer_null = false;
228@@ -134,62 +113,29 @@
229 int double_count;
230
231 public:
232- CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES),double_count(0){}
233- int DoubleCount(void){return this->double_count;};
234- void Echo(void){
235- printf("CountDoublesFunctor Echo:\n");
236- printf(" double_count: %i\n",double_count);
237- }
238- template<typename T> void call(T & value){
239- /*General case: do nothing*/
240- }
241- template<typename T> void call(T* & value,int size){
242- /*General case: do nothing*/
243- }
244- void call(IssmDouble value){
245- this->double_count++;
246- }
247- void call(IssmDouble* value,int size){
248- if(value) this->double_count+= size;
249- }
250+ CountDoublesFunctor(void);
251+ int DoubleCount(void);
252+ void Echo(void);
253+ template<typename T> void call(T & value){/*General case: do nothing*/}
254+ template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
255+ void call(IssmDouble value);
256+ void call(IssmDouble* value,int size);
257 }; /*}}}*/
258 class RegisterInputFunctor: public MarshallHandle{ /*{{{*/
259
260 private:
261- int double_count;
262- int* identifiers;
263- IssmDouble::TapeType* tape_codi;
264+ int double_count;
265+ int *identifiers;
266+ int size_max;
267+ IssmDouble::TapeType *tape_codi;
268
269 public:
270- RegisterInputFunctor(int* identifiers_in) : MarshallHandle(AD_REGISTERINPUT){
271- this->double_count = 0;
272- this->identifiers = identifiers_in;
273- this->tape_codi = &(IssmDouble::getGlobalTape());
274- }
275- void Echo(void){
276- printf("RegisterInputFunctor Echo:\n");
277- printf(" double_count: %i\n",double_count);
278- }
279- template<typename T> void call(T & value){
280- /*General case: do nothing*/
281- }
282- template<typename T> void call(T* & value,int size){
283- /*General case: do nothing*/
284- }
285- void call(IssmDouble value){
286- this->tape_codi->registerInput(value);
287- this->identifiers[this->double_count] = value.getGradientData();
288- this->double_count++;
289- }
290- void call(IssmDouble* value,int size){
291- if(value){
292- for(int i=0;i<size;i++){
293- this->tape_codi->registerInput(value[i]);
294- this->identifiers[this->double_count] = value[i].getGradientData();
295- this->double_count++;
296- }
297- }
298- }
299+ RegisterInputFunctor(int* identifiers_in,int size_max_in);
300+ void Echo(void);
301+ template<typename T> void call(T & value){/*General case: do nothing*/}
302+ template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
303+ void call(IssmDouble value);
304+ void call(IssmDouble* value,int size);
305 }; /*}}}*/
306 class RegisterOutputFunctor: public MarshallHandle{ /*{{{*/
307
308@@ -198,68 +144,28 @@
309 IssmDouble::TapeType* tape_codi;
310
311 public:
312- RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){
313- this->double_count = 0;
314- this->tape_codi = &(IssmDouble::getGlobalTape());
315- }
316- void Echo(void){
317- printf("RegisterOutputFunctor Echo:\n");
318- printf(" double_count: %i\n",double_count);
319- }
320- template<typename T> void call(T & value){
321- /*General case: do nothing*/
322- }
323- template<typename T> void call(T* & value,int size){
324- /*General case: do nothing*/
325- }
326- void call(IssmDouble value){
327- this->tape_codi->registerOutput(value);
328- this->double_count++;
329- }
330- void call(IssmDouble* value,int size){
331- if(value){
332- for(int i=0;i<size;i++){
333- this->tape_codi->registerOutput(value[i]);
334- this->double_count++;
335- }
336- }
337- }
338+ RegisterOutputFunctor(void);
339+ void Echo(void);
340+ template<typename T> void call(T & value){/*General case: do nothing*/}
341+ template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
342+ void call(IssmDouble value);
343+ void call(IssmDouble* value,int size);
344 }; /*}}}*/
345 class SetAdjointFunctor: public MarshallHandle{ /*{{{*/
346
347 private:
348 int double_count;
349+ int size_max;
350 IssmDouble::TapeType* tape_codi;
351 double* adjoint;
352
353 public:
354- SetAdjointFunctor(double* adjoint_in) : MarshallHandle(AD_SETADJOINT){
355- this->double_count = 0;
356- this->tape_codi = &(IssmDouble::getGlobalTape());
357- this->adjoint = adjoint_in;
358- }
359- void Echo(void){
360- printf("SetAdjointFunctor Echo:\n");
361- printf(" double_count: %i\n",double_count);
362- }
363- template<typename T> void call(T & value){
364- /*General case: do nothing*/
365- }
366- template<typename T> void call(T* & value,int size){
367- /*General case: do nothing*/
368- }
369- void call(IssmDouble value){
370- value.gradient() = this->adjoint[this->double_count];
371- this->double_count++;
372- }
373- void call(IssmDouble* value,int size){
374- if(value){
375- for(int i=0;i<size;i++){
376- value[i].gradient() = this->adjoint[this->double_count];
377- this->double_count++;
378- }
379- }
380- }
381+ SetAdjointFunctor(double* adjoint_in,int size_max_in);
382+ void Echo(void);
383+ template<typename T> void call(T & value){/*General case: do nothing*/}
384+ template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
385+ void call(IssmDouble value);
386+ void call(IssmDouble* value,int size);
387 }; /*}}}*/
388 #endif
389
390@@ -292,4 +198,4 @@
391 }
392 }
393
394-#endif
395+#endif
396Index: ../trunk-jpl/src/c/Makefile.am
397===================================================================
398--- ../trunk-jpl/src/c/Makefile.am (revision 25529)
399+++ ../trunk-jpl/src/c/Makefile.am (revision 25530)
400@@ -146,6 +146,7 @@
401 ./shared/io/Print/PrintfFunction.cpp \
402 ./shared/io/Comm/IssmComm.cpp \
403 ./shared/io/Marshalling/IoCodeConversions.cpp \
404+ ./shared/io/Marshalling/Marshalling.cpp \
405 ./shared/LatLong/Ll2xyx.cpp \
406 ./shared/LatLong/Xy2llx.cpp \
407 ./shared/FSanalyticals/fsanalyticals.cpp \
Note: See TracBrowser for help on using the repository browser.