50 #ifndef _ZOLTAN2_GRAPHMODEL_HPP_ 51 #define _ZOLTAN2_GRAPHMODEL_HPP_ 63 #include <Teuchos_Hashtable.hpp> 105 const RCP<const Environment> &env,
107 bool removeSelfEdges,
108 bool removeOffProcessEdges,
109 bool removeOffGroupEdges,
112 ArrayView<const int> &procIds,
125 size_t numVtx = offsets.size() - 1;
126 size_t numNbors = gidNbors.size();
128 env->localInputAssertion(__FILE__, __LINE__,
"need more input",
131 static_cast<typename ArrayView<const gid_t>::size_type
>(numVtx))
133 (!removeOffProcessEdges ||
135 static_cast<typename ArrayView<const int>::size_type
>(numNbors)) &&
136 (!removeOffGroupEdges ||
138 static_cast<typename ArrayView<const int>::size_type
>(numNbors)),
144 int eDim = edgeWeights.size();
145 std::vector<bool> uniformWeight;
147 for (
int i=0; i < eDim; i++)
148 uniformWeight[i] = (edgeWeights[i].size() == 0);
153 lno_t *offs =
new lno_t [numVtx + 1];
154 env->localMemoryAssertion(__FILE__, __LINE__, numVtx+1, offs);
155 ArrayRCP<const lno_t> offArray = arcp(offs, 0, numVtx+1,
true);
157 const lno_t *allOffs = offsets.getRawPtr();
158 const gid_t *allIds = gidNbors.getRawPtr();
160 const gid_t *vtx = NULL;
161 const int *proc = NULL;
164 vtx = gids.getRawPtr();
166 if (procIds.size() > 0)
167 proc = procIds.getRawPtr();
170 for (
size_t i=0; i < numVtx; i++){
172 int vid = vtx ? vtx[i] : 0;
173 for (lno_t j=allOffs[i]; j < allOffs[i+1]; j++){
174 int owner = proc ? proc[j] : 0;
175 bool keep = (!removeSelfEdges || vid != allIds[j]) &&
176 (!removeOffProcessEdges || owner == myRank) &&
177 (!removeOffGroupEdges || owner >= 0);
186 for (
size_t i=1; i < numVtx; i++)
187 offs[i+1] += offs[i];
189 numKeep = offs[numVtx];
193 if (numNbors == numKeep){
194 newGidNbors = Teuchos::arcpFromArrayView(gidNbors);
195 newOffsets = Teuchos::arcpFromArrayView(offsets);
198 else if (numKeep == 0){
199 newGidNbors = ArrayRCP<const gid_t>(Teuchos::null);
200 newOffsets = ArrayRCP<const lno_t>(Teuchos::null);
206 gid_t *newGids =
new gid_t [numKeep];
207 env->localMemoryAssertion(__FILE__, __LINE__, numKeep, newGids);
209 newGidNbors = arcp(newGids, 0, numKeep,
true);
210 newOffsets = offArray;
213 newWeights =
new scalar_t * [eDim];
214 env->localMemoryAssertion(__FILE__, __LINE__, eDim, newWeights);
216 for (
int w=0; w < eDim; w++){
217 if (uniformWeight[w])
218 newWeights[w] = NULL;
220 newWeights[w] =
new scalar_t [numKeep];
221 env->localMemoryAssertion(__FILE__, __LINE__, numKeep, newWeights[w]);
227 for (
size_t i=0; i < numVtx && next < numKeep; i++){
228 int vid = vtx ? vtx[i] : 0;
229 for (lno_t j=allOffs[i]; j < allOffs[i+1]; j++){
230 int owner = proc ? proc[j] : 0;
231 bool keep = (!removeSelfEdges || vid != allIds[j]) &&
232 (!removeOffProcessEdges || owner == myRank) &&
233 (!removeOffGroupEdges || owner >= 0);
236 newGids[next] = allIds[j];
238 for (
int w=0; w < eDim; w++){
239 if (!uniformWeight[w])
240 newWeights[w][next] = edgeWeights[w][j];
259 const RCP<const Environment> &env,
int rank,
260 size_t numLocalEdges,
261 size_t numLocalGraphEdges,
264 ArrayRCP<int> &allProcs,
279 bool gnosAreGids = idMap->gnosAreGids();
281 edgeLocalIds = ArrayRCP<const lno_t>(Teuchos::null);
282 offsets = ArrayRCP<const lno_t>(Teuchos::null);
283 eWeights = ArrayRCP<input_t>(Teuchos::null);
285 if (numLocalGraphEdges == 0)
288 if (numLocalGraphEdges == numLocalEdges){
292 lno_t *lnos =
new lno_t [numLocalEdges];
293 env->localMemoryAssertion(__FILE__, __LINE__,numLocalEdges, lnos);
294 for (
size_t i=0; i < numLocalEdges; i++)
296 edgeLocalIds = arcp(lnos, 0, numLocalEdges,
true);
298 eWeights = allWeights;
304 int eWeightDim = allWeights.size();
306 ArrayRCP<const gid_t> newEgids;
307 scalar_t **newWeights = NULL;
309 ArrayView<const gid_t> dummyVtx;
310 ArrayView<const gid_t> nborView= allEdgeIds.view(0, numLocalEdges);
311 ArrayView<const int> nborOwner = allProcs.view(0, numLocalEdges);
312 ArrayView<input_t> eWgts = allWeights.view(0, eWeightDim);
313 ArrayView<const lno_t> offView = allOffs.view(0, allOffs.size());
316 numLocalEdges = removeUndesiredEdges<User>(
330 env->localBugAssertion(__FILE__, __LINE__,
"local graph miscalculation",
336 input_t *wgts =
new input_t [eWeightDim];
337 for (
int w=0; w < eWeightDim; w++){
339 ArrayRCP<const scalar_t> wgtArray(
340 newWeights[w], 0, numLocalGraphEdges,
true);
341 wgts[w] =
input_t(wgtArray, 1);
344 eWeights = arcp(wgts, 0, eWeightDim);
349 ArrayRCP<gno_t> gnoArray;
352 ArrayRCP<const gno_t> gnosConst =
353 arcp_reinterpret_cast<
const gno_t>(newEgids);
354 gnoArray = arcp_const_cast<gno_t>(gnosConst);
358 ArrayRCP<gid_t> gidArray = arcp_const_cast<gid_t>(newEgids);
359 gno_t *gnoList=
new gno_t [numLocalGraphEdges];
360 env->localMemoryAssertion(__FILE__, __LINE__, numLocalGraphEdges,
362 gnoArray = arcp(gnoList, 0, numLocalGraphEdges,
true);
366 gidArray.view(0,numLocalGraphEdges),
367 gnoArray.view(0,numLocalGraphEdges),
375 lno_t *lnoList =
new lno_t [numLocalGraphEdges];
376 env->localMemoryAssertion(__FILE__, __LINE__, numLocalGraphEdges,
378 ArrayView<lno_t> lnoView(lnoList, numLocalGraphEdges);
383 gnoArray.view(0,numLocalGraphEdges),
387 edgeLocalIds = arcp<const lno_t>(lnoList, 0, numLocalGraphEdges,
true);
390 return numLocalGraphEdges;
402 template <
typename Adapter>
407 #ifndef DOXYGEN_SHOULD_SKIP_THIS 426 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
429 throw std::logic_error(
"in non-specialized GraphModel");
477 ArrayView<input_t> &xyz,
478 ArrayView<input_t> &wgts)
const {
return 0;}
498 ArrayView<const int> &procIds, ArrayView<const lno_t> &offsets,
499 ArrayView<input_t> &wgts)
const {
return 0;}
525 ArrayView<const lno_t> &offsets,
526 ArrayView<input_t> &wgts) {
return 0;}
539 #ifndef DOXYGEN_SHOULD_SKIP_THIS 545 template <
typename User>
546 class GraphModel<MatrixInput<User> > :
public Model<MatrixInput<User> >
567 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
594 ArrayView<input_t> &xyz, ArrayView<input_t> &wgts)
const;
596 size_t getEdgeList( ArrayView<const gno_t> &edgeIds,
597 ArrayView<const int> &procIds, ArrayView<const lno_t> &offsets,
598 ArrayView<input_t> &wgts)
const;
601 ArrayView<const lno_t> &offsets,
602 ArrayView<input_t> &wgts){
604 if (localGraphEdgeLnos_.size() <
605 static_cast<typename ArrayRCP<const lno_t>::size_type
>(numLocalGraphEdges_)){
609 computeLocalEdgeList<User>(env_, comm_->getRank(),
610 numLocalEdges_, numLocalGraphEdges_,
611 idmap, edgeGids_, procIds_, offsets_, eWeights_,
612 localGraphEdgeLnos_, localGraphEdgeOffsets_, localGraphEdgeWeights_);
615 edgeIds = localGraphEdgeLnos_();
616 offsets = localGraphEdgeOffsets_();
617 wgts = localGraphEdgeWeights_();
619 return numLocalGraphEdges_;
632 ArrayView<input_t> xyz, wgts;
638 const RCP<const Environment > env_;
639 const RCP<const Comm<int> > comm_;
641 ArrayRCP<const gid_t> gids_;
642 ArrayRCP<gno_t> gnos_;
645 ArrayRCP<input_t> vWeights_;
648 ArrayRCP<input_t> vCoords_;
653 ArrayRCP<const gid_t> edgeGids_;
654 ArrayRCP<gno_t> edgeGnos_;
655 ArrayRCP<int> procIds_;
656 ArrayRCP<const lno_t> offsets_;
659 ArrayRCP<input_t> eWeights_;
661 ArrayRCP<const gno_t> gnosConst_;
662 ArrayRCP<const gno_t> edgeGnosConst_;
663 ArrayRCP<const int> procIdsConst_;
670 ArrayRCP<const lno_t> localGraphEdgeLnos_;
671 ArrayRCP<const lno_t> localGraphEdgeOffsets_;
672 ArrayRCP<input_t> localGraphEdgeWeights_;
676 size_t numLocalVertices_;
677 size_t numGlobalVertices_;
678 size_t numLocalEdges_;
679 size_t numGlobalEdges_;
680 size_t numLocalGraphEdges_;
683 template <
typename User>
685 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
687 env_(env), comm_(comm),
689 vWeightDim_(0), vWeights_(),
690 vCoordDim_(0), vCoords_(),
691 edgeGids_(), edgeGnos_(), procIds_(), offsets_(),
692 eWeightDim_(0), eWeights_(),
693 gnosConst_(), edgeGnosConst_(), procIdsConst_(),
695 localGraphEdgeLnos_(), localGraphEdgeOffsets_(), localGraphEdgeWeights_(),
696 numLocalVertices_(0), numGlobalVertices_(0), numLocalEdges_(0),
697 numGlobalEdges_(0), numLocalGraphEdges_(0)
705 bool consecutiveIdsRequired =
710 if (symTranspose || symBipartite || vertexCols || vertexNz){
711 throw std::runtime_error(
"graph build option not yet implemented");
716 gid_t
const *vtxIds=NULL, *nborIds=NULL;
717 lno_t const *offsets=NULL;
723 numLocalEdges_ = offsets[numLocalVertices_];
725 gids_ = arcp<const gid_t>(vtxIds, 0, numLocalVertices_,
false);
726 edgeGids_ = arcp<const gid_t>(nborIds, 0, numLocalEdges_,
false);
727 offsets_ = arcp<const lno_t>(offsets, 0, numLocalVertices_ + 1,
false);
735 ArrayRCP<const int> nborProcs;
738 RCP<const idmap_t> idMap;
740 idMap = rcp(
new idmap_t(env_, comm_, gids_,
false));
744 ArrayRCP<int> procArray;
746 if (numLocalEdges_ > 0){
747 int *pids =
new int [numLocalEdges_];
748 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalEdges_, pids);
749 procArray = arcp(pids, 0, numLocalEdges_,
true);
752 ArrayView<gno_t> dummyGno;
758 idMap->gidGlobalTranslate( edgeGids_.view(0, numLocalEdges_),
759 dummyGno, procArray.view(0, numLocalEdges_));
764 for (
size_t i=0; i < numLocalEdges_; i++){
765 if (procArray[i] < 0){
771 if (outOfSubset == 0){
776 nborProcs = arcp_const_cast<
const int>(procArray);
782 if (subsetGraph || removeSelfEdges){
784 ArrayRCP<input_t> noEdgeWeights;
785 ArrayRCP<const gid_t> newEdges;
786 ArrayRCP<const lno_t> newOffs;
788 size_t numNewEdges = 0;
794 ArrayView<const gid_t> vtxView= gids_.view(0, numLocalVertices_);
795 ArrayView<const gid_t> nborView= edgeGids_.view(0, numLocalEdges_);
796 ArrayView<const int> nborOwner = nborProcs.view(0, nborProcs.size());
797 ArrayView<input_t> eWgts = noEdgeWeights.view(0, 0);
798 ArrayView<const lno_t> offView = offsets_.view(0, numLocalVertices_ + 1);
801 numNewEdges = Zoltan2::removeUndesiredEdges<User>(env_, comm_->getRank(),
818 if (numNewEdges < numLocalEdges_){
819 edgeGids_ = newEdges;
821 numLocalEdges_ = numNewEdges;
829 RCP<const idmap_t> idMap;
832 idMap = rcp(
new idmap_t(env_, comm_, gids_, consecutiveIdsRequired));
840 numGlobalVertices_ = idMap->getGlobalNumberOfIds();
841 gnosAreGids_ = idMap->gnosAreGids();
847 ArrayView<const gid_t> gidArray(Teuchos::null);
848 ArrayView<gno_t> gnoArray(Teuchos::null);
849 ArrayView<int> procArray(Teuchos::null);
851 if (numLocalVertices_){
855 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalVertices_, tmp);
856 gnos_ = arcp(tmp, 0, numLocalVertices_);
859 ArrayRCP<gid_t> tmpGids = arcp_const_cast<gid_t>(gids_);
861 idMap->gidTranslate(tmpGids(0,numLocalVertices_),
867 tmp =
new gno_t [numLocalEdges_];
868 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalEdges_, tmp);
869 edgeGnos_ = arcp(tmp, 0, numLocalEdges_);
870 gnoArray = edgeGnos_.view(0, numLocalEdges_);
875 gidArray = edgeGids_.view(0, numLocalEdges_);
877 int *p =
new int [numLocalEdges_];
878 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalEdges_, p);
879 procIds_ = arcp(p, 0, numLocalEdges_);
880 procArray = procIds_.view(0, numLocalEdges_);
886 idMap->gidGlobalTranslate(gidArray, gnoArray, procArray);
890 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
891 edgeGnosConst_ = arcp_const_cast<
const gno_t>(edgeGnos_);
892 procIdsConst_ = arcp_const_cast<
const int>(procIds_);
898 numLocalGraphEdges_ = 0;
899 int *pids = procArray.getRawPtr();
900 for (
size_t i=0; i < numLocalEdges_; i++)
901 if (pids[i] == comm_->getRank())
902 numLocalGraphEdges_++;
908 if (vWeightDim_ > 0){
910 env_->localMemoryAssertion(__FILE__, __LINE__, vWeightDim_, weightInfo);
912 for (
int dim=0; dim < vWeightDim_; dim++){
916 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalVertices_, wgts);
917 ArrayRCP<const scalar_t> wgtArray =
918 arcp(wgts, 0, numLocalVertices_,
true);
919 for (
size_t i=0; i < numLocalVertices_; i++){
920 wgts[i] = offsets_[i+1] - offsets_[i];
922 weightInfo[dim] =
input_t(wgtArray, 1);
929 if (weights != NULL){
930 ArrayRCP<const scalar_t> wgtArray = arcp(weights, 0, len,
false);
931 weightInfo[dim] =
input_t(wgtArray, stride);
936 vWeights_ = arcp<input_t>(weightInfo, 0, vWeightDim_,
true);
941 Array<lno_t> weightArrayLengths(vWeightDim_);
942 for (
int dim=0; dim < vWeightDim_; dim++){
943 weightArrayLengths[dim] = vWeights_[dim].size();
953 env_->localMemoryAssertion(__FILE__, __LINE__, vCoordDim_, coordInfo);
955 for (
int dim=0; dim < vCoordDim_; dim++){
959 ArrayRCP<const scalar_t> coordArray = arcp(coords, 0, len,
false);
960 coordInfo[dim] =
input_t(coordArray, stride);
963 vCoords_ = arcp<input_t>(coordInfo, 0, vCoordDim_,
true);
966 reduceAll<int, size_t>(*comm_, Teuchos::REDUCE_SUM, 1,
967 &numLocalEdges_, &numGlobalEdges_);
969 env_->memory(
"After construction of graph model");
972 template <
typename User>
974 ArrayView<const gno_t> &Ids, ArrayView<input_t> &xyz,
975 ArrayView<input_t> &wgts)
const 977 size_t nv = gids_.size();
980 Ids = gids_.view(0, nv);
982 Ids = gnosConst_.view(0, nv);
984 xyz = vCoords_.view(0, vWeightDim_);
985 wgts = vWeights_.view(0, vCoordDim_);
990 template <
typename User>
992 ArrayView<const gno_t> &edgeIds, ArrayView<const int> &procIds,
993 ArrayView<const lno_t> &offsets, ArrayView<input_t> &wgts)
const 996 edgeIds = edgeGids_.view(0, numLocalEdges_);
998 edgeIds = edgeGnosConst_.view(0, numLocalEdges_);
1000 procIds = procIdsConst_.view(0, numLocalEdges_);
1001 offsets = offsets_.view(0, numLocalVertices_+1);
1002 wgts = eWeights_.view(0, eWeightDim_);
1004 return numLocalEdges_;
1011 template <
typename User>
1016 typedef typename GraphInput<User>::scalar_t
scalar_t;
1034 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
1061 ArrayView<input_t> &xyz, ArrayView<input_t> &wgts)
const;
1063 size_t getEdgeList( ArrayView<const gno_t> &edgeIds,
1064 ArrayView<const int> &procIds, ArrayView<const lno_t> &offsets,
1065 ArrayView<input_t> &wgts)
const;
1068 ArrayView<const lno_t> &offsets,
1069 ArrayView<input_t> &wgts){
1071 if (localGraphEdgeLnos_.size() < numLocalGraphEdges_){
1076 numLocalEdges_, numLocalGraphEdges_,
1077 idmap, edgeGids_, procIds_, offsets_, eWeights_,
1078 localGraphEdgeLnos_, localGraphEdgeOffsets_, localGraphEdgeWeights_);
1081 edgeIds = localGraphEdgeLnos_;
1082 offsets = localGraphEdgeOffsets_;
1083 wgts = localGraphEdgeWeights_;
1085 return numLocalGraphEdges_;
1098 ArrayView<input_t> xyz, wgts;
1104 const RCP<const Environment > env_;
1105 const RCP<const Comm<int> > comm_;
1107 ArrayRCP<const gid_t> gids_;
1108 ArrayRCP<gno_t> gnos_;
1111 ArrayRCP<input_t> vWeights_;
1114 ArrayRCP<input_t> vCoords_;
1119 ArrayRCP<const gid_t> edgeGids_;
1120 ArrayRCP<gno_t> edgeGnos_;
1121 ArrayRCP<int> procIds_;
1122 ArrayRCP<const lno_t> offsets_;
1125 ArrayRCP<input_t> eWeights_;
1127 ArrayRCP<const gno_t> gnosConst_;
1128 ArrayRCP<const gno_t> edgeGnosConst_;
1129 ArrayRCP<const int> procIdsConst_;
1136 ArrayRCP<const lno_t> localGraphEdgeLnos_;
1137 ArrayRCP<const lno_t> localGraphEdgeOffsets_;
1138 ArrayRCP<input_t> localGraphEdgeWeights_;
1142 size_t numLocalVertices_;
1143 size_t numGlobalVertices_;
1144 size_t numLocalEdges_;
1145 size_t numGlobalEdges_;
1146 size_t numLocalGraphEdges_;
1150 template <
typename User>
1152 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
1154 env_(env), comm_(comm),
1156 vWeightDim_(0), vWeights_(),
1157 vCoordDim_(0), vCoords_(),
1158 edgeGids_(), edgeGnos_(), procIds_(), offsets_(),
1159 eWeightDim_(0), eWeights_(),
1160 gnosConst_(), edgeGnosConst_(), procIdsConst_(),
1161 gnosAreGids_(
false),
1162 localGraphEdgeLnos_(), localGraphEdgeOffsets_(), localGraphEdgeWeights_(),
1163 numLocalVertices_(0), numGlobalVertices_(0), numLocalEdges_(0),
1164 numGlobalEdges_(0), numLocalGraphEdges_(0)
1168 bool consecutiveIdsRequired =
1175 gid_t
const *vtxIds=NULL, *nborIds=NULL;
1176 lno_t const *offsets=NULL;
1182 numLocalEdges_ = offsets[numLocalVertices_];
1184 gids_ = arcp<const gid_t>(vtxIds, 0, numLocalVertices_,
false);
1185 edgeGids_ = arcp<const gid_t>(nborIds, 0, numLocalEdges_,
false);
1186 offsets_ = arcp<const lno_t>(offsets, 0, numLocalVertices_ + 1,
false);
1190 if (eWeightDim_ > 0){
1192 eWeights_ = arcp(wgts, 0, eWeightDim_,
true);
1195 for (
int w=0; w < eWeightDim_; w++){
1201 ArrayRCP<const scalar_t> wgtArray(ewgts, 0, numLocalEdges_,
false);
1202 eWeights_[w] =
input_t(wgtArray, stride);
1209 ArrayRCP<const int> nborProcs;
1212 RCP<const idmap_t> idMap;
1214 idMap = rcp(
new idmap_t(env_, comm_, gids_,
false));
1218 ArrayRCP<int> procArray;
1220 if (numLocalEdges_ > 0){
1221 int *pids =
new int [numLocalEdges_];
1222 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalEdges_, pids);
1223 procArray = arcp(pids, 0, numLocalEdges_,
true);
1226 ArrayView<gno_t> dummyGno;
1232 idMap->gidGlobalTranslate( edgeGids_.view(0, numLocalEdges_),
1233 dummyGno, procArray.view(0, numLocalEdges_));
1237 int outOfSubset = 0;
1238 for (
size_t i=0; i < numLocalEdges_; i++){
1239 if (procArray[i] < 0){
1245 if (outOfSubset == 0){
1247 subsetGraph =
false;
1250 nborProcs = arcp_const_cast<
const int>(procArray);
1256 if (subsetGraph || removeSelfEdges){
1258 ArrayRCP<const gid_t> newEdges;
1259 ArrayRCP<const lno_t> newOffs;
1261 size_t numNewEdges = 0;
1263 ArrayView<const gid_t> vtxView = gids_.view(0, numLocalVertices_);
1264 ArrayView<const gid_t> nborView= edgeGids_.view(0, numLocalEdges_);
1265 ArrayView<const int> nborOwner = nborProcs.view(0, nborProcs.size());
1266 ArrayView<input_t> eWgts = eWeights_.view(0, eWeightDim_);
1267 ArrayView<const lno_t> offView = offsets_.view(0, numLocalVertices_ + 1);
1270 numNewEdges = removeUndesiredEdges<User>(env_, comm_->getRank(),
1287 if (numNewEdges < numLocalEdges_){
1288 edgeGids_ = newEdges;
1290 numLocalEdges_ = numNewEdges;
1292 for (
int w=0; w < eWeightDim_; w++){
1293 if (newWeights[w] != NULL){
1294 ArrayRCP<const scalar_t> wgtArray(newWeights[w],
1295 0, numNewEdges,
true);
1296 eWeights_[w] =
input_t(wgtArray, 1);
1306 RCP<const idmap_t> idMap;
1309 idMap = rcp(
new idmap_t(env_, comm_, gids_, consecutiveIdsRequired));
1317 numGlobalVertices_ = idMap->getGlobalNumberOfIds();
1318 gnosAreGids_ = idMap->gnosAreGids();
1324 ArrayView<const gid_t> gidArray(Teuchos::null);
1325 ArrayView<gno_t> gnoArray(Teuchos::null);
1326 ArrayView<int> procArray(Teuchos::null);
1328 if (numLocalVertices_){
1332 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalVertices_, tmp);
1333 gnos_ = arcp(tmp, 0, numLocalVertices_);
1336 ArrayRCP<gid_t> tmpGids = arcp_const_cast<gid_t>(gids_);
1338 idMap->gidTranslate(tmpGids(0,numLocalVertices_),
1343 if (numLocalEdges_){
1344 tmp =
new gno_t [numLocalEdges_];
1345 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalEdges_, tmp);
1346 edgeGnos_ = arcp(tmp, 0, numLocalEdges_);
1347 gnoArray = edgeGnos_.view(0, numLocalEdges_);
1351 if (numLocalEdges_){
1352 gidArray = edgeGids_.view(0, numLocalEdges_);
1354 int *p =
new int [numLocalEdges_];
1355 env_->localMemoryAssertion(__FILE__, __LINE__, numLocalEdges_, p);
1356 procIds_ = arcp(p, 0, numLocalEdges_);
1357 procArray = procIds_.view(0, numLocalEdges_);
1363 idMap->gidGlobalTranslate(gidArray, gnoArray, procArray);
1367 gnosConst_ = arcp_const_cast<
const gno_t>(gnos_);
1368 edgeGnosConst_ = arcp_const_cast<
const gno_t>(edgeGnos_);
1369 procIdsConst_ = arcp_const_cast<
const int>(procIds_);
1375 numLocalGraphEdges_ = 0;
1376 int *pids = procArray.getRawPtr();
1377 for (
lno_t i=0; i < numLocalEdges_; i++)
1378 if (pids[i] == comm_->getRank())
1379 numLocalGraphEdges_++;
1385 if (vWeightDim_ > 0){
1387 env_->localMemoryAssertion(__FILE__, __LINE__, vWeightDim_, weightInfo);
1389 for (
int dim=0; dim < vWeightDim_; dim++){
1394 if (weights != NULL){
1395 ArrayRCP<const scalar_t> wgtArray = arcp(weights, 0, len,
false);
1396 weightInfo[dim] =
input_t(wgtArray, stride);
1400 vWeights_ = arcp<input_t>(weightInfo, 0, vWeightDim_,
true);
1405 Array<lno_t> weightArrayLengths(vWeightDim_);
1406 for (
int dim=0; dim < vWeightDim_; dim++){
1407 weightArrayLengths[dim] = vWeights_[dim].size();
1415 if (vCoordDim_ > 0){
1417 env_->localMemoryAssertion(__FILE__, __LINE__, vCoordDim_, coordInfo);
1419 for (
int dim=0; dim < vCoordDim_; dim++){
1423 ArrayRCP<const scalar_t> coordArray = arcp(coords, 0, len,
false);
1424 coordInfo[dim] =
input_t(coordArray, stride);
1427 vCoords_ = arcp<input_t>(coordInfo, 0, vCoordDim_,
true);
1430 reduceAll<int, size_t>(*comm_, Teuchos::REDUCE_SUM, 1,
1431 &numLocalEdges_, &numGlobalEdges_);
1433 env_->memory(
"After construction of graph model");
1436 template <
typename User>
1438 ArrayView<const gno_t> &Ids, ArrayView<input_t> &xyz,
1439 ArrayView<input_t> &wgts)
const 1441 size_t nv = gids_.size();
1444 Ids = gids_.view(0, nv);
1446 Ids = gnosConst_.view(0, nv);
1448 xyz = vCoords_.view(0, vWeightDim_);
1449 wgts = vWeights_.view(0, vCoordDim_);
1454 template <
typename User>
1456 ArrayView<const gno_t> &edgeIds, ArrayView<const int> &procIds,
1457 ArrayView<const lno_t> &offsets, ArrayView<input_t> &wgts)
const 1460 edgeIds = edgeGids_.view(0, numLocalEdges_);
1462 edgeIds = edgeGnosConst_.view(0, numLocalEdges_);
1464 procIds = procIdsConst_.view(0, numLocalEdges_);
1465 offsets = offsets_.view(0, numLocalVertices_+1);
1466 wgts = eWeights_.view(0, eWeightDim_);
1468 return numLocalEdges_;
1478 template <
typename User>
1479 class GraphModel<CoordinateInput<User> > :
public Model<CoordinateInput<User> >
1483 typedef typename CoordinateInput<User>::scalar_t
scalar_t;
1489 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
1492 throw std::runtime_error(
"may not build a graph with identifiers");
1506 ArrayView<input_t> &xyz,
1507 ArrayView<input_t> &wgts)
const {
return 0; }
1508 size_t getEdgeList( ArrayView<const gno_t> &edgeIds,
1509 ArrayView<const int> &procIds, ArrayView<const lno_t> &offsets,
1510 ArrayView<input_t> &wgts)
const {
return 0; }
1512 ArrayView<const lno_t> &offsets,
1513 ArrayView<input_t> &wgts) {
return 0; }
1530 template <
typename User>
1531 class GraphModel<VectorInput<User> > :
public Model<VectorInput<User> >
1535 typedef typename VectorInput<User>::scalar_t
scalar_t;
1541 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
1544 throw std::runtime_error(
"can not build a graph from a vector");
1558 ArrayView<input_t> &xyz,
1559 ArrayView<input_t> &wgts)
const {
return 0; }
1560 size_t getEdgeList( ArrayView<const gno_t> &edgeIds,
1561 ArrayView<const int> &procIds, ArrayView<const lno_t> &offsets,
1562 ArrayView<input_t> &wgts)
const {
return 0; }
1564 ArrayView<const lno_t> &offsets,
1565 ArrayView<input_t> &wgts) {
return 0; }
1582 template <
typename User>
1583 class GraphModel<IdentifierInput<User> > :
public Model<IdentifierInput<User> >
1587 typedef typename IdentifierInput<User>::scalar_t
scalar_t;
1593 const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
1596 throw std::runtime_error(
"can not build a graph with identifiers");
1610 ArrayView<input_t> &xyz,
1611 ArrayView<input_t> &wgts)
const {
return 0; }
1612 size_t getEdgeList( ArrayView<const gno_t> &edgeIds,
1613 ArrayView<const int> &procIds, ArrayView<const lno_t> &offsets,
1614 ArrayView<input_t> &wgts)
const {
return 0; }
1616 ArrayView<const lno_t> &offsets,
1617 ArrayView<input_t> &wgts) {
return 0; }
1627 #endif // DOXYGEN_SHOULD_SKIP_THIS use columns as graph vertices
An IdentifierMap manages a global space of object identifiers.
int getEdgeWeightDim() const
Returns the dimension (0 or greater) of edge weights.
int getVertexWeightDim() const
Returns the dimension (0 or greater) of vertex weights.
size_t getGlobalNumObjects() const
Return the global number of objects.
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
size_t getLocalNumLocalEdges() const
Returns the number of local edges on this process. Does not include edges to off-process vertices...
Defines the Model interface.
Zoltan2::StridedData< lno_t, scalar_t > input_t
convert internal ids to user ids
size_t removeUndesiredEdges(const RCP< const Environment > &env, int myRank, bool removeSelfEdges, bool removeOffProcessEdges, bool removeOffGroupEdges, ArrayView< const typename InputTraits< User >::gid_t > &gids, ArrayView< const typename InputTraits< User >::gid_t > &gidNbors, ArrayView< const int > &procIds, ArrayView< StridedData< typename InputTraits< User >::lno_t, typename InputTraits< User >::scalar_t > > &edgeWeights, ArrayView< const typename InputTraits< User >::lno_t > &offsets, ArrayRCP< const typename InputTraits< User >::gid_t > &newGidNbors, typename InputTraits< User >::scalar_t **&newWeights, ArrayRCP< const typename InputTraits< User >::lno_t > &newOffsets)
Helper function to remove undesired edges from a graph.
size_t getLocalNumGlobalEdges() const
Returns the number of global edges on this process. Includes remote edges.
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
algorithm requires consecutive ids
model must symmetrize input
model must symmetrize input
GraphModel(const Adapter *ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &modelFlags)
Constructor.
size_t getGlobalNumVertices() const
Returns the global number vertices.
convert user ids to internal ids
size_t getEdgeList(ArrayView< const gno_t > &edgeIds, ArrayView< const int > &procIds, ArrayView< const lno_t > &offsets, ArrayView< input_t > &wgts) const
Sets pointers to this process' edge (neighbor) global Ids, including off-process edges.
int getCoordinateDim() const
Returns the dimension (0 to 3) of vertex coordinates.
use nonzeros as graph vertices
size_t getGlobalNumEdges() const
Returns the global number edges.
The StridedData class manages lists of weights or coordinates.
size_t computeLocalEdgeList(const RCP< const Environment > &env, int rank, size_t numLocalEdges, size_t numLocalGraphEdges, RCP< const IdentifierMap< User > > &idMap, ArrayRCP< const typename InputTraits< User >::gid_t > &allEdgeIds, ArrayRCP< int > &allProcs, ArrayRCP< const typename InputTraits< User >::lno_t > &allOffs, ArrayRCP< StridedData< typename InputTraits< User >::lno_t, typename InputTraits< User >::scalar_t > > &allWeights, ArrayRCP< const typename InputTraits< User >::lno_t > &edgeLocalIds, ArrayRCP< const typename InputTraits< User >::lno_t > &offsets, ArrayRCP< StridedData< typename InputTraits< User >::lno_t, typename InputTraits< User >::scalar_t > > &eWeights)
Helper function to create new edges lists containing only edges connected to a neighbor on this proce...
size_t getLocalNumVertices() const
Returns the number vertices on this process.
size_t getLocalEdgeList(ArrayView< const lno_t > &edgeIds, ArrayView< const lno_t > &offsets, ArrayView< input_t > &wgts)
Sets pointers to this process' local-only edge (neighbor) LNOs, using the same implied vertex LNOs re...
GraphModel defines the interface required for graph models.
size_t getLocalNumObjects() const
Return the local number of objects.
The base class for all model classes.
algorithm requires no self edges
RCP< const idmap_t > getIdentifierMap() const
Return the map from user global identifiers to internal Zoltan2 global numbers.
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 getGlobalObjectIds(ArrayView< const gno_t > &gnos) const
Get a list of the global Ids for the local objects.
size_t getVertexList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &xyz, ArrayView< input_t > &wgts) const
Sets pointers to this process' vertex Ids and their weights.
void setIdentifierMap(RCP< const idmap_t > &map)
Set the IdentifierMap used by the model.
Kokkos::DefaultNode::DefaultNodeType node_t
This file defines the StridedData class.