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
96 typedef Xpetra::CrsMatrix<scalar_t, lno_t, gno_t, node_t>
xmatrix_t;
98 typedef UserCoord userCoord_t;
111 int nWeightsPerRow=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();
184 offsets = offset_.getRawPtr();
185 colIds = columnIds_.getRawPtr();
191 offsets = offset_.getRawPtr();
192 colIds = columnIds_.getRawPtr();
193 values = values_.getRawPtr();
202 if(idx<0 || idx >= nWeightsPerRow_)
204 std::ostringstream emsg;
205 emsg << __FILE__ <<
":" << __LINE__
206 <<
" Invalid row weight index " << idx << std::endl;
207 throw std::runtime_error(emsg.str());
211 rowWeights_[idx].getStridedList(length, weights, stride);
216 template <
typename Adapter>
220 template <
typename Adapter>
226 RCP<const User> inmatrix_;
227 RCP<const xmatrix_t> matrix_;
228 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > rowMap_;
229 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > colMap_;
231 ArrayRCP< const offset_t > offset_;
232 ArrayRCP< const lno_t > localColumnIds_;
233 ArrayRCP< const scalar_t > values_;
234 ArrayRCP<gno_t> columnIds_;
237 ArrayRCP<StridedData<lno_t, scalar_t> > rowWeights_;
238 ArrayRCP<bool> numNzWeight_;
240 bool mayHaveDiagonalEntries;
247 template <
typename User,
typename UserCoord>
249 const RCP<const User> &inmatrix,
int nWeightsPerRow):
250 inmatrix_(inmatrix), matrix_(), rowMap_(), colMap_(),
251 offset_(), columnIds_(),
252 nWeightsPerRow_(nWeightsPerRow), rowWeights_(), numNzWeight_(),
253 mayHaveDiagonalEntries(true)
257 matrix_ = rcp_const_cast<
const xmatrix_t>(
262 rowMap_ = matrix_->getRowMap();
263 colMap_ = matrix_->getColMap();
265 size_t nrows = matrix_->getNodeNumRows();
266 size_t nnz = matrix_->getNodeNumEntries();
269 matrix_->getAllValues(offset_,localColumnIds_,values_);
270 columnIds_.resize(nnz, 0);
272 for(
offset_t i = 0; i < offset_[nrows]; i++) {
273 columnIds_[i] = colMap_->getGlobalElement(localColumnIds_[i]);
276 if (nWeightsPerRow_ > 0){
277 rowWeights_ = arcp(
new input_t [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
278 numNzWeight_ = arcp(
new bool [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
279 for (
int i=0; i < nWeightsPerRow_; i++)
280 numNzWeight_[i] =
false;
285 template <
typename User,
typename UserCoord>
287 const scalar_t *weightVal,
int stride,
int idx)
289 if (this->getPrimaryEntityType() ==
MATRIX_ROW)
290 setRowWeights(weightVal, stride, idx);
293 std::ostringstream emsg;
294 emsg << __FILE__ <<
"," << __LINE__
295 <<
" error: setWeights not yet supported for"
296 <<
" columns or nonzeros."
298 throw std::runtime_error(emsg.str());
303 template <
typename User,
typename UserCoord>
305 const scalar_t *weightVal,
int stride,
int idx)
308 if(idx<0 || idx >= nWeightsPerRow_)
310 std::ostringstream emsg;
311 emsg << __FILE__ <<
":" << __LINE__
312 <<
" Invalid row weight index " << idx << std::endl;
313 throw std::runtime_error(emsg.str());
316 size_t nvtx = getLocalNumRows();
317 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
318 rowWeights_[idx] = input_t(weightV, stride);
322 template <
typename User,
typename UserCoord>
326 if (this->getPrimaryEntityType() ==
MATRIX_ROW)
327 setRowWeightIsNumberOfNonZeros(idx);
330 std::ostringstream emsg;
331 emsg << __FILE__ <<
"," << __LINE__
332 <<
" error: setWeightIsNumberOfNonZeros not yet supported for"
333 <<
" columns" << std::endl;
334 throw std::runtime_error(emsg.str());
339 template <
typename User,
typename UserCoord>
343 if(idx<0 || idx >= nWeightsPerRow_)
345 std::ostringstream emsg;
346 emsg << __FILE__ <<
":" << __LINE__
347 <<
" Invalid row weight index " << idx << std::endl;
348 throw std::runtime_error(emsg.str());
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.
#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
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...
size_t getLocalNumColumns() const
Returns the number of columns on this process.
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...
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 getLocalNumRows() const
Returns the number of rows on this process.
The StridedData class manages lists of weights or coordinates.
void getCRSView(const offset_t *&offsets, const gno_t *&colIds) const
InputTraits< User >::part_t part_t
void getCRSView(const offset_t *&offsets, const gno_t *&colIds, const scalar_t *&values) const
size_t getLocalNumEntries() const
Returns the number of nonzeros on this process.
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...
InputTraits< User >::offset_t offset_t
void getRowIDsView(const gno_t *&rowIds) const
This file defines the StridedData class.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
~XpetraCrsMatrixAdapter()
Destructor.