25 #ifndef EIGEN_PARALLELIZER_H
26 #define EIGEN_PARALLELIZER_H
45 #ifdef EIGEN_HAS_OPENMP
49 *v = omp_get_max_threads();
67 std::ptrdiff_t l1, l2;
89 template<
typename Index>
struct GemmParallelInfo
91 GemmParallelInfo() : sync(-1), users(0), rhs_start(0), rhs_length(0) {}
100 template<
bool Condition,
typename Functor,
typename Index>
105 #if !(defined (EIGEN_HAS_OPENMP)) || defined (EIGEN_USE_BLAS)
111 func(0,rows, 0,cols);
122 if((!Condition) || (omp_get_num_threads()>1))
123 return func(0,rows, 0,cols);
125 Index size = transpose ? cols : rows;
129 Index max_threads = std::max<Index>(1,size / 32);
132 Index threads = std::min<Index>(
nbThreads(), max_threads);
135 return func(0,rows, 0,cols);
138 func.initParallelSession();
141 std::swap(rows,cols);
143 Index blockCols = (cols / threads) & ~Index(0x3);
144 Index blockRows = (rows / threads) & ~Index(0x7);
146 GemmParallelInfo<Index>* info =
new GemmParallelInfo<Index>[threads];
148 #pragma omp parallel for schedule(static,1) num_threads(threads)
149 for(Index i=0; i<threads; ++i)
151 Index r0 = i*blockRows;
152 Index actualBlockRows = (i+1==threads) ? rows-r0 : blockRows;
154 Index c0 = i*blockCols;
155 Index actualBlockCols = (i+1==threads) ? cols-c0 : blockCols;
157 info[i].rhs_start = c0;
158 info[i].rhs_length = actualBlockCols;
161 func(0, cols, r0, actualBlockRows, info);
163 func(r0, actualBlockRows, 0,cols, info);
174 #endif // EIGEN_PARALLELIZER_H