1#ifndef IRLBA_PARALLEL_HPP
2#define IRLBA_PARALLEL_HPP
8#ifndef IRLBA_CUSTOM_PARALLEL
9#include "subpar/subpar.hpp"
32template<
typename Task_,
class Run_>
34#ifndef IRLBA_CUSTOM_PARALLEL
117 if (my_column_major) {
118 return my_secondary_dim;
120 return my_primary_dim;
128 if (my_column_major) {
129 return my_primary_dim;
131 return my_secondary_dim;
162 typedef typename std::remove_const<typename std::remove_reference<decltype(std::declval<PointerArray_>()[0])>::type>::type
PointerType;
165 Eigen::Index my_primary_dim, my_secondary_dim;
170 bool my_column_major;
172 typedef typename std::remove_const<typename std::remove_reference<decltype(std::declval<IndexArray_>()[0])>::type>::type IndexType;
174 std::vector<size_t> my_primary_starts, my_primary_ends;
175 std::vector<IndexType> my_secondary_ends;
176 std::vector<std::vector<PointerType> > my_secondary_nonzero_starts;
187 return my_primary_starts;
197 return my_primary_ends;
209 return my_secondary_nonzero_starts;
214 void fragment_threads() {
219 my_primary_starts.resize(my_nthreads);
220 my_primary_ends.resize(my_nthreads);
224 for (
int t = 0;
t < my_nthreads; ++
t) {
235 my_secondary_ends.resize(my_nthreads + 1);
236 my_secondary_nonzero_starts.resize(my_nthreads + 1, std::vector<PointerType>(my_primary_dim));
247 for (
int t = 0;
t < my_nthreads; ++
t) {
256 for (Eigen::Index
c = 0;
c < my_primary_dim; ++
c) {
266 my_secondary_nonzero_starts[
thread + 1][
c] =
s;
274 if (my_nthreads == 1) {
276 for (Eigen::Index
c = 0;
c < my_primary_dim; ++
c) {
278 auto end = my_ptrs[
c + 1];
281 output.coeffRef(my_indices[
s]) += my_values[
s] *
val;
295 typename EigenVector_::Scalar*
optr;
305 const auto&
nz_starts = my_secondary_nonzero_starts[
t];
306 const auto&
nz_ends = my_secondary_nonzero_starts[
t + 1];
307 for (Eigen::Index
c = 0;
c < my_primary_dim; ++
c) {
325 if (my_nthreads == 1) {
326 for (Eigen::Index
c = 0;
c < my_primary_dim; ++
c) {
334 auto curend = my_primary_ends[
t];
343 template<
typename Scalar_>
348 dot += my_values[
s] *
rhs.coeff(my_indices[
s]);
359 std::vector<std::vector<typename EigenVector_::Scalar> > thread_buffers;
362 Workspace workspace()
const {
364 if (my_nthreads > 1 && my_column_major) {
365 output.thread_buffers.resize(my_nthreads - 1);
370 struct AdjointWorkspace {
372 std::vector<std::vector<typename EigenVector_::Scalar> > thread_buffers;
375 AdjointWorkspace adjoint_workspace()
const {
377 if (my_nthreads > 1 && !my_column_major) {
378 output.thread_buffers.resize(my_nthreads - 1);
384 template<
class Right_>
387 if (my_column_major) {
394 template<
class Right_>
397 if (my_column_major) {
405 template<
class EigenMatrix_>
411 if (my_column_major) {
412 for (Eigen::Index
c = 0;
c <
nc; ++
c) {
415 output.coeffRef(my_indices[
s],
c) = my_values[
s];
419 for (Eigen::Index
r = 0;
r <
nr; ++
r) {
422 output.coeffRef(
r, my_indices[
s]) = my_values[
s];
460#ifdef IRLBA_CUSTOM_PARALLEL
461#ifdef IRLBA_CUSTOM_PARALLEL_USES_OPENMP
464 Eigen::setNbThreads(1);
467#ifdef SUBPAR_USES_OPENMP_SIMPLE
470 Eigen::setNbThreads(1);
Restrict the number of available threads for Eigen.
Definition parallel.hpp:449
Sparse matrix with customizable parallelization.
Definition parallel.hpp:74
std::remove_const< typenamestd::remove_reference< decltype(std::declval< PointerArray_ >()[0])>::type ::type PointerType
Definition parallel.hpp:162
const IndexArray_ & get_indices() const
Definition parallel.hpp:147
const ValueArray_ & get_values() const
Definition parallel.hpp:139
const std::vector< size_t > & get_primary_ends() const
Definition parallel.hpp:196
Eigen::Index rows() const
Definition parallel.hpp:116
const std::vector< size_t > & get_primary_starts() const
Definition parallel.hpp:186
const PointerArray_ & get_pointers() const
Definition parallel.hpp:154
const std::vector< std::vector< PointerType > > & get_secondary_nonzero_starts() const
Definition parallel.hpp:208
ParallelSparseMatrix()
Definition parallel.hpp:80
Eigen::Index cols() const
Definition parallel.hpp:127
ParallelSparseMatrix(Eigen::Index nrow, Eigen::Index ncol, ValueArray_ x, IndexArray_ i, PointerArray_ p, bool column_major, int nthreads)
Definition parallel.hpp:98
Implements IRLBA for approximate SVD.
Definition compute.hpp:18
void parallelize(Task_ num_tasks, Run_ run_task)
Definition parallel.hpp:33
EigenMatrix_ wrapped_realize(const Matrix_ &matrix)
Definition wrappers.hpp:185