// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef MUELU_ZOLTAN2INTERFACE_DECL_HPP #define MUELU_ZOLTAN2INTERFACE_DECL_HPP #include "MueLu_ConfigDefs.hpp" #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI) #include #include #include "MueLu_SingleLevelFactoryBase.hpp" #include "MueLu_Zoltan2Interface_fwd.hpp" #include "MueLu_Level_fwd.hpp" #include "MueLu_FactoryBase_fwd.hpp" #if defined(HAVE_MUELU_ZOLTAN) #include "MueLu_ZoltanInterface.hpp" #endif namespace MueLu { /*! @class Zoltan2Interface @brief Interface to Zoltan2 library. @ingroup Rebalancing This interface provides access to partitioning methods in Zoltan2. Currently, it supports RCB and multijagged as well as all graph partitioning algorithms from Zoltan2. ## Input/output of Zoltan2Interface ## ### User parameters of Zoltan2Interface ### Parameter | type | default | master.xml | validated | requested | description ----------|------|---------|:----------:|:---------:|:---------:|------------ | A | Factory | null | | * | * | Generating factory of the matrix A used during the prolongator smoothing process | | Coordinates | Factory | null | | * | (*) | Factory generating coordinates vector used for rebalancing. The coordinates are only needed when the chosen algorithm is 'multijagged' or 'rcb'. | ParameterList | ParamterList | null | | * | | Zoltan2 parameters | number of partitions | GO | - | | | | Short-cut parameter set by RepartitionFactory. Avoid repartitioning algorithms if only one partition is necessary (see details below) The * in the @c master.xml column denotes that the parameter is defined in the @c master.xml file.
The * in the @c validated column means that the parameter is declared in the list of valid input parameters (see Zoltan2Interface::GetValidParameters).
The * in the @c requested column states that the data is requested as input with all dependencies (see Zoltan2Interface::DeclareInput). ### Variables provided by Zoltan2Interface ### After Zoltan2Interface::Build the following data is available (if requested) Parameter | generated by | description ----------|--------------|------------ | Partition | Zoltan2Interface | GOVector based on the Row map of A (DOF-based) containing the process id the DOF should be living in after rebalancing/repartitioning The "Partition" vector is used as input for the RepartitionFactory class. If Re-partitioning/rebalancing is necessary it uses the "Partition" variable to create the corresponding Xpetra::Import object which then is used by the RebalanceFactory classes (e.g., RebalanceAcFactory, RebalanceTransferFactory,...) to rebalance the coarse level operators. The RepartitionHeuristicFactory calculates how many partitions are to be built when performing rebalancing. It stores the result in the "number of partitions" variable on the current level (type = GO). If it is "number of partitions=1" we skip the Zoltan2 call and just create an dummy "Partition" vector containing zeros only. If no repartitioning is necessary (i.e., just keep the current partitioning) we return "Partition = Teuchos::null". If "number of partitions" > 1, the algorithm tries to find the requested number of partitions. */ // FIXME: this class should not be templated template class Zoltan2Interface : public SingleLevelFactoryBase { #undef MUELU_ZOLTAN2INTERFACE_SHORT #include "MueLu_UseShortNames.hpp" public: //! @name Constructors/Destructors //@{ //! Constructor Zoltan2Interface(); //! Destructor virtual ~Zoltan2Interface() {} //@} RCP GetValidParameterList() const; //! @name Input //@{ void DeclareInput(Level& currentLevel) const; //@} //! @name Build methods. //@{ void Build(Level& currentLevel) const; //@} private: RCP defaultZoltan2Params; }; // class Zoltan2Interface #ifdef HAVE_MUELU_EPETRA #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) #if defined(HAVE_MUELU_ZOLTAN) // Stub partial specialization of Zoltan2Interface for EpetraNode // Use ZoltanInterface instead of Zoltan2Interface template <> class Zoltan2Interface : public SingleLevelFactoryBase { typedef double Scalar; typedef int LocalOrdinal; typedef int GlobalOrdinal; typedef Xpetra::EpetraNode Node; #undef MUELU_ZOLTAN2INTERFACE_SHORT #include "MueLu_UseShortNames.hpp" public: typedef typename Teuchos::ScalarTraits::magnitudeType real_type; typedef Xpetra::MultiVector RealValuedMultiVector; Zoltan2Interface() { level_ = rcp(new Level()); zoltanInterface_ = rcp(new ZoltanInterface()); level_->SetLevelID(1); } virtual ~Zoltan2Interface() { zoltanInterface_ = Teuchos::null; level_ = Teuchos::null; } RCP GetValidParameterList() const { RCP validParamList = rcp(new ParameterList()); validParamList->set >("A", Teuchos::null, "Factory of the matrix A"); validParamList->set >("Coordinates", Teuchos::null, "Factory of the coordinates"); validParamList->set >("number of partitions", Teuchos::null, "Instance of RepartitionHeuristicFactory."); validParamList->set >("ParameterList", Teuchos::null, "Zoltan2 parameters"); return validParamList; }; void DeclareInput(Level& currentLevel) const { Input(currentLevel, "A"); Input(currentLevel, "number of partitions"); const ParameterList& pL = GetParameterList(); // We do this dance, because we don't want "ParameterList" to be marked as used. // Is there a better way? Teuchos::ParameterEntry entry = pL.getEntry("ParameterList"); RCP providedList = Teuchos::any_cast >(entry.getAny(false)); if (providedList != Teuchos::null && providedList->isType("algorithm")) { const std::string algo = providedList->get("algorithm"); if (algo == "multijagged" || algo == "rcb") Input(currentLevel, "Coordinates"); } else Input(currentLevel, "Coordinates"); }; void Build(Level& currentLevel) const { this->GetOStream(Warnings0) << "Tpetra does not support instantiation, " "switching Zoltan2Interface to ZoltanInterface" << std::endl; // Put the data into a fake level level_->Set("A", Get >(currentLevel, "A")); level_->Set("Coordinates", Get >(currentLevel, "Coordinates")); level_->Set("number of partitions", currentLevel.Get("number of partitions")); level_->Request("Partition", zoltanInterface_.get()); zoltanInterface_->Build(*level_); RCP > decomposition; level_->Get("Partition", decomposition, zoltanInterface_.get()); Set(currentLevel, "Partition", decomposition); }; private: RCP level_; // fake Level RCP zoltanInterface_; }; #else // Stub partial specialization of Zoltan2Interface for EpetraNode template <> class Zoltan2Interface : public SingleLevelFactoryBase { public: Zoltan2Interface() { throw Exceptions::RuntimeError("Tpetra does not support instantiation"); } virtual ~Zoltan2Interface() {} RCP GetValidParameterList() const { return Teuchos::null; }; void DeclareInput(Level& level) const {}; void Build(Level& level) const {}; }; #endif // HAVE_MUELU_ZOLTAN #endif #endif // HAVE_MUELU_EPETRA } // namespace MueLu #define MUELU_ZOLTAN2INTERFACE_SHORT #endif // if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI) #endif // MUELU_ZOLTAN2INTERFACE_DECL_HPP