Changeset 26433
- Timestamp:
- 09/06/21 17:31:41 (4 years ago)
- Location:
- issm/trunk-jpl/src/c/toolkits
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/toolkits/codipack/CoDiPackCommon.hpp
r26432 r26433 55 55 template<typename Real, typename Data> 56 56 inline void registerVector(Real* vec, Data* dataVec, int n) { 57 typename Real::Tape Type& tape = Real::getTape();57 typename Real::Tape& tape = Real::getTape(); 58 58 59 59 for(int i = 0; i < n; ++i) { -
issm/trunk-jpl/src/c/toolkits/gsl/DenseGslSolve.cpp
r26432 r26433 254 254 255 255 #ifdef _HAVE_CODIPACK_ 256 void SolverxSeq_codi_b(void* tape_in,void* data_in,void* ra) {/*{{{*/ 256 using Tape = typename IssmDouble::Tape; 257 using AccessInterface = codi::VectorAccessInterface<typename Tape::Real, typename Tape::Identifier>; 258 void SolverxSeq_codi_b(Tape* tape,void* data_in, AccessInterface* ra) {/*{{{*/ 257 259 258 260 /*recast data_in and tape*/ 259 codi::DataStore* data = (codi::DataStore*)data_in; 260 //IssmDouble::Tape& tape = (IssmDouble::Tape&)tape_in; 261 IssmDouble::Tape& tape = IssmDouble::getTape(); 261 codi::ExternalFunctionUserData* data = (codi::ExternalFunctionUserData*)data_in; 262 262 263 263 IssmDouble::Real* valueATrans; 264 IssmDouble:: GradientData* indexATrans;265 IssmDouble:: GradientData* indexB;264 IssmDouble::Identifier* indexATrans; 265 IssmDouble::Identifier* indexB; 266 266 IssmDouble::Real* valueX; 267 IssmDouble:: GradientData* indexX;267 IssmDouble::Identifier* indexX; 268 268 int n; 269 269 … … 275 275 data->getData(n); 276 276 277 278 277 // create the adjoint vector for x and reset the adjoint values on the tape 279 278 IssmDouble::Gradient* adjX = xNew<IssmDouble::Gradient>(n); 280 getVectorAdjoint( tape, indexX, adjX, n);279 getVectorAdjoint(*tape, indexX, adjX, n); 281 280 282 281 IssmDouble::Gradient* sol = xNew<IssmDouble::Gradient>(n); 283 282 SolverxSeq(sol, valueATrans, adjX, n); 284 283 285 updateVectorAdjoint( tape, indexB, sol, n);284 updateVectorAdjoint(*tape, indexB, sol, n); 286 285 for(int i=0; i<n; ++i) { 287 286 for (int j=0; j<n; ++j) { 288 287 // we access the transposed matrix here because we stored the indices in a transposed way 289 updateAdjoint( tape, indexATrans[i*n+j], -sol[j]*valueX[i]);288 updateAdjoint(*tape, indexATrans[i*n+j], -sol[j]*valueX[i]); 290 289 } 291 290 } … … 295 294 } 296 295 /*}}}*/ 297 void SolverxSeq_codi_delete( void* tape_in,void* data_in) {/*{{{*/296 void SolverxSeq_codi_delete(Tape* tape,void* data_in) {/*{{{*/ 298 297 299 298 /*recast data_in*/ 300 codi:: DataStore* data = (codi::DataStore*)data_in;299 codi::ExternalFunctionUserData* data = (codi::ExternalFunctionUserData*)data_in; 301 300 302 301 IssmDouble::Real* valueATrans; 303 IssmDouble:: GradientData* indexATrans;304 IssmDouble:: GradientData* indexB;302 IssmDouble::Identifier* indexATrans; 303 IssmDouble::Identifier* indexB; 305 304 IssmDouble::Real* valueX; 306 IssmDouble:: GradientData* indexX;305 IssmDouble::Identifier* indexX; 307 306 int n; 308 307 … … 325 324 void SolverxSeq(IssmDouble *X,IssmDouble *A,IssmDouble *B,int n, Parameters* parameters){/*{{{*/ 326 325 IssmDouble::Tape& tape = IssmDouble::getTape(); 327 codi:: DataStore* dataHandler = NULL;326 codi::ExternalFunctionUserData* dataHandler = NULL; 328 327 329 328 if(tape.isActive()) { 330 dataHandler = new codi:: DataStore();329 dataHandler = new codi::ExternalFunctionUserData(); 331 330 332 331 // create the index vector and the double data for A and B 333 332 IssmDouble::Real* valueATrans = xNew<IssmDouble::Real>(n*n); 334 IssmDouble:: GradientData* indexATrans = xNew<IssmDouble::GradientData>(n*n);333 IssmDouble::Identifier* indexATrans = xNew<IssmDouble::Identifier>(n*n); 335 334 336 335 // read the data for matrix in a transposed fashion … … 342 341 343 342 // read the data from B (primal values are not required vor B 344 IssmDouble:: GradientData* indexB = xNew<IssmDouble::GradientData>(n);343 IssmDouble::Identifier* indexB = xNew<IssmDouble::Identifier>(n); 345 344 getVectorGradData(B, indexB, n); 346 345 … … 366 365 if(tape.isActive()) { 367 366 // create the index vector X and register x as active variables 368 IssmDouble:: GradientData* indexX = xNew<IssmDouble::GradientData>(n);367 IssmDouble::Identifier* indexX = xNew<IssmDouble::Identifier>(n); 369 368 registerVector(X, indexX, n); 370 369 … … 375 374 dataHandler->addData(n); 376 375 377 tape.pushExternalFunctionHandle(&SolverxSeq_codi_b, dataHandler, &SolverxSeq_codi_delete);376 tape.pushExternalFunction(codi::ExternalFunction<Tape>::create(&SolverxSeq_codi_b,(void*)dataHandler, &SolverxSeq_codi_delete)); 378 377 } 379 378 else{ -
issm/trunk-jpl/src/c/toolkits/mumps/MumpsSolve.cpp
r26432 r26433 485 485 486 486 #ifdef _HAVE_CODIPACK_ 487 void MumpsSolve_codi_b(void* tape_in,void* data_in,void* ra) {/*{{{*/ 487 using Tape = typename IssmDouble::Tape; 488 using AccessInterface = codi::VectorAccessInterface<typename Tape::Real, typename Tape::Identifier>; 489 490 void MumpsSolve_codi_b(Tape* tape, void* data_in, AccessInterface* ra) {/*{{{*/ 488 491 489 492 /*recast data_in and tape*/ 490 codi::DataStore* data = (codi::DataStore*)data_in; 491 //IssmDouble::Tape& tape = (IssmDouble::Tape&)tape_in; 492 IssmDouble::Tape& tape = IssmDouble::getTape(); 493 493 codi::ExternalFunctionUserData* data = (codi::ExternalFunctionUserData*)data_in; 494 494 495 495 IssmDouble::Real* valueATrans; 496 IssmDouble:: GradientData* indexATrans;496 IssmDouble::Identifier* indexATrans; 497 497 int* irnATrans; 498 498 int* jcnATrans; 499 IssmDouble:: GradientData* indexB;499 IssmDouble::Identifier* indexB; 500 500 IssmDouble::Real* valueX; 501 IssmDouble:: GradientData* indexX;501 IssmDouble::Identifier* indexX; 502 502 int n; 503 503 int nnz; … … 519 519 // create the adjoint vector for x and reset the adjoint values on the tape 520 520 IssmDouble::Gradient* adjX = xNew<IssmDouble::Gradient>(n); 521 getVectorAdjoint( tape, indexX, adjX, n);521 getVectorAdjoint(*tape, indexX, adjX, n); 522 522 523 523 MumpsSolve(n, nnz, local_nnz, irnATrans, jcnATrans, valueATrans, adjX, parameters); 524 524 // adjX contains now the solution 525 525 526 updateVectorAdjoint( tape, indexB, adjX, n);526 updateVectorAdjoint(*tape, indexB, adjX, n); 527 527 528 528 // bcast dp_y (the solution of the forward system) … … 534 534 // we access the transposed matrix here because we stored the indices in a transposed way 535 535 // -1 is substracted because jcn and irn are stored with fortran indexing 536 updateAdjoint( tape, indexATrans[i], -adjX[jcnATrans[i]-1]*valueX[irnATrans[i]-1]);536 updateAdjoint(*tape, indexATrans[i], -adjX[jcnATrans[i]-1]*valueX[irnATrans[i]-1]); 537 537 } 538 538 … … 540 540 } 541 541 /*}}}*/ 542 void MumpsSolve_codi_delete( void* tape_in,void* data_in) {/*{{{*/542 void MumpsSolve_codi_delete(Tape* tape,void* data_in) {/*{{{*/ 543 543 544 544 /*recast data_in*/ 545 codi:: DataStore* data = (codi::DataStore*)data_in;545 codi::ExternalFunctionUserData* data = (codi::ExternalFunctionUserData*)data_in; 546 546 547 547 IssmDouble::Real* valueATrans; 548 IssmDouble:: GradientData* indexATrans;548 IssmDouble::Identifier* indexATrans; 549 549 int* irnATrans; 550 550 int* jcnATrans; 551 IssmDouble:: GradientData* indexB;551 IssmDouble::Identifier* indexB; 552 552 IssmDouble::Real* valueX; 553 IssmDouble:: GradientData* indexX;553 IssmDouble::Identifier* indexX; 554 554 int n; 555 555 int nnz; … … 582 582 void MumpsSolve(int n,int nnz,int local_nnz,int* irn_loc,int* jcn_loc,IssmDouble *a_loc,IssmDouble *rhs,Parameters* parameters){/*{{{*/ 583 583 IssmDouble::Tape& tape = IssmDouble::getTape(); 584 codi:: DataStore* dataHandler = NULL;584 codi::ExternalFunctionUserData* dataHandler = NULL; 585 585 586 586 if(tape.isActive()) { 587 dataHandler = new codi:: DataStore();587 dataHandler = new codi::ExternalFunctionUserData(); 588 588 589 589 // create the index and double vector for the matrix 590 590 IssmDouble::Real* valueATrans = xNew<IssmDouble::Real>(local_nnz); 591 IssmDouble:: GradientData* indexATrans = xNew<IssmDouble::GradientData>(local_nnz);591 IssmDouble::Identifier* indexATrans = xNew<IssmDouble::Identifier>(local_nnz); 592 592 int* irnATrans = xNew<int>(local_nnz); 593 593 int* jcnATrans = xNew<int>(local_nnz); … … 601 601 602 602 // create the index vector for a (primal values are not needed for a) 603 IssmDouble:: GradientData* indexB = xNew<IssmDouble::GradientData>(n);603 IssmDouble::Identifier* indexB = xNew<IssmDouble::Identifier>(n); 604 604 getVectorGradData(rhs, indexB, n); 605 605 … … 626 626 if(tape.isActive()) { 627 627 // create the index vector X and register x as active variables 628 IssmDouble:: GradientData* indexX = xNew<IssmDouble::GradientData>(n);628 IssmDouble::Identifier* indexX = xNew<IssmDouble::Identifier>(n); 629 629 registerVector(rhs, indexX, n); 630 630 … … 638 638 dataHandler->addData(parameters); // we assume here that parameters is still intact when the reverse run is called 639 639 640 //tape.pushExternalFunction(&MumpsSolve_codi_b, dataHandler, &MumpsSolve_codi_delete); 641 tape.pushExternalFunctionHandle(&MumpsSolve_codi_b,(void*)dataHandler, &MumpsSolve_codi_delete); 640 tape.pushExternalFunction(codi::ExternalFunction<Tape>::create(&MumpsSolve_codi_b,(void*)dataHandler, &MumpsSolve_codi_delete)); 642 641 } 643 642 else{
Note:
See TracChangeset
for help on using the changeset viewer.