MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_MatrixFreeTentativePFactory_kokkos_def.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// MueLu: A package for multigrid based preconditioning
6// Copyright 2012 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact
39// Jonathan Hu (jhu@sandia.gov)
40// Andrey Prokopenko (aprokop@sandia.gov)
41// Ray Tuminaro (rstumin@sandia.gov)
42//
43// ***********************************************************************
44//
45// @HEADER
46#ifndef MUELU_MATRIXFREETENTATIVEPFACTORY_KOKKOS_DEF_HPP
47#define MUELU_MATRIXFREETENTATIVEPFACTORY_KOKKOS_DEF_HPP
48
49#include "Kokkos_UnorderedMap.hpp"
50
52
53#include "MueLu_Aggregates_kokkos.hpp"
54#include "MueLu_AmalgamationFactory_kokkos.hpp"
55#include "MueLu_AmalgamationInfo_kokkos.hpp"
56#include "MueLu_CoarseMapFactory_kokkos.hpp"
57#include "MueLu_MasterList.hpp"
58#include "MueLu_NullspaceFactory_kokkos.hpp"
59#include "MueLu_PerfUtils.hpp"
60#include "MueLu_Monitor.hpp"
61#include "MueLu_MatrixFreeTentativeP_kokkos.hpp"
62#include "MueLu_Utilities_kokkos.hpp"
63
64namespace MueLu {
65
66 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class DeviceType>
68 RCP<ParameterList> validParamList = rcp(new ParameterList());
69
70 validParamList->set< RCP<const FactoryBase> >("A", Teuchos::null, "Generating factory of the matrix A");
71 validParamList->set< RCP<const FactoryBase> >("Aggregates", Teuchos::null, "Generating factory of the aggregates");
72 validParamList->set< RCP<const FactoryBase> >("Nullspace", Teuchos::null, "Generating factory of the nullspace");
73 validParamList->set< RCP<const FactoryBase> >("Scaled Nullspace", Teuchos::null, "Generating factory of the scaled nullspace");
74 validParamList->set< RCP<const FactoryBase> >("UnAmalgamationInfo", Teuchos::null, "Generating factory of UnAmalgamationInfo");
75 validParamList->set< RCP<const FactoryBase> >("CoarseMap", Teuchos::null, "Generating factory of the coarse map");
76 validParamList->set< RCP<const FactoryBase> >("Coordinates", Teuchos::null, "Generating factory of the coordinates");
77
78 // Make sure we don't recursively validate options for the matrixmatrix kernels
79 ParameterList norecurse;
80 norecurse.disableRecursiveValidation();
81 validParamList->set<ParameterList> ("matrixmatrix: kernel params", norecurse, "MatrixMatrix kernel parameters");
82
83 return validParamList;
84 }
85
86 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class DeviceType>
88
89 const ParameterList& pL = GetParameterList();
90 // NOTE: This guy can only either be 'Nullspace' or 'Scaled Nullspace' or else the validator above will cause issues
91 std::string nspName = "Nullspace";
92 if(pL.isParameter("Nullspace name")) nspName = pL.get<std::string>("Nullspace name");
93
94 Input(fineLevel, "Aggregates");
95 Input(fineLevel, nspName);
96 Input(fineLevel, "UnAmalgamationInfo");
97 Input(fineLevel, "CoarseMap");
98 }
99
100 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class DeviceType>
102 return BuildP(fineLevel, coarseLevel);
103 }
104
105 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class DeviceType>
107 FactoryMonitor m(*this, "Build", coarseLevel);
108
109 const ParameterList& pL = GetParameterList();
110 std::string nspName = "Nullspace";
111 if(pL.isParameter("Nullspace name")) nspName = pL.get<std::string>("Nullspace name");
112
113 auto aggregates = Get< RCP<Aggregates_kokkos> > (fineLevel, "Aggregates");
114 auto amalgInfo = Get< RCP<AmalgamationInfo_kokkos> > (fineLevel, "UnAmalgamationInfo");
115 auto fineNullspace = Get< RCP<MultiVector> > (fineLevel, nspName);
116 auto coarseMap = Get< RCP<const Map> > (fineLevel, "CoarseMap");
117 Teuchos::RCP<const Map> fineMap = fineNullspace->getMap();
118
119 // Matrix-free should never run with aggregates that cross processors
120 if (aggregates->AggregatesCrossProcessors())
121 TEUCHOS_TEST_FOR_EXCEPTION(true,Exceptions::RuntimeError,"MatrixFreeTentativePFactory does not support aggregates that cross processors!");
122
123 size_t NSDim = fineNullspace->getNumVectors();
124 RCP<MultiVector> coarseNullspace = MultiVectorFactory::Build(coarseMap, NSDim);
125
126 Teuchos::RCP<Operator> P = Teuchos::rcp(new MatrixFreeTentativeP_kokkos<Scalar,LocalOrdinal,GlobalOrdinal,Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>>(coarseMap, fineMap, aggregates));
127 P->apply(*fineNullspace,*coarseNullspace,Teuchos::TRANS,1.0,0.0); // coarse = alpha*R*fine + beta*coarse
128
129 Set(coarseLevel, "Nullspace", coarseNullspace);
130 Set(coarseLevel, "P", P);
131 }
132
133} //namespace MueLu
134
135#define MUELU_MATRIXFREETENTATIVEPFACTORY_KOKKOS_SHORT
136#endif // MUELU_MATRIXFREETENTATIVEPFACTORY_KOKKOS_DEF_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
Namespace for MueLu classes and methods.