Changeset 27732
- Timestamp:
- 05/08/23 07:00:31 (23 months ago)
- Location:
- issm/trunk-jpl/src/c/cores
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp
r27728 r27732 208 208 femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum); 209 209 210 /* In transient,we need to make sure we do not modify femmodel at each iteration, make a copy*/211 if(solution_type == TransientSolutionEnum)femmodel = input_struct->femmodel->copy();210 /*we need to make sure we do not modify femmodel at each iteration, make a copy*/ 211 femmodel = input_struct->femmodel->copy(); 212 212 213 213 IssmPDouble* Jlist = input_struct->Jlist; … … 313 313 314 314 /*Get Dependents*/ 315 IssmDouble output_value;316 315 int num_dependents; 317 316 IssmPDouble *dependents; … … 333 332 dep->RecordResponsex(femmodel); 334 333 IssmDouble output_value = dep->GetValue(); 335 336 #if defined(_HAVE_CODIPACK_)337 tape_codi.registerOutput(output_value);338 334 dependents[i] = output_value.getValue(); 339 #if _CODIPACK_MAJOR_==2 340 codi_global.output_indices.push_back(output_value.getIdentifier()); 341 #elif _CODIPACK_MAJOR_==1 342 codi_global.output_indices.push_back(output_value.getGradientData()); 343 #else 344 #error "_CODIPACK_MAJOR_ not supported" 335 #if defined(_HAVE_ADOLC_) 336 output_value>>=dependents[i]; 345 337 #endif 346 338 347 #elif defined(_HAVE_ADOLC_)348 output_value>>=dependents[i];349 350 #else351 _error_("not suppoted");352 #endif353 354 339 J+=output_value; 355 340 } 341 342 #if defined(_HAVE_CODIPACK_) 343 tape_codi.registerOutput(J); 344 #if _CODIPACK_MAJOR_==2 345 codi_global.output_indices.push_back(J.getIdentifier()); 346 #elif _CODIPACK_MAJOR_==1 347 codi_global.output_indices.push_back(J.getGradientData()); 348 #else 349 #error "_CODIPACK_MAJOR_ not supported" 350 #endif 351 #endif 356 352 357 353 /*Turning off trace tape*/ … … 423 419 /*Get gradient for CoDiPack{{{*/ 424 420 if(VerboseAutodiff())_printf0_(" CoDiPack fos_reverse\n"); 425 426 /* call the fos_reverse in a loop on the index, from 0 to num_dependents, so 427 * as to generate num_dependents gradients: */ 428 for(int dep_index=0;dep_index<num_dependents_old;dep_index++){ 429 430 /*initialize direction index in the weights vector: */ 431 if(my_rank==0){ 432 if(dep_index<0 || dep_index>=num_dependents || codi_global.output_indices.size() <= dep_index){ 433 _error_("index value for dependent index should be in [0,num_dependents-1]"); 434 } 435 tape_codi.setGradient(codi_global.output_indices[dep_index],1.0); 436 } 437 //feclearexcept(FE_ALL_EXCEPT); 438 //feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); 439 tape_codi.evaluate(); 440 441 /*Get gradient for this dependent */ 442 weightVectorTimesJac=xNew<IssmPDouble>(num_independents); 443 auto in_size = codi_global.input_indices.size(); 444 for(size_t i = 0; i < in_size; ++i){ 445 _assert_(i<num_independents); 446 weightVectorTimesJac[i] = tape_codi.getGradient(codi_global.input_indices[i]); 447 } 448 if(my_rank==0) for(int i=0;i<num_independents;i++){ 449 totalgradient[i]+=weightVectorTimesJac[i]; 450 } 451 xDelete(weightVectorTimesJac); 421 if(my_rank==0) tape_codi.setGradient(codi_global.output_indices[0],1.0); 422 tape_codi.evaluate(); 423 424 auto in_size = codi_global.input_indices.size(); 425 for(size_t i = 0; i < in_size; ++i){ 426 _assert_(i<num_independents); 427 totalgradient[i] = tape_codi.getGradient(codi_global.input_indices[i]); 452 428 } 453 429 … … 520 496 521 497 /*Clean-up and return*/ 522 if(solution_type == TransientSolutionEnum)delete femmodel;498 delete femmodel; 523 499 *Jlisti = (*Jlisti) +1; 524 500 xDelete<double>(XU); -
issm/trunk-jpl/src/c/cores/transient_core.cpp
r27728 r27732 399 399 J += output_value; 400 400 401 tape_codi.registerOutput(J);402 #if _CODIPACK_MAJOR_==2403 codi_global.output_indices.push_back(J.getIdentifier());404 #elif _CODIPACK_MAJOR_==1405 codi_global.output_indices.push_back(J.getGradientData());406 #else407 #error "_CODIPACK_MAJOR_ not supported"408 #endif409 410 401 /*Keep track of output for printing*/ 411 402 Jlist[count] = output_value.getValue(); … … 415 406 _assert_(count == num_responses); 416 407 408 #if defined(_HAVE_CODIPACK_) 409 tape_codi.registerOutput(J); 410 #if _CODIPACK_MAJOR_==2 411 codi_global.output_indices.push_back(J.getIdentifier()); 412 #elif _CODIPACK_MAJOR_==1 413 codi_global.output_indices.push_back(J.getGradientData()); 414 #else 415 #error "_CODIPACK_MAJOR_ not supported" 416 #endif 417 #endif 418 417 419 tape_codi.setPassive(); 418 420 419 421 if(VerboseAutodiff())_printf0_(" CoDiPack fos_reverse\n"); 420 for(int i=0;i<num_responses;i++){ 421 if(my_rank==0) tape_codi.setGradient(codi_global.output_indices[i],1.0); 422 tape_codi.evaluate(); 423 } 422 if(my_rank==0) tape_codi.setGradient(codi_global.output_indices[0],1.0); 423 tape_codi.evaluate(); 424 424 425 425 /*Initialize Xb and Yb*/
Note:
See TracChangeset
for help on using the changeset viewer.