Zoltan2
Loading...
Searching...
No Matches
Zoltan2_EvaluateFactory.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// Zoltan2: A package of combinatorial algorithms for scientific computing
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 Karen Devine (kddevin@sandia.gov)
39// Erik Boman (egboman@sandia.gov)
40// Siva Rajamanickam (srajama@sandia.gov)
41//
42// ***********************************************************************
43//
44// @HEADER
45
50#ifndef ZOLTAN2_EVALUATE_FACTORY_HPP
51#define ZOLTAN2_EVALUATE_FACTORY_HPP
52
53#include <Zoltan2_Typedefs.hpp>
58
59using namespace Zoltan2_TestingFramework;
60using namespace Zoltan2;
61
65 public:
66
75
76 EvaluateFactory(const std::string & problemName,
77 RCP<AdapterFactory> adapterFactory,
78 ParameterList *params,
79 RCP<ProblemFactory> problemFactory) {
80
81 adapterType = adapterFactory->getMainAdapterType();
82 problem_name = problemName;
83
84 if (problem_name == "partitioning") {
85 #define PARTITIONING_PROBLEM(adapterClass) rcp_dynamic_cast< \
86 PartitioningProblem<adapterClass>> (problemFactory->getProblem())
87
88 #define EVALUATE_PARTITION(adapterClass) \
89 const adapterClass * pAdapterClassUpCast = dynamic_cast< \
90 const adapterClass *>(adapterFactory->getMainAdapter()); \
91 if(!pAdapterClassUpCast) throw std::logic_error( \
92 "Bad adapter class cast!" ); \
93 evaluate = rcp(new EvaluatePartition<adapterClass>( \
94 pAdapterClassUpCast, params, \
95 problemFactory->getProblem()->getComm(), \
96 (&PARTITIONING_PROBLEM(adapterClass)->getSolution())));
97
99 }
100 else if(problem_name == "ordering") {
101 #define ORDERING_PROBLEM(adapterClass) rcp_dynamic_cast< \
102 OrderingProblem<adapterClass>> (problemFactory->getProblem())
103
104 #define LOCAL_ORDERING(adapterClass) \
105 const adapterClass * pAdapterClassUpCast = dynamic_cast< \
106 const adapterClass *>(adapterFactory->getMainAdapter()); \
107 if(!pAdapterClassUpCast) throw std::logic_error( \
108 "Bad adapter class cast!"); \
109 evaluate = rcp(new EvaluateLocalOrdering<adapterClass>( \
110 pAdapterClassUpCast, params, \
111 problemFactory->getProblem()->getComm(), \
112 ORDERING_PROBLEM(adapterClass)->getLocalOrderingSolution()));
113
114 // EvaluateGlobalOrdering not tested/implemented yet
115 #define GLOBAL_ORDERING(adapterClass) \
116 const adapterClass * pAdapterClassUpCast = dynamic_cast< \
117 const adapterClass *>(adapterFactory->getMainAdapter()); \
118 if(!pAdapterClassUpCast) throw std::logic_error( \
119 "Bad adapter class cast!" ); \
120 evaluate = rcp(new EvaluateGlobalOrdering<adapterClass>( \
121 pAdapterClassUpCast, \
122 params, ORDERING_PROBLEM(adapterClass)->getComm(), \
123 ORDERING_PROBLEM(adapterClass)->getGlobalOrderingSolution()));
124
125 Z2_TEST_UPCAST(adapterType, LOCAL_ORDERING)
126 }
127 else if(problem_name == "coloring") {
128 // Coloring code here... EvaluateColoringFactory not created yet
129 // return EvaluateColoringFactory::newEvaluatColoring(
130 // dynamic_cast<coloring_problem_t*> (problem),
131 // adapter_name, input, params);
132 }
133
134 if(evaluate == Teuchos::null) {
135 throw std::logic_error("EvaluateFactory failed to create!");
136 }
137 }
138
139 RCP<EvaluateBaseClassRoot> getEvaluateClass() { return evaluate; }
140 const std::string & getProblemName() const { return problem_name; }
141 EAdapterType getAdapterType() const { return adapterType; }
142
143 private:
144 std::string problem_name; // string converts to a problem type
145 EAdapterType adapterType; // converts to an adapter type
146 RCP<EvaluateBaseClassRoot> evaluate;
147 };
148}
149#endif // ZOLTAN2_EVALUATE_FACTORY_HPP
150
#define EVALUATE_PARTITION(adapterClass)
#define LOCAL_ORDERING(adapterClass)
Defines the Zoltan2_EvaluateOrdering.hpp class.
Defines the EvaluatePartition class.
Defines the OrderingProblem class.
keep typedefs that commonly appear in many places localized
#define Z2_TEST_UPCAST(adptr, TEMPLATE_ACTION)
ProblemFactory class contains 1 static factory method.
EvaluateFactory(const std::string &problemName, RCP< AdapterFactory > adapterFactory, ParameterList *params, RCP< ProblemFactory > problemFactory)
\brif Zoltan2::EvaluateBaseClass factory method
Created by mbenlioglu on Aug 31, 2020.