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<std::vector<PointerType> > my_secondary_nonzero_starts;
186 return my_primary_starts;
196 return my_primary_ends;
208 return my_secondary_nonzero_starts;
213 void fragment_threads() {
218 my_primary_starts.resize(my_nthreads);
219 my_primary_ends.resize(my_nthreads);
223 for (
int t = 0;
t < my_nthreads; ++
t) {
234 my_secondary_nonzero_starts.resize(my_nthreads + 1, std::vector<PointerType>(my_primary_dim));
246 for (
int t = 0;
t < my_nthreads; ++
t) {
255 for (Eigen::Index
c = 0;
c < my_primary_dim; ++
c) {
264 my_secondary_nonzero_starts[
thread + 1][
c] =
s;
274 if (my_nthreads == 1) {
275 for (Eigen::Index
c = 0;
c < my_primary_dim; ++
c) {
277 auto end = my_ptrs[
c + 1];
280 output.coeffRef(my_indices[
s]) += my_values[
s] *
val;
287 const auto&
starts = my_secondary_nonzero_starts[
t];
288 const auto&
ends = my_secondary_nonzero_starts[
t + 1];
289 for (Eigen::Index
c = 0;
c < my_primary_dim; ++
c) {
294 output.coeffRef(my_indices[
s]) += my_values[
s] *
val;
303 if (my_nthreads == 1) {
304 for (Eigen::Index
c = 0;
c < my_primary_dim; ++
c) {
312 auto curend = my_primary_ends[
t];
321 template<
typename Scalar_>
326 dot += my_values[
s] *
rhs.coeff(my_indices[
s]);
340 Workspace workspace()
const {
344 struct AdjointWorkspace {
348 AdjointWorkspace adjoint_workspace()
const {
349 return AdjointWorkspace();
353 template<
class Right_>
356 if (my_column_major) {
363 template<
class Right_>
366 if (my_column_major) {
374 template<
class EigenMatrix_>
380 if (my_column_major) {
381 for (Eigen::Index
c = 0;
c <
nc; ++
c) {
384 output.coeffRef(my_indices[
s],
c) = my_values[
s];
388 for (Eigen::Index
r = 0;
r <
nr; ++
r) {
391 output.coeffRef(
r, my_indices[
s]) = my_values[
s];
429#ifdef IRLBA_CUSTOM_PARALLEL
430#ifdef IRLBA_CUSTOM_PARALLEL_USES_OPENMP
433 Eigen::setNbThreads(1);
436#ifdef SUBPAR_USES_OPENMP_SIMPLE
439 Eigen::setNbThreads(1);
Restrict the number of available threads for Eigen.
Definition parallel.hpp:418
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:195
Eigen::Index rows() const
Definition parallel.hpp:116
const std::vector< size_t > & get_primary_starts() const
Definition parallel.hpp:185
const PointerArray_ & get_pointers() const
Definition parallel.hpp:154
const std::vector< std::vector< PointerType > > & get_secondary_nonzero_starts() const
Definition parallel.hpp:207
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