// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /* * MueLu_RepartitionInterface_def.hpp * * Created on: 5 Sep 2013 * Author: wiesner */ #ifndef MUELU_REPARTITIONINTERFACE_DEF_HPP_ #define MUELU_REPARTITIONINTERFACE_DEF_HPP_ #include "MueLu_RepartitionInterface_decl.hpp" #include "MueLu_Level.hpp" #include "MueLu_Exceptions.hpp" #include "MueLu_Monitor.hpp" namespace MueLu { template RCP RepartitionInterface::GetValidParameterList() const { RCP validParamList = rcp(new ParameterList()); validParamList->set >("A", Teuchos::null, "Factory of the matrix A"); validParamList->set >("number of partitions", Teuchos::null, "Instance of RepartitionHeuristicFactory."); validParamList->set >("AmalgamatedPartition", Teuchos::null, "(advanced) Factory generating the AmalgamatedPartition (e.g. an IsorropiaInterface)"); return validParamList; } template void RepartitionInterface::DeclareInput(Level ¤tLevel) const { Input(currentLevel, "A"); Input(currentLevel, "number of partitions"); Input(currentLevel, "AmalgamatedPartition"); } // DeclareInput() template void RepartitionInterface::Build(Level &level) const { FactoryMonitor m(*this, "Build", level); RCP A = Get >(level, "A"); RCP > amalgPartition = Get > >(level, "AmalgamatedPartition"); int numParts = Get(level, "number of partitions"); RCP rowMap = A->getRowMap(); // standard case: use matrix info and amalgamated rebalancing info to create "Partition" vector RCP > comm = A->getRowMap()->getComm(); // Short cut: if we only need one partition, then create a dummy partition vector if (numParts == 1 || numParts == -1) { // Single processor, decomposition is trivial: all zeros RCP > decomposition = Xpetra::VectorFactory::Build(rowMap, true); Set(level, "Partition", decomposition); return; } /* else if (numParts == -1) { // No repartitioning RCP > decomposition = Teuchos::null; //Xpetra::VectorFactory::Build(rowMap, true); //decomposition->putScalar(Teuchos::as(comm->getRank())); Set(level, "Partition", decomposition); return; }*/ ArrayRCP amalgPartitionData = amalgPartition->getDataNonConst(0); RCP nodeMap = amalgPartition->getMap(); // extract amalgamation information from matrix A LO blockdim = 1; // block dim for fixed size blocks LO blockid = -1; // block id in strided map LO nStridedOffset = 0; // DOF offset for strided block id "blockid" (default = 0) LO stridedblocksize = blockdim; // size of strided block id "blockid" (default = fullblocksize, only if blockid!=-1 stridedblocksize <= fullblocksize) // 1) check for blocking/striding information // fill above variables if (A->IsView("stridedMaps") && Teuchos::rcp_dynamic_cast(A->getRowMap("stridedMaps")) != Teuchos::null) { Xpetra::viewLabel_t oldView = A->SwitchToView("stridedMaps"); // note: "stridedMaps are always non-overlapping (correspond to range and domain maps!) RCP strMap = Teuchos::rcp_dynamic_cast(A->getRowMap()); TEUCHOS_TEST_FOR_EXCEPTION(strMap == Teuchos::null, Exceptions::BadCast, "MueLu::RepartitionInterface::Build: cast to strided row map failed."); blockdim = strMap->getFixedBlockSize(); blockid = strMap->getStridedBlockId(); if (blockid > -1) { std::vector stridingInfo = strMap->getStridingData(); for (size_t j = 0; j < Teuchos::as(blockid); j++) nStridedOffset += stridingInfo[j]; stridedblocksize = Teuchos::as(stridingInfo[blockid]); } else { stridedblocksize = blockdim; } oldView = A->SwitchToView(oldView); // GetOStream(Statistics0, -1) << "RepartitionInterface::Build():" << " found blockdim=" << blockdim << " from strided maps (blockid=" << blockid << ", strided block size=" << stridedblocksize << "). offset=" << offset << std::endl; } else GetOStream(Statistics0, -1) << "RepartitionInterface::Build(): no striding information available. Use blockdim=1 with offset=0" << std::endl; // vector which stores final (unamalgamated) repartitioning RCP > decomposition = Xpetra::VectorFactory::Build(rowMap, false); ArrayRCP decompEntries = decomposition->getDataNonConst(0); TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as(nodeMap->getLocalNumElements()) * stridedblocksize != Teuchos::as(rowMap->getLocalNumElements()), Exceptions::RuntimeError, "Inconsistency between nodeMap and dofMap: we are supporting block maps only. No support for general strided maps, yet!"); // RCP > > nodegid2dofgids = amalgInfo->GetGlobalAmalgamationParams(); // fill vector with information about partitioning // TODO: we assume simple block maps here // TODO: adapt this to usage of nodegid2dofgids for (size_t i = 0; i < nodeMap->getLocalNumElements(); i++) { // not fully sure about this. We're filling local ids in the decomposition vector with // the results stored in array. The decomposition vector is created using the rowMap of A // transform local node id to global node id. // GO gNodeId = nodeMap->getGlobalElement(i); // extract global DOF ids that belong to gNodeId /*std::vector DOFs = (*nodegid2dofgids)[gNodeId]; for(size_t j=0; jgetLocalElement(DOFs[j]); // -> i doubt that we need this! // put the same domain id to all DOFs of the same node decompEntries[i * stridedblocksize + j] = amalgPartitionData[i]; // decompEntries[lDofId] = amalgPartitionData[i]; } } Set(level, "Partition", decomposition); } // Build() } // namespace MueLu #endif /* MUELU_REPARTITIONINTERFACE_DEF_HPP_ */