<div dir="ltr">Hello,<div><br></div><div>I'm using ADOL-C and adjoint sensitivity equations to provide derivatives for a nonlinear optimal control problem. As part of the debugging process we ran Valgrind on the code and found some memory issues. Running with Valgrind also caused a segmentation fault:</div>
<div><br></div><div><div>yajun@hessian:~/svn/psaProject/combined2$ valgrind ./compare</div><div>==1841== Memcheck, a memory error detector</div><div>==1841== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.</div>
<div>==1841== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info</div><div>==1841== Command: ./compare</div><div>==1841== </div><div><br></div><div>*Console output from the optimization code removed*</div>
<div>
<br></div><div>==1841== Invalid write of size 8</div><div>==1841== at 0x4E3E7C3: adouble::adouble() (adouble.cpp:66)</div><div>==1841== by 0x436437: tracerhs(double, double*, double*, double*, JACTYPE, bool, int) (tracer_ss.c:34)</div>
<div>==1841== by 0x439363: fQuad(double, _generic_N_Vector*, _generic_N_Vector*, _generic_N_Vector*, void*) (ss_adjoint.c:909)</div><div>==1841== by 0x45F3D3: CVArhsQ (in /home/yajun/svn/psaProject/combined2/compare)</div>
<div>==1841== by 0x44CFF5: cvQuadNls (in /home/yajun/svn/psaProject/combined2/compare)</div><div>==1841== by 0x44901C: cvStep (in /home/yajun/svn/psaProject/combined2/compare)</div><div>==1841== by 0x44362B: CVode (in /home/yajun/svn/psaProject/combined2/compare)</div>
<div>==1841== by 0x45AE1E: CVodeB (in /home/yajun/svn/psaProject/combined2/compare)</div><div>==1841== by 0x43ABAC: simCycles_withAdjoints(double*, double*, double*, int, Logs, double*, double*, int*, int*) (ss_adjoint.c:348)</div>
<div>==1841== by 0x4148FF: main (perturb.cpp:105)</div><div>==1841== Address 0xa73e818 is not stack'd, malloc'd or (recently) free'd</div><div>==1841== </div><div>==1841== </div><div>==1841== Process terminating with default action of signal 11 (SIGSEGV)</div>
<div>==1841== Access not within mapped region at address 0xA73E818</div><div>==1841== at 0x4E3E7C3: adouble::adouble() (adouble.cpp:66)</div><div>==1841== by 0x436437: tracerhs(double, double*, double*, double*, JACTYPE, bool, int) (tracer_ss.c:34)</div>
<div>==1841== by 0x439363: fQuad(double, _generic_N_Vector*, _generic_N_Vector*, _generic_N_Vector*, void*) (ss_adjoint.c:909)</div><div>==1841== by 0x45F3D3: CVArhsQ (in /home/yajun/svn/psaProject/combined2/compare)</div>
<div>==1841== by 0x44CFF5: cvQuadNls (in /home/yajun/svn/psaProject/combined2/compare)</div><div>==1841== by 0x44901C: cvStep (in /home/yajun/svn/psaProject/combined2/compare)</div><div>==1841== by 0x44362B: CVode (in /home/yajun/svn/psaProject/combined2/compare)</div>
<div>==1841== by 0x45AE1E: CVodeB (in /home/yajun/svn/psaProject/combined2/compare)</div><div>==1841== by 0x43ABAC: simCycles_withAdjoints(double*, double*, double*, int, Logs, double*, double*, int*, int*) (ss_adjoint.c:348)</div>
<div>==1841== by 0x4148FF: main (perturb.cpp:105)</div><div>==1841== If you believe this happened as a result of a stack</div><div>==1841== overflow in your program's main thread (unlikely but</div><div>==1841== possible), you can try to increase the size of the</div>
<div>==1841== main thread stack using the --main-stacksize= flag.</div><div>==1841== The main thread stack size used in this run was 8388608.</div><div>==1841== </div><div>==1841== HEAP SUMMARY:</div><div>==1841== in use at exit: 20,183,646 bytes in 31,127 blocks</div>
<div>==1841== total heap usage: 3,172,497 allocs, 3,141,370 frees, 203,707,733 bytes allocated</div><div>==1841== </div><div>==1841== LEAK SUMMARY:</div><div>==1841== definitely lost: 0 bytes in 0 blocks</div><div>==1841== indirectly lost: 0 bytes in 0 blocks</div>
<div>==1841== possibly lost: 34 bytes in 1 blocks</div><div>==1841== still reachable: 20,183,612 bytes in 31,126 blocks</div><div>==1841== suppressed: 0 bytes in 0 blocks</div><div>==1841== Rerun with --leak-check=full to see details of leaked memory</div>
<div>==1841== </div><div>==1841== For counts of detected and suppressed errors, rerun with: -v</div><div>==1841== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)</div><div>Segmentation fault (core dumped)</div>
</div><div><br></div><div>Here is line 34 of tracer_ss.c:</div><div> adouble *cd = new adouble[NEQ];<br></div><div><br></div><div>And lines 53 - 70 of adouble.c:</div><div><div>adouble::adouble() {</div><div> location = next_loc();</div>
<div> ADOLC_OPENMP_THREAD_NUMBER;</div><div> ADOLC_OPENMP_GET_THREAD_NUMBER;</div><div><br></div><div>#if defined(ADOLC_ADOUBLE_STDCZERO)</div><div> if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {</div><div> put_op(assign_d_zero);</div>
<div> ADOLC_PUT_LOCINT(location); // = res</div><div> }</div><div> </div><div> ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;</div><div> if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)</div><div> ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); // Line 66</div>
<div> </div><div> ADOLC_GLOBAL_TAPE_VARS.store[location] = 0.;</div><div>#endif</div><div>}</div></div><div><br></div><div>Has anyone seen this behavior before? Does it mean the dimensions of cd* are violated, or is there a problem with the adouble constructor?</div>
<div><br></div><div>Versions information: ADOL-C: 2.4.1, ColPack: 1.0.9, CVODES (integrator): 2.7.0</div><div><br></div><div>Thanks,</div><div>Alex</div><div><br></div><div><br></div></div>