[ADOL-C] tapeless adol-c question

Ian Washington washinid at mcmaster.ca
Tue May 20 17:21:56 EDT 2014


Hello all,

I am new to the tapeless version of adol-c and I have a question related
to setting the number of directional derivatives (numdirs) when using
the forward vector mode.

In essence I would like to reset numdirs for a number of possibly
different Jacobian matrices.

For example, consider the following 'pseudo' code:

#define ADOLC_TAPELESS
#include <adolc/adolc.h>
#include <adolc/adolc_sparse.h>
#include <adolc/adtl.h>
#include <ColPack/ColPackHeaders.h>

int main() {

  // n = indep.
  // m = dep.
  // xinit = initial point
  // gGraph = colpack via 'BipartiteGraphPartialColoringInterface'
  // Seed_J = seed
  // Jac_P = jac. pattern using 'jac_pat'
  // nnz = nonzeros
  // numdirs = directions

  // preprocess to get Seed and Jac. pattern

  ad_preprocess(n, m, xinit, &gGraph, &Seed_J, &Jac_P, &nnz, &numdirs);

  // note, ad_preprocess uses the tape-based adolc to get Jac_P, Seed_J

  // set numdirs (must be called before adtl::adouble definitions)

  adtl::setNumDir(numdirs);

  // evaluate to get compressed Jac.

  ad_evaluate(n, m, numdirs, xinit, Seed_J, &Jc);

  // re-set everything and get a possibly new Jac.

  adtl::setNumDir(numdirs_n);  <--- PROBLEM HERE

  ad_evaluate(n_n, m_n, numdirs_n, xinit_n, Seed_J_n, &Jc_n);

  return 0;
}

where the 'ad_evaluate' function is:

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;
  delete[] y;
}


The problem with the above is when I reset numdirs using
adtl::setNumDir(numdirs_n) the second time I get the following:

ADOL-C Warning: Tapeless: Setting numDir will not change the number of
directional derivative in existing adoubles and may lead to erronious
results or memory corruption

Note, if I just remove the second adtl::setNumDir(numdirs_n) and
evaluate the same Jacobian everything works fine.

So my question is how do I compute two different Jacobian matrices in
the same program, which have a different Seed and number of directional
derivatives?

Thanks,
Ian.







More information about the ADOL-C mailing list