Zoltan2
Loading...
Searching...
No Matches
Zoltan2_ProblemFactory.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_PROBLEM_FACTORY_HPP
51#define ZOLTAN2_PROBLEM_FACTORY_HPP
53#include <Zoltan2_Problem.hpp>
57#include <Zoltan2_Typedefs.hpp>
58
59using namespace Zoltan2_TestingFramework;
60using namespace Zoltan2;
61
65 public:
75 ProblemFactory(const std::string & problemName,
76 RCP<AdapterFactory> adapterFactory,
77 ParameterList *params
78 #ifdef HAVE_ZOLTAN2_MPI
79 , MPI_Comm comm
80 #endif
81 ) {
82
83 problem_name = problemName;
84 adapterType = adapterFactory->getMainAdapterType();
85
86 #ifdef HAVE_ZOLTAN2_MPI
87 #define CREATE_PRBLM(problemClass, adapterClass) \
88 adapterClass * pCast = dynamic_cast<adapterClass *> \
89 (adapterFactory->getMainAdapter()); \
90 if(!pCast) { throw std::logic_error( \
91 "ProblemFactory adapter dynamic_cast failed for problem name " \
92 + problem_name + " and adapterClass " + #adapterClass ); } \
93 problem = rcp(new problemClass<adapterClass>(pCast, params, comm));
94 #else
95 #define CREATE_PRBLM(problemClass, adapterClass) \
96 adapterClass * pCast = dynamic_cast<adapterClass *> \
97 (adapterFactory->getMainAdapter()); \
98 if(!pCast) { throw std::logic_error( \
99 "ProblemFactory adapter dynamic_cast failed for problem name " \
100 + problem_name + " and adapterClass " + #adapterClass ); } \
101 problem = rcp(new problemClass<adapterClass>(pCast, params));
102 #endif
103
104 #define MAKE_PARTITION_PROBLEM(adapterClass) \
105 CREATE_PRBLM(PartitioningProblem, adapterClass);
106
107 #define MAKE_ORDERING_PROBLEM(adapterClass) \
108 CREATE_PRBLM(OrderingProblem, adapterClass);
109
110 // PartitioningProblem
111 if(problem_name == "partitioning") {
113 }
114 else if(problem_name == "ordering") {
116 }
117
118 if(problem == Teuchos::null) {
119 throw std::logic_error("ProblemFactory failed to create Problem!");
120 }
121 }
122
123 RCP<ProblemRoot> getProblem() { return problem; }
124 const std::string & getProblemName() const { return problem_name; }
125 EAdapterType getAdapterType() const { return adapterType; }
126
127 private:
128 std::string problem_name; // string converts to a problem type
129 EAdapterType adapterType; // converts to an adapter type
130 RCP<ProblemRoot> problem;
131 };
132}
133#endif // ZOLTAN2_PROBLEM_FACTORY_HPP
134
Defines the ColoringProblem class.
Defines the OrderingProblem class.
Defines the PartitioningProblem class.
#define MAKE_PARTITION_PROBLEM(adapterClass)
#define MAKE_ORDERING_PROBLEM(adapterClass)
Defines the Problem base class.
common code used by tests
keep typedefs that commonly appear in many places localized
#define Z2_TEST_UPCAST(adptr, TEMPLATE_ACTION)
ProblemFactory class contains 1 static factory method.
ProblemFactory(const std::string &problemName, RCP< AdapterFactory > adapterFactory, ParameterList *params)
\brif Zoltan2::Problem factory method
Created by mbenlioglu on Aug 31, 2020.