[CppAD] using CppAD threadsafe

Brad Bell bradbell at seanet.com
Thu Aug 11 00:25:01 EDT 2011


There has been some recent improvements to how CppAD interacts with 
OpenMP; see
     http://www.coin-or.org/CppAD/Doc/whats_new_11.htm

I suggest using svn to download the trunk or downloading the most recent 
tarball at
     http://www.coin-or.org/download/source/CppAD/

The documentation for using CppAD with OpenMP can be found at
     http://www.coin-or.org/CppAD/Doc/omp_parallel.xml

Have you tried running the OpenMP test driver described  here
     http://www.coin-or.org/CppAD/Doc/openmp_run.sh.xml
Especially the AD test documented here
     http://www.coin-or.org/CppAD/Doc/multi_newton.cpp.xml

On 8/10/2011 12:44 PM, Stefan Vigerske wrote:
> 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
>



More information about the CppAD mailing list