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);
51 internal::manage_multi_threading(GetAction, &nbt);
52 std::ptrdiff_t l1, l2, l3;
53 internal::manage_caching_sizes(GetAction, &l1, &l2, &l3);
61 internal::manage_multi_threading(GetAction, &ret);
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 Index size = transpose ? rows : cols;
108 Index pb_max_threads = std::max<Index>(1,size / 32);
115 if((!Condition) || (threads==1) || (omp_get_num_threads()>1))
116 return func(0,rows, 0,cols);
119 func.initParallelSession(threads);
122 std::swap(rows,cols);
124 ei_declare_aligned_stack_constructed_variable(GemmParallelInfo<Index>,info,threads,0);
126 #pragma omp parallel num_threads(threads) 128 Index i = omp_get_thread_num();
130 Index actual_threads = omp_get_num_threads();
132 Index blockCols = (cols / actual_threads) & ~
Index(0x3);
133 Index blockRows = (rows / actual_threads);
134 blockRows = (blockRows/Functor::Traits::mr)*Functor::Traits::mr;
136 Index r0 = i*blockRows;
137 Index actualBlockRows = (i+1==actual_threads) ? rows-r0 : blockRows;
139 Index c0 = i*blockCols;
140 Index actualBlockCols = (i+1==actual_threads) ? cols-c0 : blockCols;
142 info[i].lhs_start = r0;
143 info[i].lhs_length = actualBlockRows;
145 if(transpose) func(c0, actualBlockCols, 0, rows, info);
146 else func(0, rows, c0, actualBlockCols, info);
155 #endif // EIGEN_PARALLELIZER_H void initParallel()
Definition: Parallelizer.h:48
Namespace containing all symbols from the Eigen library.
Definition: Core:271
int nbThreads()
Definition: Parallelizer.h:58
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: XprHelper.h:35
Definition: Eigen_Colamd.h:50
void setNbThreads(int v)
Definition: Parallelizer.h:67