50 #ifndef _ZOLTAN2_XPETRACRSMATRIXINPUT_HPP_
51 #define _ZOLTAN2_XPETRACRSMATRIXINPUT_HPP_
58 #include <Xpetra_RowMatrix.hpp>
84 template <
typename User>
88 #ifndef DOXYGEN_SHOULD_SKIP_THIS
94 typedef Xpetra::RowMatrix<scalar_t, lno_t, gno_t, node_t>
xmatrix_t;
183 return matrix_->getNodeNumRows();
187 return matrix_->getGlobalNumRows();
191 return matrix_->getNodeNumCols();
195 return matrix_->getGlobalNumCols();
199 const lno_t *&offsets,
const gid_t *& colIds)
const
203 ArrayView<const gid_t> rowView = rowMap_->getNodeElementList();
204 rowIds = rowView.getRawPtr();
205 offsets = offset_.getRawPtr();
206 colIds = columnIds_.getRawPtr();
216 const scalar_t *&weights,
int &stride)
const
218 env_->localInputAssertion(__FILE__, __LINE__,
219 "invalid weight dimension",
223 rowWeights_[dim].getStridedList(length, weights, stride);
232 const scalar_t *&coords,
int &stride)
const
234 env_->localInputAssertion(__FILE__, __LINE__,
235 "invalid coordinate dimension",
239 rowCoords_[dim].getStridedList(length, coords, stride);
247 template <
typename Adapter>
253 RCP<Environment> env_;
255 RCP<const User> inmatrix_;
256 RCP<const xmatrix_t> matrix_;
257 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > rowMap_;
258 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > colMap_;
260 ArrayRCP<lno_t> offset_;
261 ArrayRCP<gno_t> columnIds_;
264 ArrayRCP<StridedData<lno_t, scalar_t> > rowCoords_;
267 ArrayRCP<StridedData<lno_t, scalar_t> > rowWeights_;
268 ArrayRCP<bool> numNzWeight_;
270 bool mayHaveDiagonalEntries;
277 template <
typename User>
279 const RCP<const User> &inmatrix,
int coordDim,
int weightDim):
281 inmatrix_(inmatrix), matrix_(), rowMap_(), colMap_(), base_(),
282 offset_(), columnIds_(),
283 coordinateDim_(coordDim), rowCoords_(),
284 weightDim_(weightDim), rowWeights_(), numNzWeight_(),
285 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();
296 size_t maxnumentries = matrix_->getNodeMaxNumRowEntries();
298 offset_.resize(nrows+1, 0);
299 columnIds_.resize(nnz);
300 ArrayRCP<lno_t> indices(maxnumentries);
301 ArrayRCP<scalar_t> nzs(maxnumentries);
304 for (
size_t i=0; i < nrows; i++){
305 lno_t row = i + base_;
306 matrix_->getLocalRowCopy(row,indices(),nzs(),nnz);
307 for (
size_t j=0; j < nnz; j++){
310 columnIds_[next++] = colMap_->getGlobalElement(indices[j]);
312 offset_[i+1] = offset_[i] + nnz;
315 if (coordinateDim_ > 0)
316 rowCoords_ = arcp(
new input_t [coordinateDim_], 0, coordinateDim_,
true);
319 rowWeights_ = arcp(
new input_t [weightDim_], 0, weightDim_,
true);
320 numNzWeight_ = arcp(
new bool [weightDim_], 0, weightDim_,
true);
321 for (
int i=0; i < weightDim_; i++)
322 numNzWeight_[i] =
false;
327 template <
typename User>
329 const scalar_t *coordVal,
int stride)
333 env_->localInputAssertion(__FILE__, __LINE__,
334 "invalid row coordinate dimension",
337 size_t nvtx = getLocalNumRows();
339 ArrayRCP<const scalar_t> coordV(coordVal, 0, nvtx,
false);
340 rowCoords_[dim] =
input_t(coordV, stride);
343 template <
typename User>
345 const scalar_t *weightVal,
int stride)
349 env_->localInputAssertion(__FILE__, __LINE__,
350 "invalid row weight dimension",
353 size_t nvtx = getLocalNumRows();
355 ArrayRCP<const scalar_t> weightV(weightVal, 0, nvtx,
false);
356 rowWeights_[dim] =
input_t(weightV, stride);
359 template <
typename User>
362 env_->localInputAssertion(__FILE__, __LINE__,
363 "invalid row weight dimension",
366 numNzWeight_[dim] =
true;
369 template <
typename User>
370 template <
typename Adapter>
372 const User &in, User *&out,
378 const gid_t *gids = solution.
getIdList();
380 ArrayRCP<gid_t> gidList = arcp(const_cast<gid_t *>(gids), 0, len,
false);
381 ArrayRCP<partId_t> partList = arcp(const_cast<partId_t *>(parts), 0, len,
383 ArrayRCP<lno_t> dummyIn;
384 ArrayRCP<gid_t> importList;
385 ArrayRCP<lno_t> dummyOut;
387 const RCP<const Comm<int> > comm = matrix_->getRowMap()->getComm();
391 0, dummyIn, importList, dummyOut);
395 gno_t lsum = numNewRows;
397 reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_SUM, 1, &lsum, &gsum);
399 RCP<const User> inPtr = rcp(&in,
false);
402 inPtr, lsum, importList.getRawPtr());
404 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.