[ADOL-C] tapeless adol-c question

Kshitij Kulshreshtha kshitij at math.upb.de
Wed May 21 14:30:20 EDT 2014


Hello,

As on 2014-05-21 20:06, Ian Washington did write:
> Thanks kshitij,
> 
> The only location where I dynamically allocate adtl::adouble is in the
> function 'ad_evaluate' given as,
> 
> void ad_evaluate
> ( int n, int m, int numdirs, double *xinit,
>   double **Seed_J, double ***Jc_ret )
> {
>    adtl::adouble *x = new adtl::adouble[n];
>    adtl::adouble *y = new adtl::adouble[m];
> 
>    for (int i=0; i<n; i++) x[i] = xinit[i];
> 
>    for (int i=0; i<n;++i) {
>      x[i].setADValue(Seed_J[i]);
>    }
> 
>    ceval_ad_tl(n, x, m, y); <-- evaluate functions
> 
>    double **Jc = myalloc2(m, numdirs);
> 
>    for (int i=0; i<m; i++){
>      for (int j=0; j<numdirs; j++)
>        Jc[i][j] = y[i].getADValue(j);
>    }
> 
>    *Jc_ret = Jc;
> 
>    delete[] x; <-- KILLED HERE
>    delete[] y; <-- KILLED HERE
> }
> 
> Note that I delete these adtl::adouble's after coping the Jacobian.

Yes so this looks alright.

> 
> Also there are many array definitions of adtl::adouble in the function
> 'ceval_ad_tl' :
> 
> void ceval_ad_tl(int n, adtl::adouble *x, int m, adtl::adouble *c)
> {
>   adtl::adouble cA[nde][nel][3];
>   adtl::adouble cB[nde][nel][3];
>   adtl::adouble cAdot[nde][nel][3];
>   adtl::adouble cBdot[nde][nel][3];
> 
>   adtl::adouble q1,qde,qfe,qex,time;
>   adtl::adouble q2,q3,q4,qra;
> 
>   adtl::adouble sum;
> 
>  ...
> 
> }
> 
> Do you think these definitions are the problem? Should I change these
> arrays to be dynamically allocated, so that they can be deleted? What
> about the scalar variables?

You should try to allocate and deallocate all arrays whenever possible
with new[] and delete[]. The scalars should be deleted as soon as they
go out of scope.

If you still get the warning try to see what the value of
refcounter::refcnt variable is in a debugger. When all the adtl::adouble
objects have been deleted it should be 0.

Regards
Kshitij

-- 
Dr. Kshitij Kulshreshtha

Institut für Mathematik,
Universität Paderborn,
Warburger Straße 100,
33098 Paderborn.

Büro: A3.235

Privatanschrift:
Arnikaweg 62
33100 Paderborn.


More information about the ADOL-C mailing list