[CppAD] using CppAD threadsafe
Stefan Vigerske
stefan at math.hu-berlin.de
Wed Aug 10 15:44:59 EDT 2011
Hi,
I try to use CppAD 20110101.0 in a multithreading environment (pthreads).
That is, there are several threads running in parallel, each one using
CppAD to compute derivatives.
If I use CppAD like I am used to, I get strange error messages or
segmentation faults.
Looking a bit around, it seems that CppAD stores the tapes in some
static global variable.
But I saw these OpenMP stuff, so I compiled my code with -fopenmp.
Now I still get an error:
CppAD 20110101.0 error from a known source:
Independent: cannot create a new tape because
a previous tape is still active (for this thread).
AD<Base>::abort_recording() would abort this previous recording.
Error detected by false result for
ADBase::tape_ptr() == CPPAD_NULL
at line 172 in the file
lib/cppad/local/independent.hpp
OpenMP: thread_num = 0
I guess this is because CppAD cannot distinguish the different threads
that I'm using, thus always assumes it is called from thread 0.
It seems to use omp_get_thread_num to get the thread number, but a
printf tells me that this is always 0, which isn't suprising, since the
program I'm using uses the pthreads library for parallelization, so how
should omp_get_thread_num() know?
I also printed omp_get_max_threads() and this gives me 4, on a quad-core
machine. Seems ok. So I doubt that calling
omp_alloc::set_max_num_threads(number) would make any difference.
In the documentation it says something about calling
CppAD::omp_alloc::set_max_num_threads, but this function, or the whole
omp_alloc, does not seem to exists in the CppAD version that I'm using.
Any idea how to make CppAD threadsafe?
Stefan
--
Stefan Vigerske
Humboldt University Berlin, Numerical Mathematics
http://www.math.hu-berlin.de/~stefan
More information about the CppAD
mailing list