50 #ifndef _ZOLTAN2_XPETRACRSMATRIXINPUT_HPP_ 51 #define _ZOLTAN2_XPETRACRSMATRIXINPUT_HPP_ 58 #include <Xpetra_CrsMatrix.hpp> 85 template <
typename User>
89 #ifndef DOXYGEN_SHOULD_SKIP_THIS 95 typedef Xpetra::CrsMatrix<scalar_t, lno_t, gno_t, node_t>
xmatrix_t;
147 void setRowWeights(
int dim,
const scalar_t *weightVal,
int stride);
184 return matrix_->getNodeNumRows();
188 return matrix_->getGlobalNumRows();
192 return matrix_->getNodeNumCols();
196 return matrix_->getGlobalNumCols();
200 const lno_t *&offsets,
const gid_t *& colIds)
const 204 ArrayView<const gid_t> rowView = rowMap_->getNodeElementList();
205 rowIds = rowView.getRawPtr();
206 offsets = offset_.getRawPtr();
207 colIds = columnIds_.getRawPtr();
217 const scalar_t *&weights,
int &stride)
const 219 env_->localInputAssertion(__FILE__, __LINE__,
220 "invalid weight dimension",
224 rowWeights_[dim].getStridedList(length, weights, stride);
233 const scalar_t *&coords,
int &stride)
const 235 env_->localInputAssertion(__FILE__, __LINE__,
236 "invalid coordinate dimension",
240 rowCoords_[dim].getStridedList(length, coords, stride);
248 template <
typename Adapter>
254 RCP<Environment> env_;
256 RCP<const User> inmatrix_;
257 RCP<const xmatrix_t> matrix_;
258 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > rowMap_;
259 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > colMap_;
261 ArrayRCP<lno_t> offset_;
262 ArrayRCP<gno_t> columnIds_;
265 ArrayRCP<StridedData<lno_t, scalar_t> > rowCoords_;
268 ArrayRCP<StridedData<lno_t, scalar_t> > rowWeights_;
269 ArrayRCP<bool> numNzWeight_;
271 bool mayHaveDiagonalEntries;
278 template <
typename User>
280 const RCP<const User> &inmatrix,
int coordDim,
int weightDim):
282 inmatrix_(inmatrix), matrix_(), rowMap_(), colMap_(), base_(),
283 offset_(), columnIds_(),
284 coordinateDim_(coordDim), rowCoords_(),
285 weightDim_(weightDim), rowWeights_(), numNzWeight_(),
286 mayHaveDiagonalEntries(true)
290 rowMap_ = matrix_->getRowMap();
291 colMap_ = matrix_->getColMap();
292 base_ = rowMap_->getIndexBase();
294 size_t nrows = matrix_->getNodeNumRows();
295 size_t nnz = matrix_->getNodeNumEntries();
297 offset_.resize(nrows+1, 0);
298 columnIds_.resize(nnz);
299 ArrayView<const lno_t> indices;
300 ArrayView<const scalar_t> nzs;
302 for (
size_t i=0; i < nrows; i++){
303 lno_t row = i + base_;
304 nnz = matrix_->getNumEntriesInLocalRow(row);
305 matrix_->getLocalRowView(row, indices, nzs);
306 for (
size_t j=0; j < nnz; j++){
309 columnIds_[next++] = colMap_->getGlobalElement(indices[j]);
311 offset_[i+1] = offset_[i] + nnz;
314 if (coordinateDim_ > 0)
315 rowCoords_ = arcp(
new input_t [coordinateDim_], 0, coordinateDim_,
true);
318 rowWeights_ = arcp(
new input_t [weightDim_], 0, weightDim_,
true);
319 numNzWeight_ = arcp(
new bool [weightDim_], 0, weightDim_,
true);
320 for (
int i=0; i < weightDim_; i++)
321 numNzWeight_[i] =
false;
326 template <
typename User>
328 const scalar_t *coordVal,
int stride)
332 env_->localInputAssertion(__FILE__, __LINE__,
333 "invalid row coordinate dimension",
338 ArrayRCP<const scalar_t> coordV(coordVal, 0, nvtx,
false);
339 rowCoords_[dim] =
input_t(coordV, stride);
342 template <
typename User>
344 const scalar_t *weightVal,
int stride)
348 env_->localInputAssertion(__FILE__, __LINE__,
349 "invalid row weight dimension",
354 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx,
false);
355 rowWeights_[dim] =
input_t(weightV, stride);
358 template <
typename User>
361 env_->localInputAssertion(__FILE__, __LINE__,
362 "invalid row weight dimension",
365 numNzWeight_[dim] =
true;
368 template <
typename User>
369 template <
typename Adapter>
371 const User &in, User *&out,
377 const gid_t *gids = solution.
getIdList();
379 ArrayRCP<gid_t> gidList = arcp(const_cast<gid_t *>(gids), 0, len,
false);
380 ArrayRCP<partId_t> partList = arcp(const_cast<partId_t *>(parts), 0, len,
382 ArrayRCP<lno_t> dummyIn;
383 ArrayRCP<gid_t> importList;
384 ArrayRCP<lno_t> dummyOut;
386 const RCP<const Comm<int> > comm = matrix_->getRowMap()->getComm();
390 0, dummyIn, importList, dummyOut);
394 gno_t lsum = numNewRows;
396 reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_SUM, 1, &lsum, &gsum);
398 RCP<const User> inPtr = rcp(&in,
false);
401 inPtr, lsum, importList.getRawPtr());
403 out =
const_cast<User *
>(outPtr.get());
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Zoltan2::StridedData< lno_t, scalar_t > input_t
zoltan2_partId_t partId_t
Traits of Xpetra classes, including migration method.
Defines the PartitioningSolution class.
Zoltan2::BasicUserTypes< scalar_t, gno_t, lno_t, gno_t > user_t
size_t convertSolutionToImportList(int numExtra, ArrayRCP< Extra > &xtraInfo, ArrayRCP< typename Adapter::gid_t > &imports, ArrayRCP< Extra > &newXtraInfo) const
Create an import list from the export list.
const zoltan2_partId_t * getPartList() const
Returns the part list corresponding to the global ID list.
A PartitioningSolution is a solution to a partitioning problem.
The StridedData class manages lists of weights or coordinates.
static RCP< const User > doMigration(const RCP< const User > &from, lno_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...
static RCP< const User > convertToXpetra(const RCP< const User > &a)
Convert the object to its Xpetra wrapped version.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
const gid_t * getIdList() const
Returns the user's global ID list.
Kokkos::DefaultNode::DefaultNodeType node_t
This file defines the StridedData class.
size_t getLocalNumberOfIds() const
Returns the local number of Ids.