46 #ifndef MUELU_COUPLEDAGGREGATIONCOMMHELPER_DEF_HPP
47 #define MUELU_COUPLEDAGGREGATIONCOMMHELPER_DEF_HPP
59 #include "MueLu_Utilities.hpp"
63 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 import_ = ImportFactory::Build(uniqueMap, nonUniqueMap);
66 tempVec_ = VectorFactory::Build(uniqueMap,
false);
69 myPID_ = uniqueMap->getComm()->getRank();
72 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 const size_t nodeNumElements = weightMap->getNodeNumElements();
77 int MyPid = comm->getRank();
81 if (comm->getSize() == 1) {
83 ArrayRCP<LO> serialProcWinner = procWinner_.getDataNonConst(0);
84 for (
size_t i=0; i < nodeNumElements; ++i) {
85 if (serialWeight[i] > 0) {
87 serialProcWinner[i] = MyPid;
94 #ifdef COMPARE_IN_OUT_VECTORS
95 RCP<Vector> in_weight_ = VectorFactory::Build(weight_.getMap());
99 for (
size_t i=0; i < nodeNumElements; ++i) in_weight[i] = weight[i];
101 RCP<LOVector> in_procWinner_ = LOVectorFactory::Build(procWinner_.getMap());
103 ArrayRCP<LO> in_procWinner = in_procWinner_->getDataNonConst(0);
104 ArrayRCP<LO> procWinner = procWinner_.getDataNonConst(0);
105 for (
size_t i=0; i < nodeNumElements; ++i) in_procWinner[i] = procWinner[i];
109 if (companion != NULL) {
110 in_companion = LOMultiVectorFactory::Build(companion->getMap(), companion->getNumVectors());
111 ArrayRCP<LO> in_comp = in_companion->getDataNonConst(0);
113 for (
size_t i=0; i < nodeNumElements; ++i) in_comp[i] = comp[i];
121 if (perturbWt_ == Teuchos::null || !perturbWt_->getMap()->isSameAs(*weightMap)) {
122 perturbWt_ = VectorFactory::Build(weightMap,
false);
126 ST::seedrandom( Teuchos::as<unsigned int>(MyPid*47) );
127 for (
int i = 0; i < 10; ++i) ST::random();
132 ArrayRCP<SC> lperturbWt = perturbWt_->getDataNonConst(0);
133 for (
size_t i=0; i < nodeNumElements; ++i)
134 lperturbWt[i] = 1e-7*fabs(ST::random());
135 #ifdef COMPARE_IN_OUT_VECTORS
136 ArrayRCP<SC> locperturbWt = perturbWt_->getDataNonConst(0);
137 for (
size_t i=0; i < nodeNumElements; ++i)
138 printf(
"perturbWt[%d] = %15.10e\n",i,locperturbWt[i]);
143 ArrayRCP<SC> perturbWt = perturbWt_->getDataNonConst(0);
147 SC largestGlobalWeight = weight_.normInf();
148 for (
size_t i=0; i < nodeNumElements; ++i) {
149 if (weight[i] != 0.) {
150 weight[i] += largestGlobalWeight*perturbWt[i];
162 if (postComm_ == Teuchos::null || !postComm_->getMap()->isSameAs(*weightMap) )
163 postComm_ = VectorFactory::Build(weightMap);
183 if (candidateWinners_ == Teuchos::null || !candidateWinners_->getMap()->isSameAs(*weightMap) )
184 candidateWinners_ = VectorFactory::Build(weightMap,
false);
190 ArrayRCP<SC> candidateWinners = candidateWinners_->getDataNonConst(0);
192 for (
size_t i=0; i < nodeNumElements; ++i) {
193 if (postComm[i] == weight[i]) candidateWinners[i] = (
SC) MyPid+1;
194 else candidateWinners[i] = 0;
195 weight[i]=postComm[i];
198 NonUnique2NonUnique(*candidateWinners_, *postComm_,
Xpetra::ABSMAX);
205 int numMyWinners = 0;
206 ArrayRCP<LO> procWinner = procWinner_.getDataNonConst(0);
209 for (
size_t i=0; i < nodeNumElements; ++i) {
210 if ( weight[i] != 0.) procWinner[i] = ((int) (postComm[i])) - 1;
213 if (procWinner[i] == MyPid) ++numMyWinners;
217 weight = Teuchos::null;
219 if (companion != NULL) {
232 if (numMyWinners != numMyWinners_ || winnerMap_ == Teuchos::null) {
237 numMyWinners_ = numMyWinners;
241 procWinner = Teuchos::null;
242 std::cout << MyPid <<
": nodeNumElements=" << nodeNumElements << std::endl;
243 std::cout << MyPid <<
": procWinner=" << procWinner_ << std::endl;
244 procWinner = procWinner_.getDataNonConst(0);
250 for (
size_t i = 0; i < nodeNumElements; ++i) {
251 if (procWinner[i] == MyPid) {
252 myWinners_[numMyWinners++] = myGids[i];
258 bool entryMismatch=
false;
260 for (
size_t i = 0; i < nodeNumElements; ++i) {
261 if (procWinner[i] == MyPid) {
262 if (myWinners_[numMyWinners++] != myGids[i]) {
269 if (entryMismatch ==
true) {
273 for (
size_t i = 0; i < nodeNumElements; ++i) {
274 if (procWinner[i] == MyPid) {
275 myWinners_[numMyWinners++] = myGids[i];
281 procWinner = Teuchos::null;
284 std::cout << MyPid <<
": numMyWinners=" << numMyWinners << std::endl;
285 std::cout << MyPid <<
": myWinners_" << myWinners_ << std::endl;
286 for(
int i=0;i<numMyWinners; i++)
287 std::cout << MyPid <<
": myWinners_[locId=" << i <<
"] = " << myWinners_[i] << std::endl;
293 int irealloc,orealloc;
294 if (realloc) irealloc=1;
297 if (orealloc == 1) realloc=
true;
304 winnerMap_ = MapFactory::Build(weightMap->lib(), GSTI, myWinners_(), 0, weightMap->getComm());
310 RCP<LOMultiVector> justWinners = LOMultiVectorFactory::Build(winnerMap_, companion->getNumVectors());
314 std::cout << MyPid <<
": justWinners(Vector in)=" << *justWinners << std::endl;
318 if ( winnerImport_ == Teuchos::null
319 || !winnerImport_->getSourceMap()->isSameAs(*weightMap)
320 || !winnerImport_->getTargetMap()->isSameAs(*winnerMap_) )
321 winnerImport_ = ImportFactory::Build(weightMap, winnerMap_);
327 catch(std::exception& e)
329 std::cout << MyPid <<
": ERR2: An exception occurred." << std::endl;
340 if (!weightMap->getComm()->getRank())
341 std::cout <<
"------ winnerMap_ ------" << std::endl;
343 if (!weightMap->getComm()->getRank())
344 std::cout <<
"------ weightMap ------" << std::endl;
345 weightMap->getComm()->barrier();
356 if ( pushWinners_ == Teuchos::null
357 || !pushWinners_->getSourceMap()->isSameAs(*winnerMap_)
358 || !pushWinners_->getTargetMap()->isSameAs(*weightMap) )
359 pushWinners_ = ImportFactory::Build(winnerMap_,weightMap);
374 catch(std::exception& e)
385 std::cout << MyPid <<
": numMyWinners=" << numMyWinners << std::endl;
387 std::cout << MyPid <<
": justWinners(Vector in)=" << std::endl;
390 std::cout << MyPid <<
": companion(Vector out)=" << std::endl;
394 std::cout << MyPid <<
": winnerMap_=" << *winnerMap_ << std::endl;
395 std::cout << MyPid <<
": weight_.Map=" << *weightMap << std::endl;
401 #ifdef COMPARE_IN_OUT_VECTORS
403 std::cout <<
"==============" << std::endl;
404 std::cout <<
"call #" << numCalls <<
" (1-based)" << std::endl;
405 std::cout <<
"==============" << std::endl;
412 std::string sameOrDiff;
414 ArrayRCP<SC> in_weight = in_weight_->getDataNonConst(0);
416 if (MyPid == 0) std::cout <<
"==============\nweight\n==============\n" << std::endl;
417 for (
size_t i=0; i < weight_.getLocalLength(); ++i) {
418 if (in_weight[i] - weight[i] != 0) sameOrDiff =
" <<<<";
419 else sameOrDiff =
" ";
420 std::cout << std::setw(3) << i<<
": " << in_weight[i] <<
" " << weight[i] << sameOrDiff << in_weight[i] - weight[i] << std::endl;
433 ArrayRCP<LO> in_procWinner = in_procWinner_->getDataNonConst(0);
434 ArrayRCP<LO> procWinner = procWinner_.getDataNonConst(0);
435 if (MyPid == 0) std::cout <<
"==============\nprocWinner\n==============\n" << std::endl;
436 for (
size_t i=0; i < procWinner_.getLocalLength(); ++i) {
437 if (in_procWinner[i] != procWinner[i]) sameOrDiff =
" <<<<";
438 else sameOrDiff =
" ";
439 std::cout << std::setw(3) << i<<
": " << in_procWinner[i] <<
" " << procWinner[i] << sameOrDiff << std::endl;
452 if (companion != NULL) {
453 ArrayRCP<LO> in_comp = in_companion->getDataNonConst(0);
455 if (MyPid == 0) std::cout <<
"==============\ncompanion\n==============\n" << std::endl;
456 for (
size_t i=0; i < companion->getLocalLength(); ++i) {
457 if (in_comp[i] != comp[i]) sameOrDiff =
" <<<<";
458 else sameOrDiff =
" ";
459 std::cout << std::setw(3) << i<<
": " << in_comp[i] <<
" " << comp[i] << sameOrDiff << std::endl;
474 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
476 tempVec_->putScalar(0.);
480 tempVec_->doExport(source, *import_, what);
483 catch(std::exception& e)
485 int MyPid = tempVec_->getMap()->getComm()->getRank();
486 std::cout << MyPid <<
": ERR1: An exception occurred." << std::endl;
493 #endif // MUELU_COUPLEDAGGREGATIONCOMMHELPER_DEF_HPP
#define MueLu_maxAll(rcpComm, in, out)
void NonUnique2NonUnique(const Vector &source, Vector &dest, const Xpetra::CombineMode what) const
Redistribute data in source to dest where both source and dest might have multiple copies of the same...
void ArbitrateAndCommunicate(Vector &weights, Aggregates &aggregates, const bool perturb) const
This method assigns unknowns to aggregates.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
CoupledAggregationCommHelper(const RCP< const Map > &uniqueMap, const RCP< const Map > &nonUniqueMap)
Constructor.
void realloc(DynRankView< T, P...> &v, const size_t n0=KOKKOS_INVALID_INDEX, const size_t n1=KOKKOS_INVALID_INDEX, const size_t n2=KOKKOS_INVALID_INDEX, const size_t n3=KOKKOS_INVALID_INDEX, const size_t n4=KOKKOS_INVALID_INDEX, const size_t n5=KOKKOS_INVALID_INDEX, const size_t n6=KOKKOS_INVALID_INDEX, const size_t n7=KOKKOS_INVALID_INDEX)