50 #ifndef _ZOLTAN2_XPETRAROWMATRIXADAPTER_HPP_ 51 #define _ZOLTAN2_XPETRAROWMATRIXADAPTER_HPP_ 58 #include <Xpetra_RowMatrix.hpp> 80 template <
typename User,
typename UserCoord=User>
84 #ifndef DOXYGEN_SHOULD_SKIP_THIS 90 typedef Xpetra::RowMatrix<scalar_t, lno_t, gno_t, node_t>
xmatrix_t;
93 typedef UserCoord userCoord_t;
106 int numWeightsPerRow=0);
120 void setWeights(
const scalar_t *weightVal,
int stride,
int idx = 0);
137 void setRowWeights(
const scalar_t *weightVal,
int stride,
int idx = 0);
158 return matrix_->getNodeNumRows();
162 return matrix_->getNodeNumCols();
166 return matrix_->getNodeNumEntries();
173 ArrayView<const gno_t> rowView = rowMap_->getNodeElementList();
174 rowIds = rowView.getRawPtr();
177 void getCRSView(
const lno_t *&offsets,
const gno_t *&colIds)
const 179 offsets = offset_.getRawPtr();
180 colIds = columnIds_.getRawPtr();
184 const scalar_t *&values)
const 186 offsets = offset_.getRawPtr();
187 colIds = columnIds_.getRawPtr();
188 values = values_.getRawPtr();
197 env_->localInputAssertion(__FILE__, __LINE__,
198 "invalid weight index",
201 rowWeights_[idx].getStridedList(length, weights, stride);
206 template <
typename Adapter>
210 template <
typename Adapter>
216 RCP<Environment> env_;
218 RCP<const User> inmatrix_;
219 RCP<const xmatrix_t> matrix_;
220 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > rowMap_;
221 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > colMap_;
223 ArrayRCP<lno_t> offset_;
224 ArrayRCP<gno_t> columnIds_;
225 ArrayRCP<scalar_t> values_;
228 ArrayRCP<StridedData<lno_t, scalar_t> > rowWeights_;
229 ArrayRCP<bool> numNzWeight_;
231 bool mayHaveDiagonalEntries;
238 template <
typename User,
typename UserCoord>
240 const RCP<const User> &inmatrix,
int nWeightsPerRow):
242 inmatrix_(inmatrix), matrix_(), rowMap_(), colMap_(), base_(),
243 offset_(), columnIds_(),
244 nWeightsPerRow_(nWeightsPerRow), rowWeights_(), numNzWeight_(),
245 mayHaveDiagonalEntries(true)
248 matrix_ = rcp_const_cast<
const xmatrix_t>(
250 rowMap_ = matrix_->getRowMap();
251 colMap_ = matrix_->getColMap();
252 base_ = rowMap_->getIndexBase();
254 size_t nrows = matrix_->getNodeNumRows();
255 size_t nnz = matrix_->getNodeNumEntries();
256 size_t maxnumentries =
257 matrix_->getNodeMaxNumRowEntries();
259 offset_.resize(nrows+1, 0);
260 columnIds_.resize(nnz);
262 ArrayRCP<lno_t> indices(maxnumentries);
263 ArrayRCP<scalar_t> nzs(maxnumentries);
265 for (
size_t i=0; i < nrows; i++){
266 lno_t row = i + base_;
267 matrix_->getLocalRowCopy(row, indices(), nzs(), nnz);
268 for (
size_t j=0; j < nnz; j++){
269 values_[next] = nzs[j];
272 columnIds_[next++] = colMap_->getGlobalElement(indices[j]);
274 offset_[i+1] = offset_[i] + nnz;
277 if (nWeightsPerRow_ > 0){
278 rowWeights_ = arcp(
new input_t [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
279 numNzWeight_ = arcp(
new bool [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
280 for (
int i=0; i < nWeightsPerRow_; i++)
281 numNzWeight_[i] =
false;
286 template <
typename User,
typename UserCoord>
288 const scalar_t *weightVal,
int stride,
int idx)
294 std::ostringstream emsg;
295 emsg << __FILE__ <<
"," << __LINE__
296 <<
" error: setWeights not yet supported for" 297 <<
" columns or nonzeros." 299 throw std::runtime_error(emsg.str());
304 template <
typename User,
typename UserCoord>
306 const scalar_t *weightVal,
int stride,
int idx)
309 env_->localInputAssertion(__FILE__, __LINE__,
310 "invalid row weight index",
313 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
314 rowWeights_[idx] = input_t(weightV, stride);
318 template <
typename User,
typename UserCoord>
326 std::ostringstream emsg;
327 emsg << __FILE__ <<
"," << __LINE__
328 <<
" error: setWeightIsNumberOfNonZeros not yet supported for" 329 <<
" columns" << std::endl;
330 throw std::runtime_error(emsg.str());
335 template <
typename User,
typename UserCoord>
339 env_->localInputAssertion(__FILE__, __LINE__,
340 "invalid row weight index",
343 numNzWeight_[idx] =
true;
347 template <
typename User,
typename UserCoord>
348 template <
typename Adapter>
350 const User &in, User *&out,
355 ArrayRCP<gno_t> importList;
359 (solution,
this, importList);
365 importList.getRawPtr());
371 template <
typename User,
typename UserCoord>
372 template <
typename Adapter>
374 const User &in, RCP<User> &out,
379 ArrayRCP<gno_t> importList;
383 (solution,
this, importList);
389 importList.getRawPtr());
InputTraits< User >::scalar_t scalar_t
size_t getLocalNumEntries() const
Returns the number of nonzeros on this process.
Helper functions for Partitioning Problems.
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
MatrixAdapter defines the adapter interface for matrices.
InputTraits< User >::gno_t gno_t
XpetraRowMatrixAdapter(const RCP< const User > &inmatrix, int numWeightsPerRow=0)
Constructor.
void setWeights(const scalar_t *weightVal, int stride, int idx=0)
Specify a weight for each entity of the primaryEntityType.
enum MatrixEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc. Valid values are MATRIX_ROW, MATRIX_COLUMN, MATRIX_NONZERO.
static RCP< User > doMigration(const User &from, size_t numLocalRows, const gno_t *myNewRows)
Migrate the object Given a user object and a new row distribution, create and return a new user objec...
Traits of Xpetra classes, including migration method.
Provides access for Zoltan2 to Xpetra::RowMatrix data.
void setWeightIsDegree(int idx)
Specify an index for which the weight should be the degree of the entity.
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.
size_t getImportList(const PartitioningSolution< SolutionAdapter > &solution, const DataAdapter *const data, ArrayRCP< typename DataAdapter::gno_t > &imports)
From a PartitioningSolution, get a list of IDs to be imported. Assumes part numbers in PartitioningSo...
void getRowIDsView(const gno_t *&rowIds) const
Sets pointer to this process' rows' global IDs.
void getCRSView(const lno_t *&offsets, const gno_t *&colIds, const scalar_t *&values) const
A PartitioningSolution is a solution to a partitioning problem.
bool useNumNonzerosAsRowWeight(int idx) const
Indicate whether row weight with index idx should be the global number of nonzeros in the row...
bool CRSViewAvailable() const
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse row (CRS) fo...
The StridedData class manages lists of weights or coordinates.
InputTraits< User >::part_t part_t
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
size_t getLocalNumRows() const
Returns the number of rows on this process.
Defines the MatrixAdapter interface.
void setRowWeightIsNumberOfNonZeros(int idx)
Specify an index for which the row weight should be the global number of nonzeros in the row...
size_t getLocalNumColumns() const
Returns the number of columns on this process.
int getNumWeightsPerRow() const
Returns the number of weights per row (0 or greater). Row weights may be used when partitioning matri...
void getRowWeightsView(const scalar_t *&weights, int &stride, int idx=0) const
void getCRSView(const lno_t *&offsets, const gno_t *&colIds) const
Sets pointers to this process' matrix entries using compressed sparse row (CRS) format. All matrix adapters must implement either getCRSView or getCCSView, but implementation of both is not required.
void setRowWeights(const scalar_t *weightVal, int stride, int idx=0)
Specify a weight for each row.
~XpetraRowMatrixAdapter()
Destructor.
This file defines the StridedData class.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const