Re: [eigen] Help on solving a race condition

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


CppAD uses the following approach:

Single threaded code does not need to do anything special, but multi-threaded code needs to do extra things (like initialize static variables) and there are special routines to help do so. See
    http://www.coin-or.org/CppAD/Doc/multi_thread.xml
and
https://projects.coin-or.org/CppAD/browser/trunk/cppad/local/parallel_ad.hpp


On 06/08/2012 06:12 AM, Gael Guennebaud wrote:
Hi,

I'm looking for some help on understanding how the following piece of
code in Eigen can lead to a race condition when the function
manage_caching_sizes is called from different threads:


inline std::ptrdiff_t manage_caching_sizes_helper(std::ptrdiff_t a,
std::ptrdiff_t b)
{
   return a<=0 ? b : a;
}

inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0,
std::ptrdiff_t* l2=0)
{
   static std::ptrdiff_t m_l1CacheSize =
manage_caching_sizes_helper(queryL1CacheSize(),8 * 1024);
   static std::ptrdiff_t m_l2CacheSize =
manage_caching_sizes_helper(queryTopLevelCacheSize(),1*1024*1024);
   ...
}


During it's first call, this function computes and store the cache sizes.

I would like to find a solution that avoids making the static variable
"thread private" as suggested there:
http://stackoverflow.com/questions/8828466/using-openmp-and-eigen-causes-infinite-loop-deadlock/10540025
The problem with this approach, is that the cache-sizes are recomputed
for every thread.


thanks,

Gaël







Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/