mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
bug #466: better fix for the race condition: this new patch add an initParallel()
function which must be called at the initialization time of any multi-threaded application calling Eigen from multiple threads.
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
#define EIGEN_GENERAL_BLOCK_PANEL_H
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs=false, bool _ConjRhs=false>
|
||||
@@ -44,8 +44,7 @@ inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0, std::ptrdi
|
||||
{
|
||||
static std::ptrdiff_t m_l1CacheSize = 0;
|
||||
static std::ptrdiff_t m_l2CacheSize = 0;
|
||||
#pragma omp threadprivate(m_l1CacheSize,m_l2CacheSize)
|
||||
if(m_l1CacheSize==0)
|
||||
if(m_l2CacheSize==0)
|
||||
{
|
||||
m_l1CacheSize = manage_caching_sizes_helper(queryL1CacheSize(),8 * 1024);
|
||||
m_l2CacheSize = manage_caching_sizes_helper(queryTopLevelCacheSize(),1*1024*1024);
|
||||
|
||||
@@ -57,12 +57,23 @@ inline void manage_multi_threading(Action action, int* v)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Must be call first when calling Eigen from multiple threads */
|
||||
inline void initParallel()
|
||||
{
|
||||
int nbt;
|
||||
internal::manage_multi_threading(GetAction, &nbt);
|
||||
std::ptrdiff_t l1, l2;
|
||||
internal::manage_caching_sizes(GetAction, &l1, &l2);
|
||||
}
|
||||
|
||||
/** \returns the max number of threads reserved for Eigen
|
||||
* \sa setNbThreads */
|
||||
inline int nbThreads()
|
||||
{
|
||||
int ret;
|
||||
manage_multi_threading(GetAction, &ret);
|
||||
internal::manage_multi_threading(GetAction, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -70,9 +81,11 @@ inline int nbThreads()
|
||||
* \sa nbThreads */
|
||||
inline void setNbThreads(int v)
|
||||
{
|
||||
manage_multi_threading(SetAction, &v);
|
||||
internal::manage_multi_threading(SetAction, &v);
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<typename Index> struct GemmParallelInfo
|
||||
{
|
||||
GemmParallelInfo() : sync(-1), users(0), rhs_start(0), rhs_length(0) {}
|
||||
@@ -121,6 +134,7 @@ void parallelize_gemm(const Functor& func, Index rows, Index cols, bool transpos
|
||||
if(threads==1)
|
||||
return func(0,rows, 0,cols);
|
||||
|
||||
Eigen::initParallel();
|
||||
func.initParallelSession();
|
||||
|
||||
if(transpose)
|
||||
|
||||
Reference in New Issue
Block a user