[CppAD] Use of global var for tape

Iakov Nakhimovski Iakov.Nakhimovski at gmail.com
Thu Aug 11 05:00:52 EDT 2011


Dear Brad,

I've just started to use CppAD and so the answer to my question might
be obvious.
It seems that use of global variable for storing tape is giving a lot
of troubles in multithreading case. Have you considered other options?
For instance:
1) Use ref counting, e.g., boost::shared_ptr
- tape_this pointer in the AD<Base> is a boost::shared_ptr<ADTape<Base> >
- Independent(X) constructs a new ADTape and then sets the tape
pointers in the X
- All the assignment operators transfer the tape_ptr from arguments to
the left hand side.
- Dependent() transfers the tape to ADFunc and then cleans the tape
pointers in the AD<Base> objects. It should check that the tape is the
same as in X or NULL in all the Y.

2) Make the tape creation explicit to the user
- tape_this pointer in the AD<Base> is a normal pointer to ADTape<Base>
- Independent(X) either returns a tape pointer or the user is expected
to construct ADTape and then call Independent on it
- All the assignment operators transfer the tape_ptr from arguments to
the left hand side
- Dependent() might clone the tape object or just store a pointer to
it in ADFunc

I can think of some more options that are variations of the above.

When it comes to OpenMP and CppAD I can think of two use cases that
might be of general interest:
1. Automatically use threads to speed up Jacobian/Hessian calculation.
2. When modeling coupled subsystems parts of calculation may be done
in parallel:
- Independent(X1,X2)
- In paralllel (might use some omp private AD<Base> variables):
thread1: tmp1(X1), thread2: tmp2(X2).
- In serial: Y1(tmp1, tmp2), Y2(tmp1, tmp2)
- Dependent(Y, X)

Thanks is advance!

/Iakov



More information about the CppAD mailing list