50 #ifndef _ZOLTAN2_XPETRACRSMATRIXADAPTER_HPP_ 51 #define _ZOLTAN2_XPETRACRSMATRIXADAPTER_HPP_ 58 #include <Xpetra_CrsMatrix.hpp> 85 template <
typename User,
typename UserCoord=User>
89 #ifndef DOXYGEN_SHOULD_SKIP_THIS 95 typedef Xpetra::CrsMatrix<scalar_t, lno_t, gno_t, node_t>
xmatrix_t;
98 typedef UserCoord userCoord_t;
111 int numWeightsPerRow=0);
125 void setWeights(
const scalar_t *weightVal,
int stride,
int idx = 0);
142 void setRowWeights(
const scalar_t *weightVal,
int stride,
int idx = 0);
163 return matrix_->getNodeNumRows();
167 return matrix_->getNodeNumCols();
171 return matrix_->getNodeNumEntries();
178 ArrayView<const gno_t> rowView = rowMap_->getNodeElementList();
179 rowIds = rowView.getRawPtr();
182 void getCRSView(
const lno_t *&offsets,
const gno_t *&colIds)
const 184 offsets = offset_.getRawPtr();
185 colIds = columnIds_.getRawPtr();
189 const scalar_t *&values)
const 191 offsets = offset_.getRawPtr();
192 colIds = columnIds_.getRawPtr();
193 values = values_.getRawPtr();
202 env_->localInputAssertion(__FILE__, __LINE__,
203 "invalid weight index",
206 rowWeights_[idx].getStridedList(length, weights, stride);
211 template <
typename Adapter>
215 template <
typename Adapter>
221 RCP<Environment> env_;
223 RCP<const User> inmatrix_;
224 RCP<const xmatrix_t> matrix_;
225 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > rowMap_;
226 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > colMap_;
228 ArrayRCP<lno_t> offset_;
229 ArrayRCP<gno_t> columnIds_;
230 ArrayRCP<scalar_t> values_;
232 int numWeightsPerRow_;
233 ArrayRCP<StridedData<lno_t, scalar_t> > rowWeights_;
234 ArrayRCP<bool> numNzWeight_;
236 bool mayHaveDiagonalEntries;
243 template <
typename User,
typename UserCoord>
245 const RCP<const User> &inmatrix,
int numWeightsPerRow):
247 inmatrix_(inmatrix), matrix_(), rowMap_(), colMap_(), base_(),
248 offset_(), columnIds_(),
249 numWeightsPerRow_(numWeightsPerRow), rowWeights_(), numNzWeight_(),
250 mayHaveDiagonalEntries(true)
253 matrix_ = rcp_const_cast<
const xmatrix_t>(
255 rowMap_ = matrix_->getRowMap();
256 colMap_ = matrix_->getColMap();
257 base_ = rowMap_->getIndexBase();
259 size_t nrows = matrix_->getNodeNumRows();
260 size_t nnz = matrix_->getNodeNumEntries();
262 offset_.resize(nrows+1, 0);
263 columnIds_.resize(nnz);
265 ArrayView<const lno_t> indices;
266 ArrayView<const scalar_t> nzs;
270 for (
size_t i=0; i < nrows; i++){
271 lno_t row = i + base_;
272 nnz = matrix_->getNumEntriesInLocalRow(row);
273 matrix_->getLocalRowView(row, indices, nzs);
274 for (
size_t j=0; j < nnz; j++){
275 values_[next] = nzs[j];
278 columnIds_[next++] = colMap_->getGlobalElement(indices[j]);
280 offset_[i+1] = offset_[i] + nnz;
283 if (numWeightsPerRow_ > 0){
284 rowWeights_ = arcp(
new input_t [numWeightsPerRow_], 0, numWeightsPerRow_,
true);
285 numNzWeight_ = arcp(
new bool [numWeightsPerRow_], 0, numWeightsPerRow_,
true);
286 for (
int i=0; i < numWeightsPerRow_; i++)
287 numNzWeight_[i] =
false;
292 template <
typename User,
typename UserCoord>
294 const scalar_t *weightVal,
int stride,
int idx)
300 std::ostringstream emsg;
301 emsg << __FILE__ <<
"," << __LINE__
302 <<
" error: setWeights not yet supported for" 303 <<
" columns or nonzeros." 305 throw std::runtime_error(emsg.str());
310 template <
typename User,
typename UserCoord>
312 const scalar_t *weightVal,
int stride,
int idx)
315 env_->localInputAssertion(__FILE__, __LINE__,
316 "invalid row weight index",
319 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
320 rowWeights_[idx] = input_t(weightV, stride);
324 template <
typename User,
typename UserCoord>
332 std::ostringstream emsg;
333 emsg << __FILE__ <<
"," << __LINE__
334 <<
" error: setWeightIsNumberOfNonZeros not yet supported for" 335 <<
" columns" << std::endl;
336 throw std::runtime_error(emsg.str());
341 template <
typename User,
typename UserCoord>
345 env_->localInputAssertion(__FILE__, __LINE__,
346 "invalid row weight index",
349 numNzWeight_[idx] =
true;
353 template <
typename User,
typename UserCoord>
354 template <
typename Adapter>
356 const User &in, User *&out,
361 ArrayRCP<gno_t> importList;
365 (solution,
this, importList);
371 importList.getRawPtr());
372 out =
const_cast<User *
>(outPtr.get());
377 template <
typename User,
typename UserCoord>
378 template <
typename Adapter>
380 const User &in, RCP<User> &out,
385 ArrayRCP<gno_t> importList;
389 (solution,
this, importList);
395 importList.getRawPtr());
InputTraits< User >::scalar_t scalar_t
Helper functions for Partitioning Problems.
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
void setRowWeights(const scalar_t *weightVal, int stride, int idx=0)
Specify a weight for each row.
MatrixAdapter defines the adapter interface for matrices.
InputTraits< User >::gno_t gno_t
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
void getRowWeightsView(const scalar_t *&weights, int &stride, int idx=0) const
enum MatrixEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc. Valid values are MATRIX_ROW, MATRIX_COLUMN, MATRIX_NONZERO.
void getCRSView(const lno_t *&offsets, const gno_t *&colIds) const
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...
int getNumWeightsPerRow() const
Returns the number of weights per row (0 or greater). Row weights may be used when partitioning matri...
size_t getLocalNumColumns() const
Returns the number of columns on this process.
Traits of Xpetra classes, including migration method.
XpetraCrsMatrixAdapter(const RCP< const User > &inmatrix, int numWeightsPerRow=0)
Constructor.
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...
A PartitioningSolution is a solution to a partitioning problem.
void setWeightIsDegree(int idx)
Specify an index for which the weight should be the degree of the entity.
size_t getLocalNumRows() const
Returns the number of rows on this process.
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 getLocalNumEntries() const
Returns the number of nonzeros on this process.
void getCRSView(const lno_t *&offsets, const gno_t *&colIds, const scalar_t *&values) const
Defines the MatrixAdapter interface.
void setWeights(const scalar_t *weightVal, int stride, int idx=0)
Specify a weight for each entity of the primaryEntityType.
bool useNumNonzerosAsRowWeight(int idx) const
Indicate whether row weight with index idx should be the global number of nonzeros in the row...
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
void setRowWeightIsNumberOfNonZeros(int idx)
Specify an index for which the row weight 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...
void getRowIDsView(const gno_t *&rowIds) const
This file defines the StridedData class.
~XpetraCrsMatrixAdapter()
Destructor.