13#ifndef MATRIXPRODUCT_HH
14#define MATRIXPRODUCT_HH
36 template <
class EntryA,
class EntryB,
class IndexA,
class IndexB>
40 constexpr bool scalarA = EntryA::rows*EntryA::cols==1;
41 constexpr bool scalarB = EntryB::rows*EntryB::cols==1;
42 using Entry = std::conditional_t<scalarA,
44 std::conditional_t<scalarB,
47 static_assert(scalarA || scalarB || (int)EntryA::cols==(
int)EntryB::rows,
48 "Entry size has to match");
59 std::mutex creatorMutex;
63 std::vector<IndexA> cidx, tmp, tmp2;
65 for (IndexA i=k*A.
N()/n; i<(k+1)*A.
N()/n; ++i)
70 for (auto cai=rowA.begin(); cai!=rowA.end(); ++cai)
73 auto rowB = B[cai.index()];
74 for (auto cbi=rowB.begin(); cbi!=rowB.end(); ++cbi)
75 tmp.push_back(cbi.index());
78 std::set_union(begin(tmp),end(tmp),
79 begin(cidx),end(cidx),
80 std::back_inserter(tmp2));
84 std::lock_guard<std::mutex> creatorLock(creatorMutex);
97 for (auto cai=rowA.begin(); cai!=rowA.end(); ++cai)
99 auto rowB = B[cai.index()];
100 for (auto cbi=rowB.begin(); cbi!=rowB.end(); ++cbi)
101 rowC[cbi.index()] += normalForm(*cai) * normalForm(*cbi);
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
Index M() const
The number of columns.
Index N() const
The number of rows.
A NUMA-aware creator for matrix sparsity patterns.
void addElements(IterRow const fromRow, IterRow const toRow, IterCol const fromCol, IterCol const toCol, bool colIsSorted=false)
Enters entries into the sparsity pattern.
auto operator*(NumaBCRSMatrix< EntryA, IndexA > const &A, NumaBCRSMatrix< EntryB, IndexB > const &B)
Computes the matrix-matrix product .
void parallelFor(Func const &f, int maxTasks=std::numeric_limits< int >::max())
A parallel for loop that executes the given functor in parallel on different CPUs.