22namespace acceleration {
32 template <
typename Derived1,
typename Derived2>
34 Eigen::PlainObjectBase<Derived1> &leftMatrix,
35 Eigen::PlainObjectBase<Derived2> &rightMatrix,
36 Eigen::PlainObjectBase<Derived2> &result,
39 bool dotProductComputation =
true)
42 PRECICE_ASSERT(result.cols() == rightMatrix.cols(), result.cols(), rightMatrix.cols());
43 PRECICE_ASSERT(leftMatrix.cols() == rightMatrix.rows(), leftMatrix.cols(), rightMatrix.rows());
47 result.noalias() = leftMatrix * rightMatrix;
64 _multiplyNN(leftMatrix, rightMatrix, result, offsets, p, q, r);
69 if (dotProductComputation)
89 template <
typename Derived1,
typename Derived2,
typename Derived3>
91 const Eigen::MatrixBase<Derived1> &leftMatrix,
92 const Eigen::MatrixBase<Derived2> &rightMatrix,
93 Eigen::PlainObjectBase<Derived3> & result,
98 PRECICE_ASSERT(leftMatrix.cols() == rightMatrix.rows(), leftMatrix.cols(), rightMatrix.rows());
102 Eigen::MatrixXd localResult(result.rows(), result.cols());
103 localResult.noalias() = leftMatrix * rightMatrix;
107 result = localResult;
117 template <
typename Derived1,
typename Derived2>
119 Eigen::PlainObjectBase<Derived1> &leftMatrix,
120 Eigen::PlainObjectBase<Derived2> &rightMatrix,
121 Eigen::PlainObjectBase<Derived2> &result,
139 PRECICE_ASSERT(leftMatrix.rows() == rightMatrix.cols(), leftMatrix.rows(), rightMatrix.cols());
144 int rows_rcv = (prevProc > 0) ? offsets[prevProc + 1] - offsets[prevProc] : offsets[1];
146 Eigen::MatrixXd leftMatrix_rcv(rows_rcv, q);
152 if (leftMatrix.size() > 0)
156 if (leftMatrix_rcv.size() > 0)
161 Eigen::MatrixXd diagBlock(leftMatrix.rows(), leftMatrix.rows());
162 diagBlock.noalias() = leftMatrix * rightMatrix;
166 PRECICE_ASSERT(result.cols() == diagBlock.cols(), result.cols(), diagBlock.cols());
167 result.block(off, 0, diagBlock.rows(), diagBlock.cols()) = diagBlock;
175 if (requestSend != NULL)
177 if (requestRcv != NULL)
181 Eigen::MatrixXd leftMatrix_copy(leftMatrix_rcv);
185 if (leftMatrix_copy.size() > 0)
194 int rows_rcv_nextCycle = (sourceProc_nextCycle > 0) ? offsets[sourceProc_nextCycle + 1] - offsets[sourceProc_nextCycle] : offsets[1];
195 rows_rcv = (sourceProc > 0) ? offsets[sourceProc + 1] - offsets[sourceProc] : offsets[1];
196 leftMatrix_rcv = Eigen::MatrixXd::Zero(rows_rcv_nextCycle, q);
200 if (leftMatrix_rcv.size() > 0)
204 if (requestSend != NULL)
207 Eigen::MatrixXd block(rows_rcv, rightMatrix.cols());
208 block.noalias() = leftMatrix_copy * rightMatrix;
214 off = offsets[sourceProc];
215 PRECICE_ASSERT(result.cols() == block.cols(), result.cols(), block.cols());
216 result.block(off, 0, block.rows(), block.cols()) = block;
221 template <
typename Derived1,
typename Derived2>
223 Eigen::PlainObjectBase<Derived1> &leftMatrix,
224 Eigen::PlainObjectBase<Derived2> &rightMatrix,
225 Eigen::PlainObjectBase<Derived2> &result,
230 for (
int i = 0; i < leftMatrix.rows(); i++) {
237 while (i >= offsets[rank + 1])
240 Eigen::VectorXd lMRow = leftMatrix.row(i);
242 for (
int j = 0; j < r; j++) {
244 Eigen::VectorXd rMCol = rightMatrix.col(j);
250 local_row = i - offsets[rank];
251 result(local_row, j) = res_ij;
258 template <
typename Derived1,
typename Derived2>
260 Eigen::PlainObjectBase<Derived1> &leftMatrix,
261 Eigen::PlainObjectBase<Derived2> &rightMatrix,
262 Eigen::PlainObjectBase<Derived2> &result,
269 PRECICE_ASSERT(
static_cast<int>(leftMatrix.IsRowMajor) ==
static_cast<int>(rightMatrix.IsRowMajor),
270 static_cast<int>(leftMatrix.IsRowMajor),
static_cast<int>(rightMatrix.IsRowMajor));
274 Eigen::MatrixXd block = Eigen::MatrixXd::Zero(p, r);
275 block.noalias() = leftMatrix * rightMatrix;
282 Eigen::MatrixXd summarizedBlocks = Eigen::MatrixXd::Zero(p, r);
287 if (result.size() > 0)
294 result = summarizedBlocks.block(0, 0, offsets[1], r);
297 int off = offsets[secondaryRank];
298 int send_rows = offsets[secondaryRank + 1] - offsets[secondaryRank];
300 if (summarizedBlocks.block(off, 0, send_rows, r).size() > 0) {
303 Eigen::MatrixXd sendBlock = summarizedBlocks.block(off, 0, send_rows, r);
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
void _multiplyNM_dotProduct(Eigen::PlainObjectBase< Derived1 > &leftMatrix, Eigen::PlainObjectBase< Derived2 > &rightMatrix, Eigen::PlainObjectBase< Derived2 > &result, const std::vector< int > &offsets, int p, int q, int r)
void closeCircularCommunication()
void initialize(const bool needCyclicComm)
Initializes the acceleration.
void multiply(const Eigen::MatrixBase< Derived1 > &leftMatrix, const Eigen::MatrixBase< Derived2 > &rightMatrix, Eigen::PlainObjectBase< Derived3 > &result, int p, int q, int r)
: Method computes the matrix-matrix/matrix-vector product of a (p x q) matrix that is distributed col...
void _multiplyNM_block(Eigen::PlainObjectBase< Derived1 > &leftMatrix, Eigen::PlainObjectBase< Derived2 > &rightMatrix, Eigen::PlainObjectBase< Derived2 > &result, const std::vector< int > &offsets, int p, int q, int r)
Multiplies matrices based on a SAXPY-like block-wise computation with a rectangular result matrix of ...
com::PtrCommunication _cyclicCommLeft
Communication between neighboring ranks, backwards.
void multiply(Eigen::PlainObjectBase< Derived1 > &leftMatrix, Eigen::PlainObjectBase< Derived2 > &rightMatrix, Eigen::PlainObjectBase< Derived2 > &result, const std::vector< int > &offsets, int p, int q, int r, bool dotProductComputation=true)
com::PtrCommunication _cyclicCommRight
Communication between neighboring ranks, forward.
~ParallelMatrixOperations()
void _multiplyNN(Eigen::PlainObjectBase< Derived1 > &leftMatrix, Eigen::PlainObjectBase< Derived2 > &rightMatrix, Eigen::PlainObjectBase< Derived2 > &result, const std::vector< int > &offsets, int p, int q, int r)
void establishCircularCommunication()
This class provides a lightweight logger.
static void allreduceSum(precice::span< const double > sendData, precice::span< double > rcvData)
static int getSize()
Number of ranks. This includes ranks from both participants, e.g. minimal size is 2.
static Rank getRank()
Current rank.
static double dot(const Eigen::VectorXd &vec1, const Eigen::VectorXd &vec2)
static bool isPrimary()
True if this process is running the primary rank.
static auto allSecondaryRanks()
Returns an iterable range over salve ranks [1, _size)
static bool isParallel()
True if this process is running in parallel.
static bool isSecondary()
True if this process is running a secondary rank.
static com::PtrCommunication & getCommunication()
Intra-participant communication.
static void reduceSum(precice::span< const double > sendData, precice::span< double > rcvData)
Main namespace of the precice library.
static std::unique_ptr< precice::Participant > impl