50 #ifndef _ZOLTAN2_IDENTIFIERMODEL_HPP_ 51 #define _ZOLTAN2_IDENTIFIERMODEL_HPP_ 81 template <
typename Adapter>
88 #ifndef DOXYGEN_SHOULD_SKIP_THIS 96 throw std::logic_error(
"a specific instantiation should be used");
127 ArrayView<input_t> &wgts)
const {
return 0;}
146 #ifndef DOXYGEN_SHOULD_SKIP_THIS 152 template <
typename User>
157 typedef typename IdentifierInput<User>::scalar_t
scalar_t;
173 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
199 ArrayView<input_t> &wgts)
const 201 Ids = ArrayView<const gno_t>();
202 wgts = weights_.view(0, userWeightDim_);
209 Ids = gnosConst_(0, n);
231 ArrayView<input_t> weights;
238 gno_t numGlobalIdentifiers_;
239 const RCP<const Environment> env_;
240 const RCP<const Comm<int> > comm_;
241 ArrayRCP<const gid_t> gids_;
243 ArrayRCP<input_t> weights_;
244 ArrayRCP<gno_t> gnos_;
245 ArrayRCP<const gno_t> gnosConst_;
248 template <
typename User>
251 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
253 gnosAreGids_(
false), numGlobalIdentifiers_(), env_(env), comm_(comm),
254 gids_(), userWeightDim_(0), weights_(), gnos_(), gnosConst_()
261 Array<const scalar_t *> wgts(userWeightDim_, (
const scalar_t *)NULL);
262 Array<int> wgtStrides(userWeightDim_, 0);
263 Array<lno_t> weightArrayLengths(userWeightDim_, 0);
265 if (userWeightDim_ > 0){
267 weights_ = arcp<input_t>(w, 0, userWeightDim_);
270 const gid_t *gids=NULL;
274 for (
int dim=0; dim < userWeightDim_; dim++)
280 gids_ = arcp(gids, 0, nLocalIds,
false);
282 if (userWeightDim_ > 0){
283 for (
int i=0; i < userWeightDim_; i++){
284 if (wgts[i] != NULL){
285 ArrayRCP<const scalar_t> wgtArray(
286 wgts[i], 0, nLocalIds*wgtStrides[i],
false);
287 weights_[i] =
input_t(wgtArray, wgtStrides[i]);
288 weightArrayLengths[i] = nLocalIds;
296 RCP<const idmap_t> idMap;
300 idMap = rcp(
new idmap_t(env_, comm_, gids_,
true));
302 idMap = rcp(
new idmap_t(env_, comm_, gids_,
false));
306 gnosAreGids_ = idMap->gnosAreGids();
310 gno_t lsum = nLocalIds;
311 reduceAll<int, gno_t>(*comm_, Teuchos::REDUCE_SUM, 1, &lsum,
312 &numGlobalIdentifiers_);
314 if (!gnosAreGids_ && nLocalIds>0){
316 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
317 gnos_ = arcp(tmpGno, 0, nLocalIds);
320 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
321 idMap->gidTranslate( gidsNonConst(0,nLocalIds), gnos_(0,nLocalIds),
327 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
329 env_->memory(
"After construction of identifier model");
336 template <
typename User>
338 public Model<CoordinateInput<User> >
342 typedef typename CoordinateInput<User>::scalar_t
scalar_t;
350 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
376 ArrayView<input_t> &wgts)
const 378 Ids = ArrayView<const gno_t>();
379 wgts = weights_.view(0, userWeightDim_);
386 Ids = gnosConst_(0, n);
408 ArrayView<input_t> weights;
415 gno_t numGlobalIdentifiers_;
416 const RCP<const Environment> env_;
417 const RCP<const Comm<int> > comm_;
418 ArrayRCP<const gid_t> gids_;
420 ArrayRCP<input_t> weights_;
421 ArrayRCP<gno_t> gnos_;
422 ArrayRCP<const gno_t> gnosConst_;
425 template <
typename User>
428 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
430 gnosAreGids_(
false), numGlobalIdentifiers_(), env_(env), comm_(comm),
431 gids_(), userWeightDim_(0), weights_(), gnos_(), gnosConst_()
437 const gid_t *gids=NULL;
447 gids_ = arcp(gids, 0, nLocalIds,
false);
450 RCP<const idmap_t> idMap;
454 idMap = rcp(
new idmap_t(env_, comm_, gids_,
true));
456 idMap = rcp(
new idmap_t(env_, comm_, gids_,
false));
460 numGlobalIdentifiers_ = idMap->getGlobalNumberOfIds();
461 gnosAreGids_ = idMap->gnosAreGids();
468 Array<lno_t> weightListSizes(userWeightDim_, 0);
472 if (userWeightDim_ > 0){
474 weights_ = arcp(weightObj, 0, userWeightDim_);
481 for (
int wdim=0; wdim < userWeightDim_; wdim++){
484 if (wgtListSize > 0){
485 ArrayRCP<const scalar_t> wgtArray(wgts, 0, wgtListSize,
false);
487 weightListSizes[wdim] = wgtListSize;
498 if (!gnosAreGids_ && nLocalIds>0){
500 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
501 gnos_ = arcp(tmpGno, 0, gids_.size());
504 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
505 idMap->gidTranslate(gidsNonConst(0, nLocalIds), gnos_(0, nLocalIds),
511 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
512 env_->memory(
"After construction of identifier model");
520 template <
typename User>
525 typedef typename MatrixInput<User>::scalar_t
scalar_t;
533 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
560 ArrayView<input_t> &wgts)
const 562 Ids = ArrayView<const gno_t>();
563 wgts = weights_.view(0, userWeightDim_);
570 Ids = gnosConst_(0, n);
592 ArrayView<input_t> weights;
599 gno_t numGlobalIdentifiers_;
600 const RCP<const Environment> env_;
601 const RCP<const Comm<int> > comm_;
602 ArrayRCP<const gid_t> gids_;
604 ArrayRCP<input_t> weights_;
605 ArrayRCP<gno_t> gnos_;
606 ArrayRCP<const gno_t> gnosConst_;
610 template <
typename User>
613 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
615 gnosAreGids_(
false), numGlobalIdentifiers_(), env_(env), comm_(comm),
616 gids_(), userWeightDim_(0), weights_(), gnos_(), gnosConst_()
621 const lno_t *offsets;
629 gids_ = arcp(gids, 0, nLocalIds,
false);
632 RCP<const idmap_t> idMap;
636 idMap = rcp(
new idmap_t(env_, comm_, gids_,
true));
638 idMap = rcp(
new idmap_t(env_, comm_, gids_,
false));
642 numGlobalIdentifiers_ = idMap->getGlobalNumberOfIds();
643 gnosAreGids_ = idMap->gnosAreGids();
646 Array<lno_t> weightListSizes;
649 if (!gnosAreGids_ && nLocalIds>0){
651 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
652 gnos_ = arcp(tmpGno, 0, gids_.size());
655 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
656 idMap->gidTranslate(gidsNonConst(0, nLocalIds),
662 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
663 env_->memory(
"After construction of identifier model");
670 template <
typename User>
675 typedef typename VectorInput<User>::scalar_t
scalar_t;
683 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
710 ArrayView<input_t> &wgts)
const 712 Ids = ArrayView<const gno_t>();
713 wgts = weights_.view(0, userWeightDim_);
720 Ids = gnosConst_(0, n);
742 ArrayView<input_t> weights;
749 gno_t numGlobalIdentifiers_;
750 const RCP<const Environment> env_;
751 const RCP<const Comm<int> > comm_;
752 ArrayRCP<const gid_t> gids_;
754 ArrayRCP<input_t> weights_;
755 ArrayRCP<gno_t> gnos_;
756 ArrayRCP<const gno_t> gnosConst_;
760 template <
typename User>
763 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
765 gnosAreGids_(
false), numGlobalIdentifiers_(), env_(env), comm_(comm),
766 gids_(), userWeightDim_(0), weights_(), gnos_(), gnosConst_()
774 nLocalIds = ia->
getVector(gids, elements, stride);
779 gids_ = arcp(gids, 0, nLocalIds,
false);
782 RCP<const idmap_t> idMap;
786 idMap = rcp(
new idmap_t(env_, comm_, gids_,
true));
788 idMap = rcp(
new idmap_t(env_, comm_, gids_,
false));
792 numGlobalIdentifiers_ = idMap->getGlobalNumberOfIds();
793 gnosAreGids_ = idMap->gnosAreGids();
796 Array<lno_t> weightListSizes;
799 if (!gnosAreGids_ && nLocalIds>0){
801 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
802 gnos_ = arcp(tmpGno, 0, gids_.size());
805 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
806 idMap->gidTranslate(gidsNonConst(0, nLocalIds),
812 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
813 env_->memory(
"After construction of identifier model");
820 template <
typename User>
825 typedef typename GraphInput<User>::scalar_t
scalar_t;
841 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
867 ArrayView<input_t> &wgts)
const 869 Ids = ArrayView<const gno_t>();
870 wgts = weights_.view(0, userWeightDim_);
877 Ids = gnosConst_(0, n);
899 ArrayView<input_t> weights;
906 gno_t numGlobalIdentifiers_;
907 const RCP<const Environment> env_;
908 const RCP<const Comm<int> > comm_;
909 ArrayRCP<const gid_t> gids_;
911 ArrayRCP<input_t> weights_;
912 ArrayRCP<gno_t> gnos_;
913 ArrayRCP<const gno_t> gnosConst_;
916 template <
typename User>
919 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
921 gnosAreGids_(
false), numGlobalIdentifiers_(), env_(env), comm_(comm),
922 gids_(), userWeightDim_(0), weights_(), gnos_(), gnosConst_()
929 Array<const scalar_t *> wgts(userWeightDim_, NULL);
930 Array<int> wgtStrides(userWeightDim_, 0);
931 Array<lno_t> weightArrayLengths(userWeightDim_, 0);
933 if (userWeightDim_ > 0){
935 weights_ = arcp<input_t>(w, 0, userWeightDim_);
938 const gid_t *gids=NULL;
941 const lno_t *offsets;
944 for (
int dim=0; dim < userWeightDim_; dim++)
950 gids_ = arcp(gids, 0, nLocalIds,
false);
952 if (userWeightDim_ > 0){
953 for (
int i=0; i < userWeightDim_; i++){
954 if (wgts[i] != NULL){
955 ArrayRCP<const scalar_t> wgtArray(
956 wgts[i], 0, nLocalIds*wgtStrides[i],
false);
957 weights_[i] =
input_t(wgtArray, wgtStrides[i]);
958 weightArrayLengths[i] = nLocalIds;
966 RCP<const idmap_t> idMap;
970 idMap = rcp(
new idmap_t(env_, comm_, gids_,
true));
972 idMap = rcp(
new idmap_t(env_, comm_, gids_,
false));
976 gnosAreGids_ = idMap->gnosAreGids();
980 gno_t lsum = nLocalIds;
981 reduceAll<int, gno_t>(*comm_, Teuchos::REDUCE_SUM, 1, &lsum,
982 &numGlobalIdentifiers_);
984 if (!gnosAreGids_ && nLocalIds>0){
986 env_->localMemoryAssertion(__FILE__, __LINE__, nLocalIds, tmpGno);
987 gnos_ = arcp(tmpGno, 0, nLocalIds);
990 ArrayRCP<gid_t> gidsNonConst = arcp_const_cast<gid_t>(gids_);
991 idMap->gidTranslate( gidsNonConst(0,nLocalIds), gnos_(0,nLocalIds),
997 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
999 env_->memory(
"After construction of identifier model");
1002 #endif // DOXYGEN_SHOULD_SKIP_THIS An IdentifierMap manages a global space of object identifiers.
#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.
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
algorithm requires consecutive ids
void getGlobalObjectIds(ArrayView< const gno_t > &gnos) const
Get a list of the global Ids for the local objects.
int getNumWeights() const
Return the number of weights supplied for each object. If the user supplied no weights, dimension one is returned, because one dimension of uniform weights is implied.
int getIdentifierWeightDim() const
Returns the dimension (0 or greater) of identifier weights.
convert user ids to internal ids
The StridedData class manages lists of weights or coordinates.
size_t getLocalNumObjects() const
Return the local number of objects.
The base class for all model classes.
size_t getLocalNumIdentifiers() const
Returns the number identifiers on this process.
IdentifierModel defines the interface for all identifier models.
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...
size_t getGlobalNumObjects() const
Return the global number of objects.
global_size_t getGlobalNumIdentifiers() const
Returns the global number identifiers.
size_t getIdentifierList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const
Sets pointers to this process' identifier Ids and their weights.
void setIdentifierMap(RCP< const idmap_t > &map)
Set the IdentifierMap used by the model.
This file defines the StridedData class.