/// Solve multiple systems w/ each column of the Matrix a single RHS
  MatrixType *p_solve(const MatrixType& B) const
  {
    VectorType b(B.communicator(), B.localRows());
    VectorType X(B.communicator(), B.localRows());
    MatrixType *result(new MatrixType(B.communicator(), B.localRows(), B.localCols(), Dense));

    int ilo, ihi;
    X.localIndexRange(ilo, ihi);
    int nloc(X.localSize());
    std::vector<IdxType> iidx;
    iidx.reserve(nloc);
    for (IdxType i = ilo; i < ihi; ++i) { iidx.push_back(i); }
    std::vector<IdxType> jidx(nloc);
    std::vector<TheType> locX(nloc);

    for (int j = 0; j < B.cols(); ++j) {
      column(B, j, b);
      X.zero();
      X.ready();
      if (j == 0) {
        this->solve(b, X);
      } else {
        this->resolve(b, X);
      }
      std::fill(jidx.begin(), jidx.end(), j);
      X.getElements(nloc, &iidx[0], &locX[0]);
      result->setElements(nloc, &iidx[0], &jidx[0], &locX[0]);
    }
  
    result->ready();
    return result;
  }
Ejemplo n.º 2
0
void DenseSubmatrix(Sparse<Scalar>& matrix, std::vector<int>& rows,
                    std::vector<int>& cols, Dense<Scalar>& submatrix) {
#ifndef RELEASE
    CallStackEntry entry("DenseSubmatrix");
#endif
    // TODO: avoid this copy
    Vector<int> iidx(rows.size());
    for (size_t i = 0; i < rows.size(); ++i) {
	iidx.Set(i, rows[i]);
    }
    Vector<int> jidx(cols.size());
    for (size_t j = 0; j < cols.size(); ++j) {
	jidx.Set(j, cols[j]);
    }
    submatrix.Resize(iidx.Size(), jidx.Size());
    matrix.Find(iidx, jidx, submatrix);
}