Dominik, could you provide a standalone testcase that would allow us to reproduce the problem you&#39;re experiencing?<br>
<br>Brad,<br><br>&gt; 3. I am not sure I understand the discussion below. Are you trying to use<br>&gt; CppAD without calling parallel_setup ? Or have you found a bug in CppAD ?<br>
<br>I am calling parallel_setup, and I don&#39;t know whether everything is working correctly or not. I&#39;m using helgrind to check for threading errors, and it does issue some warnings in CppAD::ADFun&lt;double&gt;::operator=, but helgrind tends to be conservative in the errors it reports and could be simply complaining about code that is actually thread safe.<br>
<br>I don&#39;t quite understand the motivation for the thread_alloc machinery.<br><br>-Jey<br><br><br><div class="gmail_quote">On Mon, Mar 19, 2012 at 3:25 PM,  <span dir="ltr">&lt;<a href="mailto:bradbell@seanet.com">bradbell@seanet.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">1. If you do not call hold_memory<br>
  <a href="http://www.coin-or.org/CppAD/Doc/ta_hold_memory.xml" target="_blank">http://www.coin-or.org/CppAD/Doc/ta_hold_memory.xml</a><br>
then CppAD will not hold onto memory for quick use by the same thread;<br>
i.e., the behavior will be very close to using the original system<br>
allocator.<br>
<br>
2. It is still in the CppAD API requirements to call parallel_setup<br>
   <a href="http://www.coin-or.org/CppAD/Doc/ta_parallel_setup.xml" target="_blank">http://www.coin-or.org/CppAD/Doc/ta_parallel_setup.xml</a><br>
before using CppAD with multiple threads.<br>
<br>
3. I am not sure I understand the discussion below. Are you trying to use<br>
CppAD without calling parallel_setup ? Or have you found a bug in CppAD ?<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
&gt; Hi Dominik,<br>
&gt;<br>
&gt; Is this occurring because thread_alloc expects memory to be freed from<br>
&gt; the same thread where it&#39;s allocated?<br>
&gt;<br>
&gt;&gt; Or is it really true that independently  allocating memory in<br>
&gt;&gt; one thread  slows down everything even so no mutex mechanism is needed?<br>
&gt;<br>
&gt; This can happen when using a malloc that isn&#39;t designed for threading<br>
&gt; workloads, but it&#39;s easy to select an alternate malloc on modern<br>
&gt; systems. For example under Linux/x86 and Linux/x86-64 options include<br>
&gt; TCMalloc, jemalloc, TBBmalloc, and hoard. In practice I would<br>
&gt; recommend just using the system malloc until you&#39;ve determined that<br>
&gt; the malloc is actually a performance problem. The important thing<br>
&gt; however is to use a *thread-safe* malloc, for example under Linux with<br>
&gt; GCC you should pass the &quot;-pthreads&quot; option to GCC when compiling and<br>
&gt; linking. (It may not be enough to pass &quot;-lpthread&quot; when linking since<br>
&gt; &quot;-pthreads&quot; enables other options too.)<br>
&gt;<br>
&gt; Attached is a rudimentary patch that switches thread_alloc to use<br>
&gt; operator new and delete directly. You might want to give that a shot.<br>
&gt;<br>
&gt; However, even after using this patch and building with -DNDEBUG, I<br>
&gt; still get some warnings from helgrind about data races in<br>
&gt; CppAD::ADFun&lt;double&gt;::operator=, and I don&#39;t know whether they are<br>
&gt; simply spurious warnings. I&#39;m planning to switch to a multiprocess<br>
&gt; model using mmap(MAP_SHARED) and fork() to avoid these issues.<br>
&gt;<br>
&gt; -Jey<br>
&gt;<br>
&gt; On Mon, Mar 19, 2012 at 9:00 AM, Dominik Skanda<br>
&gt; &lt;<a href="mailto:Dominik.Skanda@biologie.uni-freiburg.de">Dominik.Skanda@biologie.uni-freiburg.de</a>&gt; wrote:<br>
&gt;&gt; Concerning my last message, I have looked a little bit deeper in the<br>
&gt;&gt; code and found out that essentially the command<br>
&gt;&gt;<br>
&gt;&gt; pod_vector&lt;Base&gt; Partial;<br>
&gt;&gt; Partial.extend(total_num_var_ * p);<br>
&gt;&gt;<br>
&gt;&gt; in reverse.hpp causes the error.<br>
&gt;&gt; So  as far as I think the Vector Partial is only accesed within the<br>
&gt;&gt; function<br>
&gt;&gt;<br>
&gt;&gt; &quot;VectorBase ADFun&lt;Base&gt;::Reverse(size_t p, const VectorBase &amp;w)&quot;<br>
&gt;&gt;<br>
&gt;&gt; and therefore should be thread safe (Since it is no global variable)! On<br>
&gt;&gt; the other side due to the new memory allocater it is not. I think that<br>
&gt;&gt; the new memory allocator should only be used were global information is<br>
&gt;&gt; created. Or is it really true that independently  allocating memory in<br>
&gt;&gt; one thread  slows down everything even so no mutex mechanism is needed?<br>
&gt;&gt; This would made the applicability of the CppAD Library really much more<br>
&gt;&gt; flexible!<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; CppAD mailing list<br>
&gt;&gt; <a href="mailto:CppAD@list.coin-or.org">CppAD@list.coin-or.org</a><br>
&gt;&gt; <a href="http://list.coin-or.org/mailman/listinfo/cppad" target="_blank">http://list.coin-or.org/mailman/listinfo/cppad</a><br>
&gt; _______________________________________________<br>
&gt; CppAD mailing list<br>
&gt; <a href="mailto:CppAD@list.coin-or.org">CppAD@list.coin-or.org</a><br>
&gt; <a href="http://list.coin-or.org/mailman/listinfo/cppad" target="_blank">http://list.coin-or.org/mailman/listinfo/cppad</a><br>
&gt;<br>
<br>
<br>
</div></div></blockquote></div><br>