50 #ifndef _ZOLTAN2_XPETRACRSMATRIXADAPTER_HPP_
51 #define _ZOLTAN2_XPETRACRSMATRIXADAPTER_HPP_
58 #include <Xpetra_CrsMatrix.hpp>
88 template <
typename User,
typename UserCoord=User>
92 #ifndef DOXYGEN_SHOULD_SKIP_THIS
99 using xmatrix_t = Xpetra::CrsMatrix<scalar_t, lno_t, gno_t, node_t>;
101 using userCoord_t = UserCoord;
111 int nWeightsPerRow=0);
163 return matrix_->getLocalNumRows();
167 return matrix_->getLocalNumCols();
171 return matrix_->getLocalNumEntries();
178 ArrayView<const gno_t> rowView = rowMap_->getLocalElementList();
179 rowIds = rowView.getRawPtr();
183 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 {
194 ArrayRCP< const lno_t > localColumnIds;
195 matrix_->getAllValues(offsets,localColumnIds,values);
205 if(idx<0 || idx >= nWeightsPerRow_)
207 std::ostringstream emsg;
208 emsg << __FILE__ <<
":" << __LINE__
209 <<
" Invalid row weight index " << idx << std::endl;
210 throw std::runtime_error(emsg.str());
214 rowWeights_[idx].getStridedList(length, weights, stride);
219 template <
typename Adapter>
223 template <
typename Adapter>
229 RCP<const User> inmatrix_;
230 RCP<const xmatrix_t> matrix_;
231 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > rowMap_;
232 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > colMap_;
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_(),
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_->getLocalNumRows();
266 size_t nnz = matrix_->getLocalNumEntries();
269 ArrayRCP< const offset_t > offset;
270 ArrayRCP< const lno_t > localColumnIds;
271 ArrayRCP< const scalar_t > values;
272 matrix_->getAllValues(offset,localColumnIds,values);
273 columnIds_.resize(nnz, 0);
275 for(
offset_t i = 0; i < offset[nrows]; i++){
276 columnIds_[i] = colMap_->getGlobalElement(localColumnIds[i]);
279 if (nWeightsPerRow_ > 0){
280 rowWeights_ = arcp(
new input_t [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
281 numNzWeight_ = arcp(
new bool [nWeightsPerRow_], 0, nWeightsPerRow_,
true);
282 for (
int i=0; i < nWeightsPerRow_; i++)
283 numNzWeight_[i] =
false;
288 template <
typename User,
typename UserCoord>
290 const scalar_t *weightVal,
int stride,
int idx)
292 if (this->getPrimaryEntityType() ==
MATRIX_ROW)
293 setRowWeights(weightVal, stride, idx);
296 std::ostringstream emsg;
297 emsg << __FILE__ <<
"," << __LINE__
298 <<
" error: setWeights not yet supported for"
299 <<
" columns or nonzeros."
301 throw std::runtime_error(emsg.str());
306 template <
typename User,
typename UserCoord>
308 const scalar_t *weightVal,
int stride,
int idx)
311 if(idx<0 || idx >= nWeightsPerRow_)
313 std::ostringstream emsg;
314 emsg << __FILE__ <<
":" << __LINE__
315 <<
" Invalid row weight index " << idx << std::endl;
316 throw std::runtime_error(emsg.str());
319 size_t nvtx = getLocalNumRows();
320 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx*stride,
false);
321 rowWeights_[idx] = input_t(weightV, stride);
325 template <
typename User,
typename UserCoord>
329 if (this->getPrimaryEntityType() ==
MATRIX_ROW)
330 setRowWeightIsNumberOfNonZeros(idx);
333 std::ostringstream emsg;
334 emsg << __FILE__ <<
"," << __LINE__
335 <<
" error: setWeightIsNumberOfNonZeros not yet supported for"
336 <<
" columns" << std::endl;
337 throw std::runtime_error(emsg.str());
342 template <
typename User,
typename UserCoord>
346 if(idx<0 || idx >= nWeightsPerRow_)
348 std::ostringstream emsg;
349 emsg << __FILE__ <<
":" << __LINE__
350 <<
" Invalid row weight index " << idx << std::endl;
351 throw std::runtime_error(emsg.str());
355 numNzWeight_[idx] =
true;
359 template <
typename User,
typename UserCoord>
360 template <
typename Adapter>
362 const User &in, User *&out,
367 ArrayRCP<gno_t> importList;
371 (solution,
this, importList);
377 importList.getRawPtr());
378 out =
const_cast<User *
>(outPtr.get());
383 template <
typename User,
typename UserCoord>
384 template <
typename Adapter>
386 const User &in, RCP<User> &out,
391 ArrayRCP<gno_t> importList;
395 (solution,
this, importList);
401 importList.getRawPtr());
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.
typename InputTraits< User >::scalar_t scalar_t
MatrixAdapter defines the adapter interface for matrices.
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
void getRowWeightsView(const scalar_t *&weights, int &stride, int idx=0) const
Provide a pointer to the row weights, if any.
map_t::global_ordinal_type gno_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.
void getCRSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &colIds) const
Traits of Xpetra classes, including migration method.
typename InputTraits< User >::part_t part_t
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 getCRSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &colIds, ArrayRCP< 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 getLocalNumRows() const
Returns the number of rows on this process.
The StridedData class manages lists of weights or coordinates.
map_t::local_ordinal_type lno_t
size_t getLocalNumEntries() const
Returns the number of nonzeros on this process.
typename InputTraits< User >::offset_t offset_t
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.