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;
97 typedef UserCoord userCoord_t;
110 int nWeightsPerRow=0);
162 return matrix_->getNodeNumRows();
166 return matrix_->getNodeNumCols();
170 return matrix_->getNodeNumEntries();
177 ArrayView<const gno_t> rowView = rowMap_->getNodeElementList();
178 rowIds = rowView.getRawPtr();
183 offsets = offset_.getRawPtr();
184 colIds = columnIds_.getRawPtr();
190 offsets = offset_.getRawPtr();
191 colIds = columnIds_.getRawPtr();
192 values = values_.getRawPtr();
201 env_->localInputAssertion(__FILE__, __LINE__,
202 "invalid weight index",
205 rowWeights_[idx].getStridedList(length,
weights, stride);
210 template <
typename Adapter>
214 template <
typename Adapter>
220 RCP<Environment> env_;
222 RCP<const User> inmatrix_;
223 RCP<const xmatrix_t> matrix_;
224 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > rowMap_;
225 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > colMap_;
227 ArrayRCP<lno_t> offset_;
228 ArrayRCP<gno_t> columnIds_;
229 ArrayRCP<scalar_t> values_;
232 ArrayRCP<StridedData<lno_t, scalar_t> > rowWeights_;
233 ArrayRCP<bool> numNzWeight_;
235 bool mayHaveDiagonalEntries;
242 template <
typename User,
typename UserCoord>
244 const RCP<const User> &inmatrix,
int nWeightsPerRow):
246 inmatrix_(inmatrix), matrix_(), rowMap_(), colMap_(), base_(),
247 offset_(), columnIds_(),
248 nWeightsPerRow_(nWeightsPerRow), rowWeights_(), numNzWeight_(),
249 mayHaveDiagonalEntries(true)
253 matrix_ = rcp_const_cast<
const xmatrix_t>(
258 rowMap_ = matrix_->getRowMap();
259 colMap_ = matrix_->getColMap();
260 base_ = rowMap_->getIndexBase();
262 size_t nrows = matrix_->getNodeNumRows();
263 size_t nnz = matrix_->getNodeNumEntries();
265 offset_.resize(nrows+1, 0);
266 columnIds_.resize(nnz);
268 ArrayView<const lno_t> indices;
269 ArrayView<const scalar_t> nzs;
273 for (
size_t i=0; i < nrows; i++){
274 lno_t row = i + base_;
275 nnz = matrix_->getNumEntriesInLocalRow(row);
276 matrix_->getLocalRowView(row, indices, nzs);
277 for (
size_t j=0; j < nnz; j++){
278 values_[next] = nzs[j];
281 columnIds_[next++] = colMap_->getGlobalElement(indices[j]);
283 offset_[i+1] = offset_[i] + nnz;
286 if (nWeightsPerRow_ > 0){
287 rowWeights_ = arcp(
new input_t [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
288 numNzWeight_ = arcp(
new bool [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
289 for (
int i=0; i < nWeightsPerRow_; i++)
290 numNzWeight_[i] =
false;
295 template <
typename User,
typename UserCoord>
297 const scalar_t *weightVal,
int stride,
int idx)
299 if (this->getPrimaryEntityType() ==
MATRIX_ROW)
300 setRowWeights(weightVal, stride, idx);
303 std::ostringstream emsg;
304 emsg << __FILE__ <<
"," << __LINE__
305 <<
" error: setWeights not yet supported for" 306 <<
" columns or nonzeros." 308 throw std::runtime_error(emsg.str());
313 template <
typename User,
typename UserCoord>
315 const scalar_t *weightVal,
int stride,
int idx)
318 env_->localInputAssertion(__FILE__, __LINE__,
319 "invalid row weight index",
321 size_t nvtx = getLocalNumRows();
322 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
323 rowWeights_[idx] = input_t(weightV, stride);
327 template <
typename User,
typename UserCoord>
331 if (this->getPrimaryEntityType() ==
MATRIX_ROW)
332 setRowWeightIsNumberOfNonZeros(idx);
335 std::ostringstream emsg;
336 emsg << __FILE__ <<
"," << __LINE__
337 <<
" error: setWeightIsNumberOfNonZeros not yet supported for" 338 <<
" columns" << std::endl;
339 throw std::runtime_error(emsg.str());
344 template <
typename User,
typename UserCoord>
348 env_->localInputAssertion(__FILE__, __LINE__,
349 "invalid row weight index",
352 numNzWeight_[idx] =
true;
356 template <
typename User,
typename UserCoord>
357 template <
typename Adapter>
359 const User &in, User *&out,
364 ArrayRCP<gno_t> importList;
368 (solution,
this, importList);
374 importList.getRawPtr());
375 out =
const_cast<User *
>(outPtr.get());
380 template <
typename User,
typename UserCoord>
381 template <
typename Adapter>
383 const User &in, RCP<User> &out,
388 ArrayRCP<gno_t> importList;
392 (solution,
this, importList);
398 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.
void getRowWeightsView(const scalar_t *&weights, int &stride, int idx=0) const
MatrixAdapter defines the adapter interface for matrices.
InputTraits< User >::gno_t gno_t
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
size_t getLocalNumColumns() const
Returns the number of columns on this process.
bool useNumNonzerosAsRowWeight(int idx) const
Indicate whether row weight with index idx should be the global number of nonzeros in the row...
size_t getLocalNumRows() const
Returns the number of rows on this process.
InputTraits< User >::lno_t lno_t
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...
Traits of Xpetra classes, including migration method.
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...
bool CRSViewAvailable() const
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse row (CRS) fo...
void getCRSView(const lno_t *&offsets, const gno_t *&colIds, const scalar_t *&values) const
A PartitioningSolution is a solution to a partitioning problem.
XpetraCrsMatrixAdapter(const RCP< const User > &inmatrix, int nWeightsPerRow=0)
Constructor
void setWeightIsDegree(int idx)
Specify an index for which the weight should be the degree of the entity.
size_t getLocalNumEntries() const
Returns the number of nonzeros on this process.
The StridedData class manages lists of weights or coordinates.
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.
InputTraits< User >::part_t part_t
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
void getRowIDsView(const gno_t *&rowIds) const
Sets pointer to this process' rows' global IDs.
Defines the MatrixAdapter interface.
void setWeights(const scalar_t *weightVal, int stride, int idx=0)
Specify a weight for each entity of the primaryEntityType.
void setRowWeightIsNumberOfNonZeros(int idx)
Specify an index for which the row weight should be the global number of nonzeros in the row...
This file defines the StridedData class.
~XpetraCrsMatrixAdapter()
Destructor.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const