This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
View | Details | Raw Unified | Return to bug 466
Collapse All | Expand All

(-)a/Eigen/Core (-1 / +1 lines)
Lines 324-342 using std::ptrdiff_t; Link Here
324
#include "src/Core/IO.h"
324
#include "src/Core/IO.h"
325
#include "src/Core/Swap.h"
325
#include "src/Core/Swap.h"
326
#include "src/Core/CommaInitializer.h"
326
#include "src/Core/CommaInitializer.h"
327
#include "src/Core/Flagged.h"
327
#include "src/Core/Flagged.h"
328
#include "src/Core/ProductBase.h"
328
#include "src/Core/ProductBase.h"
329
#include "src/Core/GeneralProduct.h"
329
#include "src/Core/GeneralProduct.h"
330
#include "src/Core/TriangularMatrix.h"
330
#include "src/Core/TriangularMatrix.h"
331
#include "src/Core/SelfAdjointView.h"
331
#include "src/Core/SelfAdjointView.h"
332
#include "src/Core/products/GeneralBlockPanelKernel.h"
332
#include "src/Core/products/Parallelizer.h"
333
#include "src/Core/products/Parallelizer.h"
333
#include "src/Core/products/CoeffBasedProduct.h"
334
#include "src/Core/products/CoeffBasedProduct.h"
334
#include "src/Core/products/GeneralBlockPanelKernel.h"
335
#include "src/Core/products/GeneralMatrixVector.h"
335
#include "src/Core/products/GeneralMatrixVector.h"
336
#include "src/Core/products/GeneralMatrixMatrix.h"
336
#include "src/Core/products/GeneralMatrixMatrix.h"
337
#include "src/Core/SolveTriangular.h"
337
#include "src/Core/SolveTriangular.h"
338
#include "src/Core/products/GeneralMatrixMatrixTriangular.h"
338
#include "src/Core/products/GeneralMatrixMatrixTriangular.h"
339
#include "src/Core/products/SelfadjointMatrixVector.h"
339
#include "src/Core/products/SelfadjointMatrixVector.h"
340
#include "src/Core/products/SelfadjointMatrixMatrix.h"
340
#include "src/Core/products/SelfadjointMatrixMatrix.h"
341
#include "src/Core/products/SelfadjointProduct.h"
341
#include "src/Core/products/SelfadjointProduct.h"
342
#include "src/Core/products/SelfadjointRank2Update.h"
342
#include "src/Core/products/SelfadjointRank2Update.h"
(-)a/Eigen/src/Core/products/GeneralBlockPanelKernel.h (-3 / +2 lines)
Lines 21-37 Link Here
21
// You should have received a copy of the GNU Lesser General Public
21
// You should have received a copy of the GNU Lesser General Public
22
// License and a copy of the GNU General Public License along with
22
// License and a copy of the GNU General Public License along with
23
// Eigen. If not, see <http://www.gnu.org/licenses/>.
23
// Eigen. If not, see <http://www.gnu.org/licenses/>.
24
24
25
#ifndef EIGEN_GENERAL_BLOCK_PANEL_H
25
#ifndef EIGEN_GENERAL_BLOCK_PANEL_H
26
#define EIGEN_GENERAL_BLOCK_PANEL_H
26
#define EIGEN_GENERAL_BLOCK_PANEL_H
27
27
28
namespace Eigen { 
28
namespace Eigen { 
29
29
  
30
namespace internal {
30
namespace internal {
31
31
32
template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs=false, bool _ConjRhs=false>
32
template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs=false, bool _ConjRhs=false>
33
class gebp_traits;
33
class gebp_traits;
34
34
35
35
36
/** \internal \returns b if a<=0, and returns a otherwise. */
36
/** \internal \returns b if a<=0, and returns a otherwise. */
37
inline std::ptrdiff_t manage_caching_sizes_helper(std::ptrdiff_t a, std::ptrdiff_t b)
37
inline std::ptrdiff_t manage_caching_sizes_helper(std::ptrdiff_t a, std::ptrdiff_t b)
Lines 39-56 inline std::ptrdiff_t manage_caching_siz Link Here
39
  return a<=0 ? b : a;
39
  return a<=0 ? b : a;
40
}
40
}
41
41
42
/** \internal */
42
/** \internal */
43
inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0, std::ptrdiff_t* l2=0)
43
inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0, std::ptrdiff_t* l2=0)
44
{
44
{
45
  static std::ptrdiff_t m_l1CacheSize = 0;
45
  static std::ptrdiff_t m_l1CacheSize = 0;
46
  static std::ptrdiff_t m_l2CacheSize = 0;
46
  static std::ptrdiff_t m_l2CacheSize = 0;
47
  #pragma omp threadprivate(m_l1CacheSize,m_l2CacheSize)
47
  if(m_l2CacheSize==0)
48
  if(m_l1CacheSize==0)
49
  {
48
  {
50
    m_l1CacheSize = manage_caching_sizes_helper(queryL1CacheSize(),8 * 1024);
49
    m_l1CacheSize = manage_caching_sizes_helper(queryL1CacheSize(),8 * 1024);
51
    m_l2CacheSize = manage_caching_sizes_helper(queryTopLevelCacheSize(),1*1024*1024);
50
    m_l2CacheSize = manage_caching_sizes_helper(queryTopLevelCacheSize(),1*1024*1024);
52
  }
51
  }
53
  
52
  
54
  if(action==SetAction)
53
  if(action==SetAction)
55
  {
54
  {
56
    // set the cpu cache size and cache all block sizes from a global cache size in byte
55
    // set the cpu cache size and cache all block sizes from a global cache size in byte
(-)a/Eigen/src/Core/products/Parallelizer.h (-2 / +16 lines)
Lines 52-83 inline void manage_multi_threading(Actio Link Here
52
    #endif
52
    #endif
53
  }
53
  }
54
  else
54
  else
55
  {
55
  {
56
    eigen_internal_assert(false);
56
    eigen_internal_assert(false);
57
  }
57
  }
58
}
58
}
59
59
60
}
61
62
/** Must be call first when calling Eigen from multiple threads */
63
inline void initParallel()
64
{
65
  int nbt;
66
  internal::manage_multi_threading(GetAction, &nbt);
67
  std::ptrdiff_t l1, l2;
68
  internal::manage_caching_sizes(GetAction, &l1, &l2);
69
}
70
60
/** \returns the max number of threads reserved for Eigen
71
/** \returns the max number of threads reserved for Eigen
61
  * \sa setNbThreads */
72
  * \sa setNbThreads */
62
inline int nbThreads()
73
inline int nbThreads()
63
{
74
{
64
  int ret;
75
  int ret;
65
  manage_multi_threading(GetAction, &ret);
76
  internal::manage_multi_threading(GetAction, &ret);
66
  return ret;
77
  return ret;
67
}
78
}
68
79
69
/** Sets the max number of threads reserved for Eigen
80
/** Sets the max number of threads reserved for Eigen
70
  * \sa nbThreads */
81
  * \sa nbThreads */
71
inline void setNbThreads(int v)
82
inline void setNbThreads(int v)
72
{
83
{
73
  manage_multi_threading(SetAction, &v);
84
  internal::manage_multi_threading(SetAction, &v);
74
}
85
}
75
86
87
namespace internal {
88
76
template<typename Index> struct GemmParallelInfo
89
template<typename Index> struct GemmParallelInfo
77
{
90
{
78
  GemmParallelInfo() : sync(-1), users(0), rhs_start(0), rhs_length(0) {}
91
  GemmParallelInfo() : sync(-1), users(0), rhs_start(0), rhs_length(0) {}
79
92
80
  int volatile sync;
93
  int volatile sync;
81
  int volatile users;
94
  int volatile users;
82
95
83
  Index rhs_start;
96
  Index rhs_start;
Lines 116-131 void parallelize_gemm(const Functor& fun Link Here
116
  Index max_threads = std::max<Index>(1,size / 32);
129
  Index max_threads = std::max<Index>(1,size / 32);
117
130
118
  // 3 - compute the number of threads we are going to use
131
  // 3 - compute the number of threads we are going to use
119
  Index threads = std::min<Index>(nbThreads(), max_threads);
132
  Index threads = std::min<Index>(nbThreads(), max_threads);
120
133
121
  if(threads==1)
134
  if(threads==1)
122
    return func(0,rows, 0,cols);
135
    return func(0,rows, 0,cols);
123
136
137
  Eigen::initParallel();
124
  func.initParallelSession();
138
  func.initParallelSession();
125
139
126
  if(transpose)
140
  if(transpose)
127
    std::swap(rows,cols);
141
    std::swap(rows,cols);
128
142
129
  Index blockCols = (cols / threads) & ~Index(0x3);
143
  Index blockCols = (cols / threads) & ~Index(0x3);
130
  Index blockRows = (rows / threads) & ~Index(0x7);
144
  Index blockRows = (rows / threads) & ~Index(0x7);
131
  
145
  
(-)a/doc/TopicMultithreading.dox (+46 lines)
Line 0 Link Here
1
namespace Eigen {
2
3
/** \page TopicMultiThreading Eigen and multi-threading
4
5
\section TopicMultiThreading_MakingEigenMT Make Eigen run in parallel
6
7
Some Eigen's algorithms can exploit the multiple cores present in your hardware. To this end, it is enough to enable OpenMP on your compiler, for instance:
8
 * GCC: \c -fopenmp
9
 * ICC: \c -openmp
10
 * MSVC: check the respective option in the build properties.
11
You can control the number of thread that will be used using either the OpenMP API or Eiegn's API using the following priority:
12
\code
13
 OMP_NUM_THREADS=n ./my_program
14
 omp_set_num_threads(n);
15
 Eigen::setNbThreads(n);
16
\endcode
17
Unless setNbThreads has been called, Eigen uses the number of threads specified by OpenMP. You can restore this bahavior by calling \code setNbThreads(0); \endcode
18
You can query the number of threads that will be used with:
19
\code
20
n = Eigen::nbThreads(n);
21
\endcode
22
You can disable Eigen's multi threading at compile time by defining the EIGEN_DONT_PARALLELIZE preprocessor token.
23
24
Currently, the following algorithms can make use of multi-threading:
25
 * general matrix - matrix products
26
 * PartialPivLU
27
28
\section TopicMultiThreading_UsingEigenWithMT Using Eigen in a multi-threaded application
29
30
In the case your own application is multithreaded, and multiple threads make calls to Eigen, then you have to initialize Eigen by calling the following routine \b before creating the threads:
31
\code
32
#include <Eigen/Core>
33
34
int main(int argc, char** argv)
35
{
36
  Eigen::initParallel();
37
  
38
  ...
39
}
40
\endcode
41
42
In the case your application is parallelized with OpenMP, you might want to disable Eigen's own parallization as detailed in the previous section.
43
44
*/
45
46
}

Return to bug 466