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 |
|