Index: ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp =================================================================== --- ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp (nonexistent) +++ ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp (revision 25530) @@ -0,0 +1,145 @@ +/*!\file: Marshalling.cpp + * \brief implement marshall + */ + +#ifdef HAVE_CONFIG_H +#include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include "./Marshalling.h" + +WriteCheckpointFunctor::WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE){/*{{{*/ + this->pmarshalled_data = pmarshalled_data_in; +}/*}}}*/ +void WriteCheckpointFunctor::Echo(void){/*{{{*/ + printf("WriteCheckpointFunctor Echo:\n"); + printf(" pmarshalled_data: %p\n",pmarshalled_data); +}/*}}}*/ +void WriteCheckpointFunctor::call(char* & value){/*{{{*/ + int size = strlen(value)+1; + this->call(size); + this->call(value,size); +};/*}}}*/ + +LoadCheckpointFunctor::LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD){/*{{{*/ + this->pmarshalled_data = pmarshalled_data_in; +}/*}}}*/ +void LoadCheckpointFunctor::Echo(void){/*{{{*/ + printf("LoadCheckpointFunctor Echo:\n"); + printf(" pmarshalled_data: %p\n",pmarshalled_data); +}/*}}}*/ +void LoadCheckpointFunctor::call(char* & value){/*{{{*/ + int size; + this->call(size); + this->call(value,size); +};/*}}}*/ + +SizeCheckpointFunctor::SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE){/*{{{*/ + this->marshalled_data_size = 0; +}/*}}}*/ +int SizeCheckpointFunctor::MarshalledSize(void){/*{{{*/ + return this->marshalled_data_size; +};/*}}}*/ +void SizeCheckpointFunctor::Echo(void){/*{{{*/ + printf("SizeCheckpointFunctor Echo:\n"); + printf(" marshalled_data_size: %i\n",marshalled_data_size); +}/*}}}*/ +void SizeCheckpointFunctor::call(char* & value){/*{{{*/ + int size = strlen(value)+1; + this->call(size); + this->call(value,size); +};/*}}}*/ + +#if defined(_HAVE_CODIPACK_) && !defined(_WRAPPERS_) +CountDoublesFunctor::CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES){/*{{{*/ + this->double_count= 0; +}/*}}}*/ +int CountDoublesFunctor::DoubleCount(void){/*{{{*/ + return this->double_count; +};/*}}}*/ +void CountDoublesFunctor::Echo(void){/*{{{*/ + printf("CountDoublesFunctor Echo:\n"); + printf(" double_count: %i\n",double_count); +}/*}}}*/ +void CountDoublesFunctor::call(IssmDouble value){/*{{{*/ + this->double_count++; +}/*}}}*/ +void CountDoublesFunctor::call(IssmDouble* value,int size){/*{{{*/ + if(value) this->double_count+= size; +}/*}}}*/ + +RegisterInputFunctor::RegisterInputFunctor(int* identifiers_in,int size_max_in) : MarshallHandle(AD_REGISTERINPUT){/*{{{*/ + this->double_count = 0; + this->identifiers = identifiers_in; + this->size_max = size_max_in; + this->tape_codi = &(IssmDouble::getGlobalTape()); +}/*}}}*/ +void RegisterInputFunctor::Echo(void){/*{{{*/ + printf("RegisterInputFunctor Echo:\n"); + printf(" double_count: %i\n",double_count); +}/*}}}*/ +void RegisterInputFunctor::call(IssmDouble value){/*{{{*/ + _assert_(this->double_counttape_codi->registerInput(value); + this->identifiers[this->double_count] = value.getGradientData(); + this->double_count++; +}/*}}}*/ +void RegisterInputFunctor::call(IssmDouble* value,int size){/*{{{*/ + if(value){ + for(int i=0;idouble_counttape_codi->registerInput(value[i]); + this->identifiers[this->double_count] = value[i].getGradientData(); + this->double_count++; + } + } +}/*}}}*/ + +RegisterOutputFunctor::RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){/*{{{*/ + this->double_count = 0; + this->tape_codi = &(IssmDouble::getGlobalTape()); +}/*}}}*/ +void RegisterOutputFunctor::Echo(void){/*{{{*/ + printf("RegisterOutputFunctor Echo:\n"); + printf(" double_count: %i\n",double_count); +}/*}}}*/ +void RegisterOutputFunctor::call(IssmDouble value){/*{{{*/ + this->tape_codi->registerOutput(value); + this->double_count++; +}/*}}}*/ +void RegisterOutputFunctor::call(IssmDouble* value,int size){/*{{{*/ + if(value){ + for(int i=0;itape_codi->registerOutput(value[i]); + this->double_count++; + } + } +}/*}}}*/ + +SetAdjointFunctor::SetAdjointFunctor(double* adjoint_in,int size_max_in) : MarshallHandle(AD_SETADJOINT){/*{{{*/ + this->double_count = 0; + this->tape_codi = &(IssmDouble::getGlobalTape()); + this->adjoint = adjoint_in; + this->size_max = size_max_in; +}/*}}}*/ +void SetAdjointFunctor::Echo(void){/*{{{*/ + printf("SetAdjointFunctor Echo:\n"); + printf(" double_count: %i\n",double_count); +}/*}}}*/ +void SetAdjointFunctor::call(IssmDouble value){/*{{{*/ + _assert_(this->double_countadjoint[this->double_count]; + this->double_count++; +}/*}}}*/ +void SetAdjointFunctor::call(IssmDouble* value,int size){/*{{{*/ + if(value){ + for(int i=0;idouble_countadjoint[this->double_count]; + this->double_count++; + } + } +}/*}}}*/ +#endif Index: ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h =================================================================== --- ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h (revision 25529) +++ ../trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h (revision 25530) @@ -41,20 +41,13 @@ char** pmarshalled_data; public: - WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE),pmarshalled_data(pmarshalled_data_in){} - void Echo(void){ - printf("WriteCheckpointFunctor Echo:\n"); - printf(" pmarshalled_data: %p\n",pmarshalled_data); - } + WriteCheckpointFunctor(char** pmarshalled_data_in); + void Echo(void); template void call(T & value){ memcpy(*pmarshalled_data,&value,sizeof(T)); *pmarshalled_data+=sizeof(T); } - void call(char* & value){ - int size = strlen(value)+1; - this->call(size); - this->call(value,size); - }; + void call(char* & value); template void call(T* & value,int size){ bool pointer_null = true; if(value) pointer_null = false; @@ -71,20 +64,13 @@ char** pmarshalled_data; public: - LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD),pmarshalled_data(pmarshalled_data_in){} - void Echo(void){ - printf("LoadCheckpointFunctor Echo:\n"); - printf(" pmarshalled_data: %p\n",pmarshalled_data); - } + LoadCheckpointFunctor(char** pmarshalled_data_in); + void Echo(void); + void call(char* & value); template void call(T & value){ memcpy(&value,*pmarshalled_data,sizeof(T)); *pmarshalled_data+=sizeof(T); } - void call(char* & value){ - int size; - this->call(size); - this->call(value,size); - }; template void call(T* & value,int size){ bool pointer_null; call(pointer_null); @@ -104,20 +90,13 @@ int marshalled_data_size; public: - SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE),marshalled_data_size(0){} - int MarshalledSize(void){return this->marshalled_data_size;}; - void Echo(void){ - printf("SizeCheckpointFunctor Echo:\n"); - printf(" marshalled_data_size: %i\n",marshalled_data_size); - } + SizeCheckpointFunctor(void); + int MarshalledSize(void); + void Echo(void); template void call(T & value){ marshalled_data_size+=sizeof(T); } - void call(char* & value){ - int size = strlen(value)+1; - this->call(size); - this->call(value,size); - }; + void call(char* & value); template void call(T* & value,int size){ bool pointer_null = true; if(value) pointer_null = false; @@ -134,62 +113,29 @@ int double_count; public: - CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES),double_count(0){} - int DoubleCount(void){return this->double_count;}; - void Echo(void){ - printf("CountDoublesFunctor Echo:\n"); - printf(" double_count: %i\n",double_count); - } - template void call(T & value){ - /*General case: do nothing*/ - } - template void call(T* & value,int size){ - /*General case: do nothing*/ - } - void call(IssmDouble value){ - this->double_count++; - } - void call(IssmDouble* value,int size){ - if(value) this->double_count+= size; - } + CountDoublesFunctor(void); + int DoubleCount(void); + void Echo(void); + template void call(T & value){/*General case: do nothing*/} + template void call(T* & value,int size){/*General case: do nothing*/} + void call(IssmDouble value); + void call(IssmDouble* value,int size); }; /*}}}*/ class RegisterInputFunctor: public MarshallHandle{ /*{{{*/ private: - int double_count; - int* identifiers; - IssmDouble::TapeType* tape_codi; + int double_count; + int *identifiers; + int size_max; + IssmDouble::TapeType *tape_codi; public: - RegisterInputFunctor(int* identifiers_in) : MarshallHandle(AD_REGISTERINPUT){ - this->double_count = 0; - this->identifiers = identifiers_in; - this->tape_codi = &(IssmDouble::getGlobalTape()); - } - void Echo(void){ - printf("RegisterInputFunctor Echo:\n"); - printf(" double_count: %i\n",double_count); - } - template void call(T & value){ - /*General case: do nothing*/ - } - template void call(T* & value,int size){ - /*General case: do nothing*/ - } - void call(IssmDouble value){ - this->tape_codi->registerInput(value); - this->identifiers[this->double_count] = value.getGradientData(); - this->double_count++; - } - void call(IssmDouble* value,int size){ - if(value){ - for(int i=0;itape_codi->registerInput(value[i]); - this->identifiers[this->double_count] = value[i].getGradientData(); - this->double_count++; - } - } - } + RegisterInputFunctor(int* identifiers_in,int size_max_in); + void Echo(void); + template void call(T & value){/*General case: do nothing*/} + template void call(T* & value,int size){/*General case: do nothing*/} + void call(IssmDouble value); + void call(IssmDouble* value,int size); }; /*}}}*/ class RegisterOutputFunctor: public MarshallHandle{ /*{{{*/ @@ -198,68 +144,28 @@ IssmDouble::TapeType* tape_codi; public: - RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){ - this->double_count = 0; - this->tape_codi = &(IssmDouble::getGlobalTape()); - } - void Echo(void){ - printf("RegisterOutputFunctor Echo:\n"); - printf(" double_count: %i\n",double_count); - } - template void call(T & value){ - /*General case: do nothing*/ - } - template void call(T* & value,int size){ - /*General case: do nothing*/ - } - void call(IssmDouble value){ - this->tape_codi->registerOutput(value); - this->double_count++; - } - void call(IssmDouble* value,int size){ - if(value){ - for(int i=0;itape_codi->registerOutput(value[i]); - this->double_count++; - } - } - } + RegisterOutputFunctor(void); + void Echo(void); + template void call(T & value){/*General case: do nothing*/} + template void call(T* & value,int size){/*General case: do nothing*/} + void call(IssmDouble value); + void call(IssmDouble* value,int size); }; /*}}}*/ class SetAdjointFunctor: public MarshallHandle{ /*{{{*/ private: int double_count; + int size_max; IssmDouble::TapeType* tape_codi; double* adjoint; public: - SetAdjointFunctor(double* adjoint_in) : MarshallHandle(AD_SETADJOINT){ - this->double_count = 0; - this->tape_codi = &(IssmDouble::getGlobalTape()); - this->adjoint = adjoint_in; - } - void Echo(void){ - printf("SetAdjointFunctor Echo:\n"); - printf(" double_count: %i\n",double_count); - } - template void call(T & value){ - /*General case: do nothing*/ - } - template void call(T* & value,int size){ - /*General case: do nothing*/ - } - void call(IssmDouble value){ - value.gradient() = this->adjoint[this->double_count]; - this->double_count++; - } - void call(IssmDouble* value,int size){ - if(value){ - for(int i=0;iadjoint[this->double_count]; - this->double_count++; - } - } - } + SetAdjointFunctor(double* adjoint_in,int size_max_in); + void Echo(void); + template void call(T & value){/*General case: do nothing*/} + template void call(T* & value,int size){/*General case: do nothing*/} + void call(IssmDouble value); + void call(IssmDouble* value,int size); }; /*}}}*/ #endif @@ -292,4 +198,4 @@ } } -#endif +#endif Index: ../trunk-jpl/src/c/Makefile.am =================================================================== --- ../trunk-jpl/src/c/Makefile.am (revision 25529) +++ ../trunk-jpl/src/c/Makefile.am (revision 25530) @@ -146,6 +146,7 @@ ./shared/io/Print/PrintfFunction.cpp \ ./shared/io/Comm/IssmComm.cpp \ ./shared/io/Marshalling/IoCodeConversions.cpp \ + ./shared/io/Marshalling/Marshalling.cpp \ ./shared/LatLong/Ll2xyx.cpp \ ./shared/LatLong/Xy2llx.cpp \ ./shared/FSanalyticals/fsanalyticals.cpp \