Changeset 25509
- Timestamp:
- 09/01/20 15:18:50 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h
r25507 r25509 16 16 MARSHALLING_LOAD, 17 17 MARSHALLING_SIZE, 18 #ifdef _HAVE_CODIPACK_ 19 AD_COUNTDOUBLES, 20 AD_REGISTERINPUT, 21 AD_SETADJOINT, 22 #endif 18 23 }; 19 24 20 25 /*Define virtual Marshall Handle*/ 21 class MarshallHandle{ 26 class MarshallHandle{ /*{{{*/ 22 27 public: 23 28 MarshallOpEnum operation_enum; … … 28 33 template<typename T> void call(T & value); 29 34 template<typename T> void call(T* & value,int size); 30 }; 31 32 /*Make sure to pass all fields by reference!*/33 class WriteCheckpointFunctor: public MarshallHandle{ 34 p ublic:35 }; /*}}}*/ 36 /* !! Make sure to pass all fields by reference !! */ 37 class WriteCheckpointFunctor: public MarshallHandle{ /*{{{*/ 38 39 private: 35 40 char** pmarshalled_data; 41 42 public: 36 43 WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE),pmarshalled_data(pmarshalled_data_in){} 37 44 template<typename T> void call(T & value){ … … 52 59 } 53 60 } 54 }; 55 56 class LoadCheckpointFunctor: public MarshallHandle{ 57 p ublic:61 };/*}}}*/ 62 class LoadCheckpointFunctor: public MarshallHandle{ /*{{{*/ 63 64 private: 58 65 char** pmarshalled_data; 66 67 public: 59 68 LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD),pmarshalled_data(pmarshalled_data_in){} 60 69 void Echo(void){ … … 78 87 } 79 88 } 80 }; 81 82 class SizeCheckpointFunctor: public MarshallHandle{ 83 p ublic:89 };/*}}}*/ 90 class SizeCheckpointFunctor: public MarshallHandle{ /*{{{*/ 91 92 private: 84 93 int marshalled_data_size; 94 95 public: 85 96 SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE),marshalled_data_size(0){} 86 97 int MarshalledSize(void){return this->marshalled_data_size;}; … … 100 111 } 101 112 } 102 }; 113 };/*}}}*/ 114 #ifdef _HAVE_CODIPACK_ 115 class CountDoublesFunctor: public MarshallHandle{ /*{{{*/ 116 117 private: 118 int double_count; 119 120 public: 121 CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES),double_count(0){} 122 int DoubleCount(void){return this->double_count;}; 123 void Echo(void){ 124 printf("CountDoublesFunctor Echo:\n"); 125 printf(" double_count: %i\n",double_count); 126 } 127 template<typename T> void call(T & value){ 128 /*General case: do nothing*/ 129 } 130 template<typename T> void call(T* & value,int size){ 131 /*General case: do nothing*/ 132 } 133 void call(IssmDouble value){ 134 this->double_count++; 135 } 136 void call(IssmDouble* value,int size){ 137 if(value) this->double_count+= size; 138 } 139 }; /*}}}*/ 140 class RegisterInputFunctor: public MarshallHandle{ /*{{{*/ 141 142 private: 143 int double_count; 144 int* identifiers; 145 auto* tape_codi; 146 147 public: 148 RegisterInputFunctor(auto* tape_in,int* identifiers_in) : MarshallHandle(AD_REGISTERINPUT),double_count(0),identifiers(identifiers_in),tape_codi(tape_in)){} 149 int DoubleCount(void){return this->double_count;}; 150 void Echo(void){ 151 printf("RegisterInputFunctor Echo:\n"); 152 printf(" double_count: %i\n",double_count); 153 } 154 template<typename T> void call(T & value){ 155 /*General case: do nothing*/ 156 } 157 template<typename T> void call(T* & value,int size){ 158 /*General case: do nothing*/ 159 } 160 void call(IssmDouble value){ 161 this->tape_codi->registerInput(value); 162 this->identifiers[this->double_count] = value.getGradientData(); 163 this->double_count++; 164 } 165 void call(IssmDouble* value,int size){ 166 if(value){ 167 for(int i=0;i<size;i++){ 168 this->tape_codi->registerInput(value[i]); 169 this->identifiers[this->double_count] = value[i].getGradientData(); 170 this->double_count++; 171 } 172 } 173 } 174 }; /*}}}*/ 175 #endif 103 176 104 177 template<typename T> void MarshallHandle::call(T & value){ … … 107 180 case MARSHALLING_LOAD: {LoadCheckpointFunctor* temp = xDynamicCast<LoadCheckpointFunctor*>(this); temp->call(value); break;} 108 181 case MARSHALLING_SIZE: {SizeCheckpointFunctor* temp = xDynamicCast<SizeCheckpointFunctor*>(this); temp->call(value); break;} 109 default: _error_("not supported yet"); 182 #ifdef _HAVE_CODIPACK_ 183 case AD_COUNTDOUBLES: {CountDoublesFunctor* temp = xDynamicCast<CountDoublesFunctor*>(this); temp->call(value); break;} 184 case AD_REGISTERINPUT: {RegisterInputFunctor* temp = xDynamicCast<RegisterInputFunctor*>(this); temp->call(value); break;} 185 //case AD_SETADJOINT: {SetAdjointFunction* temp = xDynamicCast<SetAdjointFunction*>(this); temp->call(value); break;} 186 #endif 187 default: _error_("Operation "<<OperationNumber()<<" not supported yet"); 110 188 } 111 189 } … … 115 193 case MARSHALLING_LOAD: {LoadCheckpointFunctor* temp = xDynamicCast<LoadCheckpointFunctor*>(this); temp->call(value,size); break;} 116 194 case MARSHALLING_SIZE: {SizeCheckpointFunctor* temp = xDynamicCast<SizeCheckpointFunctor*>(this); temp->call(value,size); break;} 117 default: _error_("not supported yet"); 195 #ifdef _HAVE_CODIPACK_ 196 case AD_COUNTDOUBLES: {CountDoublesFunctor* temp = xDynamicCast<CountDoublesFunctor*>(this); temp->call(value,size); break;} 197 case AD_REGISTERINPUT: {RegisterInputFunctor* temp = xDynamicCast<RegisterInputFunctor*>(this); temp->call(value,size); break;} 198 //case AD_SETADJOINT: {SetAdjointFunction* temp = xDynamicCast<SetAdjointFunction*>(this); temp->call(value,size); break;} 199 #endif 200 default: _error_("Operation "<<OperationNumber() <<" not supported yet"); 118 201 } 119 202 }
Note:
See TracChangeset
for help on using the changeset viewer.