51 #ifndef _ZOLTAN2_COORDINATEMODEL_HPP_ 52 #define _ZOLTAN2_COORDINATEMODEL_HPP_ 70 template <
typename Adapter>
75 #ifndef DOXYGEN_SHOULD_SKIP_THIS 83 throw std::logic_error(
"a specific instantiation should be used");
129 ArrayView<input_t> &xyz,
130 ArrayView<input_t> &wgts)
const {
return 0;}
149 #ifndef DOXYGEN_SHOULD_SKIP_THIS 155 template <
typename User>
157 public Model<CoordinateInput<User> >
162 typedef typename CoordinateInput<User>::scalar_t
scalar_t;
178 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
190 ArrayView<input_t> &xyz,
191 ArrayView<input_t> &wgts)
const 193 xyz = xyz_.view(0, coordinateDim_);
194 wgts = weights_.view(0, userNumWeights_);
197 Ids = ArrayView<const gno_t>();
201 Ids = Teuchos::arrayView<const gno_t>(
202 reinterpret_cast<const gno_t *
>(gids_.getRawPtr()), nCoord);
204 Ids = gnosConst_.view(0, nCoord);
226 ArrayView<input_t> xyz;
227 ArrayView<input_t> weights;
234 gno_t numGlobalCoordinates_;
235 const RCP<const Environment> env_;
236 const RCP<const Comm<int> > comm_;
238 ArrayRCP<const gid_t> gids_;
239 ArrayRCP<input_t> xyz_;
241 ArrayRCP<input_t> weights_;
242 ArrayRCP<gno_t> gnos_;
243 ArrayRCP<const gno_t> gnosConst_;
247 template <
typename User>
250 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
252 gnosAreGids_(
false), numGlobalCoordinates_(), env_(env), comm_(comm),
253 coordinateDim_(), gids_(), xyz_(), userNumWeights_(0), weights_(),
254 gnos_(), gnosConst_()
268 env_->localBugAssertion(__FILE__, __LINE__,
"coordinate dimension",
274 weightArray =
new input_t [userNumWeights_];
276 env_->localMemoryAssertion(__FILE__, __LINE__, userNumWeights_+coordinateDim_,
277 coordArray && (!userNumWeights_ || weightArray));
279 Array<lno_t> arrayLengths(userNumWeights_, 0);
282 for (
int dim=0; dim < coordinateDim_; dim++){
284 const gid_t *gids=NULL;
291 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
292 coordArray[dim] =
input_t(cArray, stride);
295 gids_ = arcp(gids, 0, nLocalIds,
false);
298 for (
int dim=0; dim < userNumWeights_; dim++){
307 ArrayRCP<const scalar_t> wArray(weights, 0, nLocalIds*stride,
false);
308 weightArray[dim] =
input_t(wArray, stride);
309 arrayLengths[dim] = nLocalIds;
314 xyz_ = arcp(coordArray, 0, coordinateDim_);
317 weights_ = arcp(weightArray, 0, userNumWeights_);
324 RCP<const idmap_t> idMap;
327 idMap = rcp(
new idmap_t(env_, comm_, gids_, consecutiveIds));
331 numGlobalCoordinates_ = idMap->getGlobalNumberOfIds();
332 gnosAreGids_ = idMap->gnosAreGids();
336 if (!gnosAreGids_ && nLocalIds>0){
338 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
339 gnos_ = arcp(tmpGno, 0, nLocalIds);
342 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
343 idMap->gidTranslate( gidsNonConst(0,nLocalIds), gnos_(0,nLocalIds),
349 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
351 env_->memory(
"After construction of coordinate model");
358 template <
typename User>
360 public Model<MatrixInput<User> >
364 typedef typename MatrixInput<User>::scalar_t
scalar_t;
380 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
397 ArrayView<input_t> &xyz,
398 ArrayView<input_t> &wgts)
const 400 xyz = xyz_.view(0, coordinateDim_);
401 wgts = weights_.view(0, userNumWeights_);
404 Ids = ArrayView<const gno_t>();
408 Ids = Teuchos::arrayView<const gno_t>(
409 reinterpret_cast<const gno_t *
>(gids_.getRawPtr()), nCoord);
411 Ids = gnosConst_.view(0, nCoord);
433 ArrayView<input_t> xyz;
434 ArrayView<input_t> weights;
441 gno_t numGlobalCoordinates_;
442 const RCP<const Environment> env_;
443 const RCP<const Comm<int> > comm_;
445 ArrayRCP<const gid_t> gids_;
446 ArrayRCP<input_t> xyz_;
448 ArrayRCP<input_t> weights_;
449 ArrayRCP<gno_t> gnos_;
450 ArrayRCP<const gno_t> gnosConst_;
453 template <
typename User>
456 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
458 gnosAreGids_(
false), numGlobalCoordinates_(), env_(env), comm_(comm),
459 coordinateDim_(), gids_(), xyz_(), userNumWeights_(0), weights_(),
460 gnos_(), gnosConst_()
470 env_->localBugAssertion(__FILE__, __LINE__,
"coordinate dimension",
478 env_->localMemoryAssertion(__FILE__, __LINE__, coordinateDim_, coordArray);
481 for (
int dim=0; dim < coordinateDim_; dim++){
489 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
490 coordArray[dim] =
input_t(cArray, stride);
494 xyz_ = arcp(coordArray, 0, coordinateDim_);
498 const gid_t *rowGids;
499 const lno_t *offsets;
500 const gid_t *colGids;
504 gids_ = arcp<const gid_t>(rowGids, 0, nLocalIds,
false);
506 RCP<const idmap_t> idMap;
509 idMap = rcp(
new idmap_t(env_, comm_, gids_, consecutiveIds));
513 numGlobalCoordinates_ = idMap->getGlobalNumberOfIds();
514 gnosAreGids_ = idMap->gnosAreGids();
518 if (!gnosAreGids_ && nLocalIds>0){
520 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
521 gnos_ = arcp(tmpGno, 0, nLocalIds);
524 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
525 idMap->gidTranslate( gidsNonConst(0,nLocalIds), gnos_(0,nLocalIds),
531 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
533 env_->memory(
"After construction of coordinate model");
540 template <
typename User>
542 public Model<VectorInput<User> >
547 typedef typename VectorInput<User>::scalar_t
scalar_t;
555 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
567 ArrayView<input_t> &xyz,
568 ArrayView<input_t> &wgts)
const 570 xyz = xyz_.view(0, coordinateDim_);
571 wgts = weights_.view(0, userNumWeights_);
574 Ids = ArrayView<const gno_t>();
578 Ids = Teuchos::arrayView<const gno_t>(
579 reinterpret_cast<const gno_t *
>(gids_.getRawPtr()), nCoord);
581 Ids = gnosConst_.view(0, nCoord);
596 ArrayView<input_t> a, b;
604 gno_t numGlobalCoordinates_;
605 const RCP<const Environment> env_;
606 const RCP<const Comm<int> > comm_;
608 ArrayRCP<const gid_t> gids_;
609 ArrayRCP<input_t> xyz_;
611 ArrayRCP<input_t> weights_;
612 ArrayRCP<gno_t> gnos_;
613 ArrayRCP<const gno_t> gnosConst_;
616 template <
typename User>
619 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
621 gnosAreGids_(
false), numGlobalCoordinates_(), env_(env), comm_(comm),
622 coordinateDim_(), gids_(), xyz_(), userNumWeights_(0), weights_(),
623 gnos_(), gnosConst_()
636 env_->localBugAssertion(__FILE__, __LINE__,
"coordinate dimension",
642 weightArray =
new input_t [userNumWeights_];
644 env_->localMemoryAssertion(__FILE__, __LINE__, userNumWeights_+coordinateDim_,
645 coordArray && (!userNumWeights_|| weightArray));
647 Array<lno_t> arrayLengths(userNumWeights_, 0);
650 for (
int dim=0; dim < coordinateDim_; dim++){
652 const gid_t *gids=NULL;
655 ia->
getVector(dim, gids, coords, stride);
659 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
660 coordArray[dim] =
input_t(cArray, stride);
663 gids_ = arcp(gids, 0, nLocalIds,
false);
666 for (
int dim=0; dim < userNumWeights_; dim++){
675 ArrayRCP<const scalar_t> wArray(weights, 0, nLocalIds*stride,
false);
676 weightArray[dim] =
input_t(wArray, stride);
677 arrayLengths[dim] = nLocalIds;
682 xyz_ = arcp(coordArray, 0, coordinateDim_);
685 weights_ = arcp(weightArray, 0, userNumWeights_);
692 RCP<const idmap_t> idMap;
695 idMap = rcp(
new idmap_t(env_, comm_, gids_, consecutiveIds));
699 numGlobalCoordinates_ = idMap->getGlobalNumberOfIds();
700 gnosAreGids_ = idMap->gnosAreGids();
704 if (!gnosAreGids_ && nLocalIds>0){
706 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
707 gnos_ = arcp(tmpGno, 0, nLocalIds);
710 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
711 idMap->gidTranslate( gidsNonConst(0,nLocalIds), gnos_(0,nLocalIds),
717 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
719 env_->memory(
"After construction of coordinate model");
728 template <
typename User>
730 public Model<IdentifierInput<User> >
734 typedef typename IdentifierInput<User>::scalar_t
scalar_t;
740 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
744 "a coordinate model can not be build from identifier input");
752 ArrayView<input_t> &xyz,
753 ArrayView<input_t> &wgts)
const {
return 0;}
769 template <
typename User>
771 public Model<GraphInput<User> >
776 typedef typename GraphInput<User>::scalar_t
scalar_t;
784 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
796 ArrayView<input_t> &xyz,
797 ArrayView<input_t> &wgts)
const 799 xyz = xyz_.view(0, coordinateDim_);
800 wgts = weights_.view(0, userNumWeights_);
803 Ids = ArrayView<const gno_t>();
807 Ids = Teuchos::arrayView<const gno_t>(
808 reinterpret_cast<const gno_t *
>(gids_.getRawPtr()), nCoord);
810 Ids = gnosConst_.view(0, nCoord);
825 ArrayView<input_t> a, b;
833 gno_t numGlobalCoordinates_;
834 const RCP<const Environment> env_;
835 const RCP<const Comm<int> > comm_;
837 ArrayRCP<const gid_t> gids_;
838 ArrayRCP<input_t> xyz_;
840 ArrayRCP<input_t> weights_;
841 ArrayRCP<gno_t> gnos_;
842 ArrayRCP<const gno_t> gnosConst_;
845 template <
typename User>
848 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
850 gnosAreGids_(
false), numGlobalCoordinates_(), env_(env), comm_(comm),
851 coordinateDim_(), gids_(), xyz_(), userNumWeights_(0), weights_(),
852 gnos_(), gnosConst_()
856 env->localInputAssertion(__FILE__, __LINE__,
857 "graph input does not have vertex coordinates",
869 weightArray =
new input_t [userNumWeights_];
871 env_->localMemoryAssertion(__FILE__, __LINE__, userNumWeights_+coordinateDim_,
872 coordArray && (!userNumWeights_|| weightArray));
874 Array<lno_t> arrayLengths(userNumWeights_, 0);
879 const gid_t *globalIds=NULL;
880 const lno_t *offsets=NULL;
881 const gid_t *edgeIds=NULL;
885 gids_ = arcp(globalIds, 0, nLocalIds,
false);
887 for (
int dim=0; dim < coordinateDim_; dim++){
895 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
896 coordArray[dim] =
input_t(cArray, stride);
899 for (
int dim=0; dim < userNumWeights_; dim++){
908 ArrayRCP<const scalar_t> wArray(weights, 0, nLocalIds*stride,
false);
909 weightArray[dim] =
input_t(wArray, stride);
910 arrayLengths[dim] = nLocalIds;
915 xyz_ = arcp(coordArray, 0, coordinateDim_);
918 weights_ = arcp(weightArray, 0, userNumWeights_);
927 RCP<const idmap_t> idMap;
930 idMap = rcp(
new idmap_t(env_, comm_, gids_, consecutiveIds));
934 numGlobalCoordinates_ = idMap->getGlobalNumberOfIds();
935 gnosAreGids_ = idMap->gnosAreGids();
939 if (!gnosAreGids_ && nLocalIds>0){
941 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
942 gnos_ = arcp(tmpGno, 0, nLocalIds);
945 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
946 idMap->gidTranslate( gidsNonConst(0,nLocalIds), gnos_(0,nLocalIds),
952 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
954 env_->memory(
"After construction of coordinate model");
956 #endif // DOXYGEN_SHOULD_SKIP_THIS An IdentifierMap manages a global space of object identifiers.
void getGlobalObjectIds(ArrayView< const gno_t > &gnos) const
Get a list of the global Ids for the local objects.
global_size_t getGlobalNumCoordinates() const
Returns the global number coordinates.
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Defines the Model interface.
Zoltan2::StridedData< lno_t, scalar_t > input_t
static void maxCount(const Comm< int > &comm, Array< T > &countValues)
Get the global maximum for each of an array of values.
more involved, like validate a graph
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
algorithm requires consecutive ids
This class provides geometric coordinates with optional weights to the Zoltan2 algorithm.
convert user ids to internal ids
size_t getCoordinates(ArrayView< const gno_t > &Ids, ArrayView< input_t > &xyz, ArrayView< input_t > &wgts) const
Returns the coordinate ids, values and optional weights.
size_t getLocalNumObjects() const
Return the local number of objects.
The StridedData class manages lists of weights or coordinates.
size_t getGlobalNumObjects() const
Return the global number of objects.
size_t getLocalNumCoordinates() const
Returns the number of coordinates on this process.
int getCoordinateWeightDim() const
Returns the dimension (0 or greater) of coordinate weights.
The base class for all model classes.
int getCoordinateDim() const
Returns the dimension of the coordinates.
void setWeightArrayLengths(const Array< lno_t > &len, const Teuchos::Comm< int > &comm)
Set the length of each weight array. The Model calls this in the constructor so we know which weights...
void setIdentifierMap(RCP< const idmap_t > &map)
Set the IdentifierMap used by the model.
This file defines the StridedData class.