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();
182 void getCRSView(ArrayRCP<const offset_t> &offsets, ArrayRCP<const gno_t> &colIds)
const 185 ArrayRCP< const lno_t > localColumnIds;
186 ArrayRCP<const scalar_t> values;
187 matrix_->getAllValues(offsets,localColumnIds,values);
192 ArrayRCP<const gno_t> &colIds,
193 ArrayRCP<const scalar_t> &values)
const 195 ArrayRCP< const lno_t > localColumnIds;
196 matrix_->getAllValues(offsets,localColumnIds,values);
206 if(idx<0 || idx >= nWeightsPerRow_)
208 std::ostringstream emsg;
209 emsg << __FILE__ <<
":" << __LINE__
210 <<
" Invalid row weight index " << idx << std::endl;
211 throw std::runtime_error(emsg.str());
215 rowWeights_[idx].getStridedList(length,
weights, stride);
220 template <
typename Adapter>
224 template <
typename Adapter>
230 RCP<const User> inmatrix_;
231 RCP<const xmatrix_t> matrix_;
232 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > rowMap_;
233 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > colMap_;
235 ArrayRCP<gno_t> columnIds_;
238 ArrayRCP<StridedData<lno_t, scalar_t> > rowWeights_;
239 ArrayRCP<bool> numNzWeight_;
241 bool mayHaveDiagonalEntries;
248 template <
typename User,
typename UserCoord>
250 const RCP<const User> &inmatrix,
int nWeightsPerRow):
251 inmatrix_(inmatrix), matrix_(), rowMap_(), colMap_(),
253 nWeightsPerRow_(nWeightsPerRow), rowWeights_(), numNzWeight_(),
254 mayHaveDiagonalEntries(true)
258 matrix_ = rcp_const_cast<
const xmatrix_t>(
263 rowMap_ = matrix_->getRowMap();
264 colMap_ = matrix_->getColMap();
266 size_t nrows = matrix_->getNodeNumRows();
267 size_t nnz = matrix_->getNodeNumEntries();
270 ArrayRCP< const offset_t > offset;
271 ArrayRCP< const lno_t > localColumnIds;
272 ArrayRCP< const scalar_t > values;
273 matrix_->getAllValues(offset,localColumnIds,values);
274 columnIds_.resize(nnz, 0);
276 for(
offset_t i = 0; i < offset[nrows]; i++) {
277 columnIds_[i] = colMap_->getGlobalElement(localColumnIds[i]);
280 if (nWeightsPerRow_ > 0){
281 rowWeights_ = arcp(
new input_t [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
282 numNzWeight_ = arcp(
new bool [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
283 for (
int i=0; i < nWeightsPerRow_; i++)
284 numNzWeight_[i] =
false;
289 template <
typename User,
typename UserCoord>
291 const scalar_t *weightVal,
int stride,
int idx)
293 if (this->getPrimaryEntityType() ==
MATRIX_ROW)
294 setRowWeights(weightVal, stride, idx);
297 std::ostringstream emsg;
298 emsg << __FILE__ <<
"," << __LINE__
299 <<
" error: setWeights not yet supported for" 300 <<
" columns or nonzeros." 302 throw std::runtime_error(emsg.str());
307 template <
typename User,
typename UserCoord>
309 const scalar_t *weightVal,
int stride,
int idx)
312 if(idx<0 || idx >= nWeightsPerRow_)
314 std::ostringstream emsg;
315 emsg << __FILE__ <<
":" << __LINE__
316 <<
" Invalid row weight index " << idx << std::endl;
317 throw std::runtime_error(emsg.str());
320 size_t nvtx = getLocalNumRows();
321 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
322 rowWeights_[idx] = input_t(weightV, stride);
326 template <
typename User,
typename UserCoord>
330 if (this->getPrimaryEntityType() ==
MATRIX_ROW)
331 setRowWeightIsNumberOfNonZeros(idx);
334 std::ostringstream emsg;
335 emsg << __FILE__ <<
"," << __LINE__
336 <<
" error: setWeightIsNumberOfNonZeros not yet supported for" 337 <<
" columns" << std::endl;
338 throw std::runtime_error(emsg.str());
343 template <
typename User,
typename UserCoord>
347 if(idx<0 || idx >= nWeightsPerRow_)
349 std::ostringstream emsg;
350 emsg << __FILE__ <<
":" << __LINE__
351 <<
" Invalid row weight index " << idx << std::endl;
352 throw std::runtime_error(emsg.str());
356 numNzWeight_[idx] =
true;
360 template <
typename User,
typename UserCoord>
361 template <
typename Adapter>
363 const User &in, User *&out,
368 ArrayRCP<gno_t> importList;
372 (solution,
this, importList);
378 importList.getRawPtr());
379 out =
const_cast<User *
>(outPtr.get());
384 template <
typename User,
typename UserCoord>
385 template <
typename Adapter>
387 const User &in, RCP<User> &out,
392 ArrayRCP<gno_t> importList;
396 (solution,
this, importList);
402 importList.getRawPtr());
InputTraits< User >::scalar_t scalar_t
Created by mbenlioglu on Aug 31, 2020.
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.
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.
void getCRSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &colIds, ArrayRCP< const scalar_t > &values) const
map_t::global_ordinal_type gno_t
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...
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.
InputTraits< User >::node_t node_t
map_t::local_ordinal_type lno_t
InputTraits< User >::part_t part_t
void getRowIDsView(const gno_t *&rowIds) const
void getCRSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &colIds) 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.
void setRowWeightIsNumberOfNonZeros(int idx)
Specify an index for which the row weight should be the global number of nonzeros in the row...
InputTraits< User >::offset_t offset_t
This file defines the StridedData class.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
~XpetraCrsMatrixAdapter()
Destructor.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const