10 #ifndef EIGEN_PARALLELIZER_H
11 #define EIGEN_PARALLELIZER_H
18 inline void manage_multi_threading(Action action,
int* v)
20 static EIGEN_UNUSED
int m_maxThreads = -1;
24 eigen_internal_assert(v!=0);
27 else if(action==GetAction)
29 eigen_internal_assert(v!=0);
30 #ifdef EIGEN_HAS_OPENMP
34 *v = omp_get_max_threads();
41 eigen_internal_assert(
false);
48 inline void initParallel()
51 internal::manage_multi_threading(GetAction, &nbt);
52 std::ptrdiff_t l1, l2, l3;
53 internal::manage_caching_sizes(GetAction, &l1, &l2, &l3);
58 inline int nbThreads()
61 internal::manage_multi_threading(GetAction, &ret);
67 inline void setNbThreads(
int v)
69 internal::manage_multi_threading(SetAction, &v);
74 template<
typename Index>
struct GemmParallelInfo
76 GemmParallelInfo() : sync(-1), users(0), lhs_start(0), lhs_length(0) {}
85 template<
bool Condition,
typename Functor,
typename Index>
86 void parallelize_gemm(
const Functor& func, Index rows, Index cols,
bool transpose)
90 #if !(defined (EIGEN_HAS_OPENMP)) || defined (EIGEN_USE_BLAS)
95 EIGEN_UNUSED_VARIABLE(transpose);
107 if((!Condition) || (omp_get_num_threads()>1))
108 return func(0,rows, 0,cols);
110 Index size = transpose ? rows : cols;
114 Index max_threads = std::max<Index>(1,size / 32);
117 Index threads = std::min<Index>(nbThreads(), max_threads);
120 return func(0,rows, 0,cols);
122 Eigen::initParallel();
123 func.initParallelSession(threads);
126 std::swap(rows,cols);
128 ei_declare_aligned_stack_constructed_variable(GemmParallelInfo<Index>,info,threads,0);
130 #pragma omp parallel num_threads(threads)
132 Index i = omp_get_thread_num();
134 Index actual_threads = omp_get_num_threads();
136 Index blockCols = (cols / actual_threads) & ~Index(0x3);
137 Index blockRows = (rows / actual_threads);
138 blockRows = (blockRows/Functor::Traits::mr)*Functor::Traits::mr;
140 Index r0 = i*blockRows;
141 Index actualBlockRows = (i+1==actual_threads) ? rows-r0 : blockRows;
143 Index c0 = i*blockCols;
144 Index actualBlockCols = (i+1==actual_threads) ? cols-c0 : blockCols;
146 info[i].lhs_start = r0;
147 info[i].lhs_length = actualBlockRows;
149 if(transpose) func(c0, actualBlockCols, 0, rows, info);
150 else func(0, rows, c0, actualBlockCols, info);
159 #endif // EIGEN_PARALLELIZER_H
Definition: Eigen_Colamd.h:54