Changeset 26556
- Timestamp:
- 11/09/21 05:34:35 (3 years ago)
- Location:
- issm/trunk-jpl
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/m4/issm_options.m4
r26392 r26556 967 967 dnl CoDiPack libraries and header files 968 968 if test "x${HAVE_CODIPACK}" == "xyes"; then 969 970 AC_MSG_CHECKING(for CoDiPack version) 971 CODIPACK_MAJOR=`cat ${CODIPACK_ROOT}/include/codi.hpp | grep "#define CODI_MAJOR_VERSION" | sed 's/#define CODI_MAJOR_VERSION//' | sed 's/ //g'` 972 CODIPACK_MINOR=`cat ${CODIPACK_ROOT}/include/codi.hpp | grep "#define CODI_MINOR_VERSION" | sed 's/#define CODI_MINOR_VERSION//' | sed 's/ //g'` 973 if test -z "${CODIPACK_MAJOR}"; then 974 CODIPACK_MAJOR=`cat ${CODIPACK_ROOT}/include/codi/configure.h | grep "#define CODI_MAJOR_VERSION" | sed 's/#define CODI_MAJOR_VERSION//' | sed 's/ //g'` 975 CODIPACK_MINOR=`cat ${CODIPACK_ROOT}/include/codi/configure.h | grep "#define CODI_MINOR_VERSION" | sed 's/#define CODI_MINOR_VERSION//' | sed 's/ //g'` 976 fi 977 if test -z "${CODIPACK_MAJOR}"; then 978 AC_MSG_ERROR([Couldn't determine CoDiPack version]) 979 fi 980 AC_DEFINE_UNQUOTED([_CODIPACK_MAJOR_], ${CODIPACK_MAJOR}, [CoDiPack version major]) 981 AC_DEFINE_UNQUOTED([_CODIPACK_MINOR_], ${CODIPACK_MINOR}, [CoDiPack version minor]) 982 AC_MSG_RESULT([${CODIPACK_MAJOR}.${CODIPACK_MINOR}]) 983 969 984 CODIPACKINCL="-I${CODIPACK_ROOT}/include" 970 985 AC_DEFINE([_HAVE_CODIPACK_], [1], [with CoDiPack in ISSM src]) -
issm/trunk-jpl/src/c/classes/FemModel.cpp
r26487 r26556 2299 2299 2300 2300 #if defined(_HAVE_CODIPACK_) 2301 #if _CODIPACK_MAJOR_==2 2301 2302 auto& tape_codi = IssmDouble::getTape(); 2303 #elif _CODIPACK_MAJOR_==1 2304 auto& tape_codi = IssmDouble::getGlobalTape(); 2305 #else 2306 #error "_CODIPACK_MAJOR_ not supported" 2307 #endif 2302 2308 #endif 2303 2309 … … 2311 2317 tape_codi.registerOutput(output_value); 2312 2318 dependents[i] = output_value.getValue(); 2319 #if _CODIPACK_MAJOR_==2 2313 2320 codi_global.output_indices.push_back(output_value.getIdentifier()); 2321 #elif _CODIPACK_MAJOR_==1 2322 codi_global.output_indices.push_back(output_value.getGradientData()); 2323 #else 2324 #error "_CODIPACK_MAJOR_ not supported" 2325 #endif 2314 2326 #else 2315 2327 output_value>>=dependents[i]; -
issm/trunk-jpl/src/c/classes/IoModel.cpp
r26468 r26556 2063 2063 scalar=pscalar; 2064 2064 } 2065 #if _CODIPACK_MAJOR_==2 2065 2066 auto& tape_codi = IssmDouble::getTape(); 2066 2067 tape_codi.registerInput(scalar); 2067 2068 codi_global.input_indices.push_back(scalar.getIdentifier()); 2069 #elif _CODIPACK_MAJOR_==1 2070 auto& tape_codi = IssmDouble::getGlobalTape(); 2071 tape_codi.registerInput(scalar); 2072 codi_global.input_indices.push_back(scalar.getGradientData()); 2073 #else 2074 #error "_CODIPACK_MAJOR_ not supported" 2075 #endif 2076 2068 2077 #else 2069 2078 if(X){ … … 2136 2145 #if defined(_HAVE_CODIPACK_) 2137 2146 // FIXME codi here we just assign instead of using "operator <<=" 2147 #if _CODIPACK_MAJOR_==2 2138 2148 auto& tape_codi = IssmDouble::getTape(); 2149 #elif _CODIPACK_MAJOR_==1 2150 auto& tape_codi = IssmDouble::getGlobalTape(); 2151 #else 2152 #error "_CODIPACK_MAJOR_ not supported" 2153 #endif 2154 2139 2155 if(X){ 2140 2156 for (int i=0;i<M*N;i++) { 2141 2157 matrix[i]=X[Xcount+i]; 2142 2158 tape_codi.registerInput(matrix[i]); 2159 #if _CODIPACK_MAJOR_==2 2143 2160 codi_global.input_indices.push_back(matrix[i].getIdentifier()); 2161 #elif _CODIPACK_MAJOR_==1 2162 codi_global.input_indices.push_back(matrix[i].getGradientData()); 2163 #else 2164 #error "_CODIPACK_MAJOR_ not supported" 2165 #endif 2166 2144 2167 } 2145 2168 } … … 2148 2171 matrix[i]=buffer[i]; 2149 2172 tape_codi.registerInput(matrix[i]); 2173 #if _CODIPACK_MAJOR_==2 2150 2174 codi_global.input_indices.push_back(matrix[i].getIdentifier()); 2175 #elif _CODIPACK_MAJOR_==1 2176 codi_global.input_indices.push_back(matrix[i].getGradientData()); 2177 #else 2178 #error "_CODIPACK_MAJOR_ not supported" 2179 #endif 2151 2180 } 2152 2181 } … … 2961 2990 * -> These parameters are not read for the CoDiPack ISSM version! 2962 2991 */ 2992 #if _CODIPACK_MAJOR_==2 2963 2993 auto& tape_codi = IssmDouble::getTape(); 2994 #elif _CODIPACK_MAJOR_==1 2995 auto& tape_codi = IssmDouble::getGlobalTape(); 2996 #else 2997 #error "_CODIPACK_MAJOR_ not supported" 2998 #endif 2999 2964 3000 tape_codi.setActive(); 2965 3001 #if _AD_TAPE_ALLOC_ -
issm/trunk-jpl/src/c/cores/ad_core.cpp
r26432 r26556 326 326 327 327 /*First, stop tracing: */ 328 #if _CODIPACK_MAJOR_==2 328 329 auto& tape_codi = IssmDouble::getTape(); 330 #elif _CODIPACK_MAJOR_==1 331 auto& tape_codi = IssmDouble::getGlobalTape(); 332 #else 333 #error "_CODIPACK_MAJOR_ not supported" 334 #endif 335 329 336 tape_codi.setPassive(); 330 337 -
issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp
r26523 r26556 14 14 extern CoDi_global codi_global; 15 15 #include <sstream> // for output of the CoDiPack tape 16 #include <fenv.h> 16 17 void transient_ad(FemModel* femmodel); 17 18 #endif … … 75 76 * -> These parameters are not read for the CoDiPack ISSM version! 76 77 */ 78 #if _CODIPACK_MAJOR_==2 77 79 auto& tape_codi = IssmDouble::getTape(); 80 #elif _CODIPACK_MAJOR_==1 81 auto& tape_codi = IssmDouble::getGlobalTape(); 82 #else 83 #error "_CODIPACK_MAJOR_ not supported" 84 #endif 85 78 86 tape_codi.setActive(); 79 87 #if _AD_TAPE_ALLOC_ … … 153 161 #endif 154 162 std::stringstream out_s; 163 #if _CODIPACK_MAJOR_==2 155 164 IssmDouble::getTape().printStatistics(out_s); 165 #elif _CODIPACK_MAJOR_==1 166 IssmDouble::getGlobalTape().printStatistics(out_s); 167 #else 168 #error "_CODIPACK_MAJOR_ not supported" 169 #endif 156 170 _printf0_("CoDiPack Profiling::Tape Statistics :\n" << out_s.str()); 157 171 #endif … … 159 173 160 174 #elif defined(_HAVE_CODIPACK_) 175 176 /*Get Tape*/ 177 #if _CODIPACK_MAJOR_==2 161 178 auto& tape_codi = IssmDouble::getTape(); 179 #elif _CODIPACK_MAJOR_==1 180 auto& tape_codi = IssmDouble::getGlobalTape(); 181 #else 182 #error "_CODIPACK_MAJOR_ not supported" 183 #endif 184 162 185 tape_codi.setPassive(); 163 186 if(VerboseAutodiff()){ … … 239 262 } 240 263 #elif defined(_HAVE_CODIPACK_) 264 265 /*Get tape*/ 266 #if _CODIPACK_MAJOR_==2 241 267 auto& tape_codi = IssmDouble::getTape(); 268 #elif _CODIPACK_MAJOR_==1 269 auto& tape_codi = IssmDouble::getGlobalTape(); 270 #else 271 #error "_CODIPACK_MAJOR_ not supported" 272 #endif 273 242 274 codi_global.input_indices.clear(); 243 275 if(my_rank==0){ … … 245 277 aX[i]=X[i]; 246 278 tape_codi.registerInput(aX[i]); 279 #if _CODIPACK_MAJOR_==2 247 280 codi_global.input_indices.push_back(aX[i].getIdentifier()); 281 #elif _CODIPACK_MAJOR_==1 282 codi_global.input_indices.push_back(aX[i].getGradientData()); 283 #else 284 #error "_CODIPACK_MAJOR_ not supported" 285 #endif 286 248 287 } 249 288 } … … 285 324 tape_codi.registerOutput(output_value); 286 325 dependents[i] = output_value.getValue(); 326 #if _CODIPACK_MAJOR_==2 287 327 codi_global.output_indices.push_back(output_value.getIdentifier()); 328 #elif _CODIPACK_MAJOR_==1 329 codi_global.output_indices.push_back(output_value.getGradientData()); 330 #else 331 #error "_CODIPACK_MAJOR_ not supported" 332 #endif 288 333 289 334 #elif defined(_HAVE_ADOLC_) … … 377 422 tape_codi.setGradient(codi_global.output_indices[dep_index],1.0); 378 423 } 424 feclearexcept(FE_ALL_EXCEPT); 425 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); 379 426 tape_codi.evaluate(); 380 427 … … 446 493 } 447 494 Gnorm = sqrt(Gnorm); 495 _assert_(!xIsNan(Gnorm)); 448 496 449 497 /*Print info*/ -
issm/trunk-jpl/src/c/cores/controlvalidation_core.cpp
r26478 r26556 50 50 * -> These parameters are not read for the CoDiPack ISSM version! 51 51 */ 52 #if _CODIPACK_MAJOR_==2 52 53 auto& tape_codi = IssmDouble::getTape(); 54 #elif _CODIPACK_MAJOR_==1 55 auto& tape_codi = IssmDouble::getGlobalTape(); 56 #else 57 #error "_CODIPACK_MAJOR_ not supported" 58 #endif 59 53 60 tape_codi.setActive(); 54 61 #if _AD_TAPE_ALLOC_ … … 127 134 #endif 128 135 std::stringstream out_s; 136 #if _CODIPACK_MAJOR_==2 129 137 IssmDouble::getTape().printStatistics(out_s); 138 #elif _CODIPACK_MAJOR_==1 139 IssmDouble::getGlobalTape().printStatistics(out_s); 140 #else 141 #error "_CODIPACK_MAJOR_ not supported" 142 #endif 130 143 _printf0_("CoDiPack Profiling::Tape Statistics :\n" << out_s.str()); 131 144 #endif … … 133 146 134 147 #elif defined(_HAVE_CODIPACK_) 148 149 #if _CODIPACK_MAJOR_==2 135 150 auto& tape_codi = IssmDouble::getTape(); 151 #elif _CODIPACK_MAJOR_==1 152 auto& tape_codi = IssmDouble::getGlobalTape(); 153 #else 154 #error "_CODIPACK_MAJOR_ not supported" 155 #endif 156 136 157 tape_codi.setPassive(); 137 158 if(VerboseAutodiff()){ … … 191 212 simul_starttrace2(femmodel); 192 213 IssmDouble* aX=xNew<IssmDouble>(n); 214 215 #if _CODIPACK_MAJOR_==2 193 216 auto& tape_codi = IssmDouble::getTape(); 217 #elif _CODIPACK_MAJOR_==1 218 auto& tape_codi = IssmDouble::getGlobalTape(); 219 #else 220 #error "_CODIPACK_MAJOR_ not supported" 221 #endif 222 194 223 codi_global.input_indices.clear(); 195 224 if(my_rank==0){ … … 197 226 aX[i]=X0[i]; 198 227 tape_codi.registerInput(aX[i]); 228 #if _CODIPACK_MAJOR_==2 199 229 codi_global.input_indices.push_back(aX[i].getIdentifier()); 230 #elif _CODIPACK_MAJOR_==1 231 codi_global.input_indices.push_back(aX[i].getGradientData()); 232 #else 233 #error "_CODIPACK_MAJOR_ not supported" 234 #endif 235 200 236 } 201 237 } … … 231 267 tape_codi.registerOutput(output_value); 232 268 dependents[i] = output_value.getValue(); 269 #if _CODIPACK_MAJOR_==2 233 270 codi_global.output_indices.push_back(output_value.getIdentifier()); 271 #elif _CODIPACK_MAJOR_==1 272 codi_global.output_indices.push_back(output_value.getGradientData()); 273 #else 274 #error "_CODIPACK_MAJOR_ not supported" 275 #endif 276 234 277 J+=output_value; 235 278 } -
issm/trunk-jpl/src/c/cores/transient_core.cpp
r26526 r26556 379 379 380 380 /*Start tracing*/ 381 #if _CODIPACK_MAJOR_==2 381 382 auto& tape_codi = IssmDouble::getTape(); 383 #elif _CODIPACK_MAJOR_==1 384 auto& tape_codi = IssmDouble::getGlobalTape(); 385 #else 386 #error "_CODIPACK_MAJOR_ not supported" 387 #endif 382 388 tape_codi.setActive(); 383 389 -
issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp
r26534 r26556 76 76 this->identifiers = identifiers_in; 77 77 this->size_max = size_max_in; 78 #if _CODIPACK_MAJOR_==2 78 79 this->tape_codi = &(IssmDouble::getTape()); 80 #elif _CODIPACK_MAJOR_==1 81 this->tape_codi = &(IssmDouble::getGlobalTape()); 82 #else 83 #error "_CODIPACK_MAJOR_ not supported" 84 #endif 85 79 86 }/*}}}*/ 80 87 void RegisterInputFunctor::Echo(void){/*{{{*/ … … 86 93 _assert_(!xIsNan<IssmDouble>(value)); 87 94 this->tape_codi->registerInput(value); 95 #if _CODIPACK_MAJOR_==2 88 96 this->identifiers[this->double_count] = value.getIdentifier(); 97 #elif _CODIPACK_MAJOR_==1 98 this->identifiers[this->double_count] = value.getGradientData(); 99 #else 100 #error "_CODIPACK_MAJOR_ not supported" 101 #endif 102 89 103 this->double_count++; 90 104 }/*}}}*/ … … 95 109 _assert_(!xIsNan<IssmDouble>(value[i])); 96 110 this->tape_codi->registerInput(value[i]); 111 #if _CODIPACK_MAJOR_==2 97 112 this->identifiers[this->double_count] = value[i].getIdentifier(); 113 #elif _CODIPACK_MAJOR_==1 114 this->identifiers[this->double_count] = value[i].getGradientData(); 115 #else 116 #error "_CODIPACK_MAJOR_ not supported" 117 #endif 118 98 119 this->double_count++; 99 120 } … … 103 124 RegisterOutputFunctor::RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){/*{{{*/ 104 125 this->double_count = 0; 126 #if _CODIPACK_MAJOR_==2 105 127 this->tape_codi = &(IssmDouble::getTape()); 128 #elif _CODIPACK_MAJOR_==1 129 this->tape_codi = &(IssmDouble::getGlobalTape()); 130 #else 131 #error "_CODIPACK_MAJOR_ not supported" 132 #endif 106 133 }/*}}}*/ 107 134 void RegisterOutputFunctor::Echo(void){/*{{{*/ … … 126 153 SetAdjointFunctor::SetAdjointFunctor(double* adjoint_in,int size_max_in) : MarshallHandle(AD_SETADJOINT){/*{{{*/ 127 154 this->double_count = 0; 128 this->tape_codi = &(IssmDouble::getTape());129 155 this->adjoint = adjoint_in; 130 156 this->size_max = size_max_in; 157 #if _CODIPACK_MAJOR_==2 158 this->tape_codi = &(IssmDouble::getTape()); 159 #elif _CODIPACK_MAJOR_==1 160 this->tape_codi = &(IssmDouble::getGlobalTape()); 161 #else 162 #error "_CODIPACK_MAJOR_ not supported" 163 #endif 131 164 }/*}}}*/ 132 165 void SetAdjointFunctor::Echo(void){/*{{{*/ -
issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h
r26432 r26556 108 108 };/*}}}*/ 109 109 #if defined(_HAVE_CODIPACK_) && !defined(_WRAPPERS_) 110 #if _CODIPACK_MAJOR_==2 111 using Tape = typename IssmDouble::Tape; 112 #elif _CODIPACK_MAJOR_==1 113 using Tape = typename IssmDouble::TapeType; 114 #else 115 #error "_CODIPACK_MAJOR_ not supported" 116 #endif 110 117 class CountDoublesFunctor: public MarshallHandle{ /*{{{*/ 111 118 … … 128 135 int *identifiers; 129 136 int size_max; 130 IssmDouble::Tape *tape_codi;137 Tape *tape_codi; 131 138 132 139 public: … … 142 149 private: 143 150 int double_count; 144 IssmDouble::Tape*tape_codi;151 Tape *tape_codi; 145 152 146 153 public: … … 155 162 156 163 private: 157 int 158 int 159 IssmDouble::Tape*tape_codi;160 double *adjoint;164 int double_count; 165 int size_max; 166 Tape *tape_codi; 167 double *adjoint; 161 168 162 169 public: -
issm/trunk-jpl/src/c/toolkits/codipack/CoDiPackCommon.hpp
r26433 r26556 35 35 inline void getVectorGradData(const Real* vec, Data* dataVec, int n) { 36 36 for(int i = 0; i < n; ++i) { 37 #if _CODIPACK_MAJOR_==2 37 38 dataVec[i]=vec[i].getIdentifier(); 39 #elif _CODIPACK_MAJOR_==1 40 dataVec[i]=vec[i].getGradientData(); 41 #else 42 #error "_CODIPACK_MAJOR_ not supported" 43 #endif 38 44 } 39 45 } … … 43 49 for(int i = 0; i < n; ++i) { 44 50 pasVec[i]=vec[i].getValue(); 51 #if _CODIPACK_MAJOR_==2 45 52 dataVec[i]=vec[i].getIdentifier(); 53 #elif _CODIPACK_MAJOR_==1 54 dataVec[i]=vec[i].getGradientData(); 55 #else 56 #error "_CODIPACK_MAJOR_ not supported" 57 #endif 46 58 } 47 59 } … … 50 62 inline void getPrimalAndGradData(const Real& value, Passive& pas, Data& data) { 51 63 pas=value.getValue(); 64 #if _CODIPACK_MAJOR_==2 52 65 data=value.getIdentifier(); 66 #elif _CODIPACK_MAJOR_==1 67 data=value.getGradientData(); 68 #else 69 #error "_CODIPACK_MAJOR_ not supported" 70 #endif 53 71 } 54 72 55 73 template<typename Real, typename Data> 56 74 inline void registerVector(Real* vec, Data* dataVec, int n) { 57 typename Real::Tape& tape = Real::getTape(); 75 #if _CODIPACK_MAJOR_==2 76 typename Real::Tape& tape = Real::getTape(); 77 #elif _CODIPACK_MAJOR_==1 78 typename Real::TapeType& tape = Real::getGlobalTape(); 79 #else 80 #error "_CODIPACK_MAJOR_ not supported" 81 #endif 58 82 59 83 for(int i = 0; i < n; ++i) { 60 84 tape.registerInput(vec[i]); 85 #if _CODIPACK_MAJOR_==2 61 86 dataVec[i]=vec[i].getIdentifier(); 87 #elif _CODIPACK_MAJOR_==1 88 dataVec[i]=vec[i].getGradientData(); 89 #else 90 #error "_CODIPACK_MAJOR_ not supported" 91 #endif 62 92 } 63 93 } -
issm/trunk-jpl/src/c/toolkits/gsl/DenseGslSolve.cpp
r26468 r26556 254 254 255 255 #ifdef _HAVE_CODIPACK_ 256 #if _CODIPACK_MAJOR_==2 256 257 using Tape = typename IssmDouble::Tape; 257 258 using AccessInterface = codi::VectorAccessInterface<typename Tape::Real, typename Tape::Identifier>; … … 385 386 } 386 387 /*}}}*/ 388 #elif _CODIPACK_MAJOR_==1 389 void SolverxSeq_codi_b(void* tape_in,void* data_in,void* ra) {/*{{{*/ 390 391 /*recast data_in and tape*/ 392 codi::DataStore* data = (codi::DataStore*)data_in; 393 //IssmDouble::TapeType& tape = (IssmDouble::TapeType&)tape_in; 394 IssmDouble::TapeType& tape = IssmDouble::getGlobalTape(); 395 396 IssmDouble::Real* valueATrans; 397 IssmDouble::GradientData* indexATrans; 398 IssmDouble::GradientData* indexB; 399 IssmDouble::Real* valueX; 400 IssmDouble::GradientData* indexX; 401 int n; 402 403 data->getData(valueATrans); 404 data->getData(indexATrans); 405 data->getData(indexB); 406 data->getData(valueX); 407 data->getData(indexX); 408 data->getData(n); 409 410 411 // create the adjoint vector for x and reset the adjoint values on the tape 412 IssmDouble::GradientValue* adjX = xNew<IssmDouble::GradientValue>(n); 413 getVectorAdjoint(tape, indexX, adjX, n); 414 415 IssmDouble::GradientValue* sol = xNew<IssmDouble::GradientValue>(n); 416 SolverxSeq(sol, valueATrans, adjX, n); 417 418 updateVectorAdjoint(tape, indexB, sol, n); 419 for(int i=0; i<n; ++i) { 420 for (int j=0; j<n; ++j) { 421 // we access the transposed matrix here because we stored the indices in a transposed way 422 updateAdjoint(tape, indexATrans[i*n+j], -sol[j]*valueX[i]); 423 } 424 } 425 426 xDelete(sol); 427 xDelete(adjX); 428 } 429 /*}}}*/ 430 void SolverxSeq_codi_delete(void* tape_in,void* data_in) {/*{{{*/ 431 432 /*recast data_in*/ 433 codi::DataStore* data = (codi::DataStore*)data_in; 434 435 IssmDouble::Real* valueATrans; 436 IssmDouble::GradientData* indexATrans; 437 IssmDouble::GradientData* indexB; 438 IssmDouble::Real* valueX; 439 IssmDouble::GradientData* indexX; 440 int n; 441 442 data->getData(valueATrans); 443 data->getData(indexATrans); 444 data->getData(indexB); 445 data->getData(valueX); 446 data->getData(indexX); 447 data->getData(n); 448 449 xDelete(valueATrans); 450 xDelete(indexATrans); 451 xDelete(indexB); 452 xDelete(valueX); 453 xDelete(indexX); 454 455 delete data; 456 } 457 /*}}}*/ 458 void SolverxSeq(IssmDouble *X,IssmDouble *A,IssmDouble *B,int n, Parameters* parameters){/*{{{*/ 459 IssmDouble::TapeType& tape = IssmDouble::getGlobalTape(); 460 codi::DataStore* dataHandler = NULL; 461 462 if(tape.isActive()) { 463 dataHandler = new codi::DataStore(); 464 465 // create the index vector and the double data for A and B 466 IssmDouble::Real* valueATrans = xNew<IssmDouble::Real>(n*n); 467 IssmDouble::GradientData* indexATrans = xNew<IssmDouble::GradientData>(n*n); 468 469 // read the data for matrix in a transposed fashion 470 for (int i=0; i<n; ++i) { 471 for (int j=0; j<n; ++j) { 472 getPrimalAndGradData(A[i*n+j], valueATrans[j*n+i], indexATrans[j*n+i]); 473 } 474 } 475 476 // read the data from B (primal values are not required vor B 477 IssmDouble::GradientData* indexB = xNew<IssmDouble::GradientData>(n); 478 getVectorGradData(B, indexB, n); 479 480 dataHandler->addData(valueATrans); 481 dataHandler->addData(indexATrans); 482 dataHandler->addData(indexB); 483 } 484 485 // unpack the primal values from the matrix and the vector 486 IssmDouble::Real* valueA = xNew<IssmDouble::Real>(n*n); 487 IssmDouble::Real* valueB = xNew<IssmDouble::Real>(n); 488 // read the data from A and B 489 getVectorPrimal(A, valueA, n*n); 490 getVectorPrimal(B, valueB, n); 491 492 // create the placeholder for X and solve the system 493 IssmDouble::Real* valueX = xNew<IssmDouble::Real>(n); 494 SolverxSeq(valueX, valueA, valueB, n); 495 496 // pack the values into x 497 setVectorPrimal(X, valueX, n); 498 499 if(tape.isActive()) { 500 // create the index vector X and register x as active variables 501 IssmDouble::GradientData* indexX = xNew<IssmDouble::GradientData>(n); 502 registerVector(X, indexX, n); 503 504 dataHandler->addData(valueX); 505 dataHandler->addData(indexX); 506 507 // store other arguments 508 dataHandler->addData(n); 509 510 tape.pushExternalFunctionHandle(&SolverxSeq_codi_b, dataHandler, &SolverxSeq_codi_delete); 511 } 512 else{ 513 // if the tape is active valueX is stored in the dataHandler and deleted in the reverse sweep 514 xDelete(valueX); 515 } 516 517 xDelete(valueB); 518 xDelete(valueA); 519 } 520 /*}}}*/ 521 #else 522 #error "_CODIPACK_MAJOR_ not supported" 523 #endif 387 524 void DenseGslSolve(/*output*/ IssmDouble** px,/*stiffness matrix:*/ IssmDouble* Kff, int Kff_M, int Kff_N, /*right hand side load vector: */ IssmDouble* pf, int pf_M, Parameters* parameters){ /*{{{*/ 388 525 … … 400 537 } 401 538 /*}}}*/ 402 #endif 539 540 #endif -
issm/trunk-jpl/src/c/toolkits/mpi/issmmpi.h
r26432 r26556 34 34 //using MpiTypes = CoDiMpiTypes<IssmDouble>; 35 35 /*New implementation*/ 36 #if _CODIPACK_MAJOR_==2 36 37 #include <codi/tools/mpi/codiMpiTypes.hpp> 37 using MpiTypes = codi::CoDiMpiTypes<IssmDouble>; 38 using MpiTypes = codi::CoDiMpiTypes<IssmDouble>; 39 40 #elif _CODIPACK_MAJOR_==1 41 #include <codi/externals/codiMpiTypes.hpp> 42 using MpiTypes = CoDiMpiTypes<IssmDouble>; 43 44 #else 45 #error "_CODIPACK_MAJOR_ not supported" 46 #endif 47 38 48 extern MpiTypes* mpiTypes; 39 49 #define AMPI_ADOUBLE mpiTypes->MPI_TYPE -
issm/trunk-jpl/src/c/toolkits/mumps/MumpsSolve.cpp
r26433 r26556 485 485 486 486 #ifdef _HAVE_CODIPACK_ 487 #if _CODIPACK_MAJOR_==2 487 488 using Tape = typename IssmDouble::Tape; 488 489 using AccessInterface = codi::VectorAccessInterface<typename Tape::Real, typename Tape::Identifier>; 489 490 490 void MumpsSolve_codi_b(Tape* tape, void* data_in, AccessInterface* ra) {/*{{{*/ 491 491 … … 648 648 } 649 649 /*}}}*/ 650 #endif 650 #elif _CODIPACK_MAJOR_==1 651 void MumpsSolve_codi_b(void* tape_in,void* data_in,void* ra) {/*{{{*/ 652 653 /*recast data_in and tape*/ 654 codi::DataStore* data = (codi::DataStore*)data_in; 655 //IssmDouble::TapeType& tape = (IssmDouble::TapeType&)tape_in; 656 IssmDouble::TapeType& tape = IssmDouble::getGlobalTape(); 657 658 659 IssmDouble::Real* valueATrans; 660 IssmDouble::GradientData* indexATrans; 661 int* irnATrans; 662 int* jcnATrans; 663 IssmDouble::GradientData* indexB; 664 IssmDouble::Real* valueX; 665 IssmDouble::GradientData* indexX; 666 int n; 667 int nnz; 668 int local_nnz; 669 Parameters* parameters; 670 671 data->getData(valueATrans); 672 data->getData(indexATrans); 673 data->getData(irnATrans); 674 data->getData(jcnATrans); 675 data->getData(indexB); 676 data->getData(valueX); 677 data->getData(indexX); 678 data->getData(n); 679 data->getData(nnz); 680 data->getData(local_nnz); 681 data->getData(parameters); 682 683 // create the adjoint vector for x and reset the adjoint values on the tape 684 IssmDouble::GradientValue* adjX = xNew<IssmDouble::GradientValue>(n); 685 getVectorAdjoint(tape, indexX, adjX, n); 686 687 MumpsSolve(n, nnz, local_nnz, irnATrans, jcnATrans, valueATrans, adjX, parameters); 688 // adjX contains now the solution 689 690 updateVectorAdjoint(tape, indexB, adjX, n); 691 692 // bcast dp_y (the solution of the forward system) 693 ISSM_MPI_Bcast(valueX,n,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 694 // bcast the adjoint of the right-hand-side, i.e. this solution 695 ISSM_MPI_Bcast(adjX,n,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 696 697 for(int i=0; i<local_nnz; ++i) { 698 // we access the transposed matrix here because we stored the indices in a transposed way 699 // -1 is substracted because jcn and irn are stored with fortran indexing 700 updateAdjoint(tape, indexATrans[i], -adjX[jcnATrans[i]-1]*valueX[irnATrans[i]-1]); 701 } 702 703 xDelete(adjX); 704 } 705 /*}}}*/ 706 void MumpsSolve_codi_delete(void* tape_in,void* data_in) {/*{{{*/ 707 708 /*recast data_in*/ 709 codi::DataStore* data = (codi::DataStore*)data_in; 710 711 IssmDouble::Real* valueATrans; 712 IssmDouble::GradientData* indexATrans; 713 int* irnATrans; 714 int* jcnATrans; 715 IssmDouble::GradientData* indexB; 716 IssmDouble::Real* valueX; 717 IssmDouble::GradientData* indexX; 718 int n; 719 int nnz; 720 int local_nnz; 721 Parameters* parameters; 722 723 data->getData(valueATrans); 724 data->getData(indexATrans); 725 data->getData(irnATrans); 726 data->getData(jcnATrans); 727 data->getData(indexB); 728 data->getData(valueX); 729 data->getData(indexX); 730 data->getData(n); 731 data->getData(nnz); 732 data->getData(local_nnz); 733 data->getData(parameters); 734 735 xDelete(valueATrans); 736 xDelete(indexATrans); 737 xDelete(irnATrans); 738 xDelete(jcnATrans); 739 xDelete(indexB); 740 xDelete(valueX); 741 xDelete(indexX); 742 743 delete data; 744 } 745 /*}}}*/ 746 void MumpsSolve(int n,int nnz,int local_nnz,int* irn_loc,int* jcn_loc,IssmDouble *a_loc,IssmDouble *rhs,Parameters* parameters){/*{{{*/ 747 IssmDouble::TapeType& tape = IssmDouble::getGlobalTape(); 748 codi::DataStore* dataHandler = NULL; 749 750 if(tape.isActive()) { 751 dataHandler = new codi::DataStore(); 752 753 // create the index and double vector for the matrix 754 IssmDouble::Real* valueATrans = xNew<IssmDouble::Real>(local_nnz); 755 IssmDouble::GradientData* indexATrans = xNew<IssmDouble::GradientData>(local_nnz); 756 int* irnATrans = xNew<int>(local_nnz); 757 int* jcnATrans = xNew<int>(local_nnz); 758 759 // read the data for the matrix A in a transposed fashion 760 for (int i=0; i<local_nnz; ++i) { 761 getPrimalAndGradData(a_loc[i], valueATrans[i], indexATrans[i]); 762 irnATrans[i]=jcn_loc[i]; // transposed store 763 jcnATrans[i]=irn_loc[i]; // transposed store 764 } 765 766 // create the index vector for a (primal values are not needed for a) 767 IssmDouble::GradientData* indexB = xNew<IssmDouble::GradientData>(n); 768 getVectorGradData(rhs, indexB, n); 769 770 dataHandler->addData(valueATrans); 771 dataHandler->addData(indexATrans); 772 dataHandler->addData(irnATrans); 773 dataHandler->addData(jcnATrans); 774 dataHandler->addData(indexB); 775 } 776 777 // unpack the primal values from the matrix and the vector 778 IssmDouble::Real* valueA = xNew<IssmDouble::Real>(local_nnz); 779 IssmDouble::Real* valueB = xNew<IssmDouble::Real>(n); 780 // read the data from A and B 781 getVectorPrimal(a_loc, valueA, local_nnz); 782 getVectorPrimal(rhs, valueB, n); 783 784 MumpsSolve(n, nnz, local_nnz, irn_loc, jcn_loc, valueA, valueB, parameters); 785 // valueB contains now the solution 786 787 // pack the values into rhs 788 setVectorPrimal(rhs, valueB, n); 789 790 if(tape.isActive()) { 791 // create the index vector X and register x as active variables 792 IssmDouble::GradientData* indexX = xNew<IssmDouble::GradientData>(n); 793 registerVector(rhs, indexX, n); 794 795 dataHandler->addData(valueB); // contains the values from x 796 dataHandler->addData(indexX); 797 798 // store other arguments 799 dataHandler->addData(n); 800 dataHandler->addData(nnz); 801 dataHandler->addData(local_nnz); 802 dataHandler->addData(parameters); // we assume here that parameters is still intact when the reverse run is called 803 804 //tape.pushExternalFunction(&MumpsSolve_codi_b, dataHandler, &MumpsSolve_codi_delete); 805 tape.pushExternalFunctionHandle(&MumpsSolve_codi_b,(void*)dataHandler, &MumpsSolve_codi_delete); 806 } 807 else{ 808 // if the tape is active valueB is stored in the dataHandler and deleted in the reverse sweep 809 xDelete(valueB); 810 } 811 812 xDelete(valueA); 813 } 814 /*}}}*/ 815 #else 816 #error "_CODIPACK_MAJOR_ not supported" 817 #endif 818 #endif
Note:
See TracChangeset
for help on using the changeset viewer.