Zoltan2
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
52 #include <Zoltan2_TestHelpers.hpp>
53 #include <Zoltan2_Problem.hpp>
57 #include <Zoltan2_Typedefs.hpp>
58 
59 using namespace Zoltan2_TestingFramework;
60 using namespace Zoltan2;
61 
62 namespace Zoltan2_TestingFramework {
65  public:
66 
76 #ifdef HAVE_ZOLTAN2_MPI
77  static Problem<basic_id_t> * newProblem( const std::string &kind,
78  const std::string &adapter_name,
79  base_adapter_t *input,
80  ParameterList *params,
81  MPI_Comm comm)
82 #else
83  static Problem<basic_id_t> * newProblem( const std::string & kind,
84  const std::string &adapter_name,
85  base_adapter_t *input,
86  ParameterList *params)
87 #endif
88  {
89  if(kind == "partitioning") {
90 #ifdef HAVE_ZOLTAN2_MPI
91  if (adapter_name == "BasicIdentifier")
92  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params, comm));
93  else if (adapter_name == "XpetraMultiVector")
94  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<xpetra_mv_adapter>(reinterpret_cast<xpetra_mv_adapter *>(input), params, comm));
95  else if (adapter_name == "XpetraCrsGraph")
96  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<xcrsGraph_adapter>(reinterpret_cast<xcrsGraph_adapter *>(input), params, comm));
97  else if (adapter_name == "XpetraCrsMatrix")
98  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<xcrsMatrix_adapter>(reinterpret_cast<xcrsMatrix_adapter *>(input), params, comm));
99  else if (adapter_name == "BasicVector")
100  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params, comm));
101  else if (adapter_name == "PamgenMesh")
102  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<pamgen_adapter_t>(reinterpret_cast<pamgen_adapter_t*>(input), params, comm));
103 #else
104  if (adapter_name == "BasicIdentifier")
105  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params));
106  else if (adapter_name == "XpetraMultiVector")
107  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<xpetra_mv_adapter>(reinterpret_cast<xpetra_mv_adapter *>(input), params));
108  else if (adapter_name == "XpetraCrsGraph")
109  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<xcrsGraph_adapter>(reinterpret_cast<xcrsGraph_adapter *>(input), params));
110  else if (adapter_name == "XpetraCrsMatrix")
111  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<xcrsMatrix_adapter>(reinterpret_cast<xcrsMatrix_adapter *>(input), params));
112  else if (adapter_name == "BasicVector")
113  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params));
114  else if (adapter_name == "PamgenMesh")
115  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::PartitioningProblem<pamgen_adapter_t>(reinterpret_cast<pamgen_adapter_t*>(input), params));
116 #endif
117  } else if (kind == "ordering") {
118 #ifdef HAVE_ZOLTAN2_MPI
119  if (adapter_name == "BasicIdentifier")
120  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params, comm));
121  else if (adapter_name == "XpetraMultiVector")
122  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<xpetra_mv_adapter>(reinterpret_cast<xpetra_mv_adapter *>(input), params, comm));
123  else if (adapter_name == "XpetraCrsGraph")
124  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<xcrsGraph_adapter>(reinterpret_cast<xcrsGraph_adapter *>(input), params, comm));
125  else if (adapter_name == "XpetraCrsMatrix")
126  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<xcrsMatrix_adapter>(reinterpret_cast<xcrsMatrix_adapter *>(input), params, comm));
127  else if (adapter_name == "BasicVector")
128  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params, comm));
129  else if (adapter_name == "PamgenMesh")
130  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<pamgen_adapter_t>(reinterpret_cast<pamgen_adapter_t*>(input), params, comm));
131 #else
132  if (adapter_name == "BasicIdentifier")
133  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params));
134  else if (adapter_name == "XpetraMultiVector")
135  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<xpetra_mv_adapter>(reinterpret_cast<xpetra_mv_adapter *>(input), params));
136  else if (adapter_name == "XpetraCrsGraph")
137  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<xcrsGraph_adapter>(reinterpret_cast<xcrsGraph_adapter *>(input), params));
138  else if (adapter_name == "XpetraCrsMatrix")
139  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<xcrsMatrix_adapter>(reinterpret_cast<xcrsMatrix_adapter *>(input), params));
140  else if (adapter_name == "BasicVector")
141  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params));
142  else if (adapter_name == "PamgenMesh")
143  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::OrderingProblem<pamgen_adapter_t>(reinterpret_cast<pamgen_adapter_t*>(input), params));
144 #endif
145  } else if (kind == "coloring") {
146 #ifdef HAVE_ZOLTAN2_MPI
147  if (adapter_name == "BasicIdentifier")
148  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params, comm));
149  else if (adapter_name == "XpetraMultiVector")
150  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<xpetra_mv_adapter>(reinterpret_cast<xpetra_mv_adapter *>(input), params, comm));
151  else if (adapter_name == "XpetraCrsGraph")
152  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<xcrsGraph_adapter>(reinterpret_cast<xcrsGraph_adapter *>(input), params, comm));
153  else if (adapter_name == "XpetraCrsMatrix")
154  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<xcrsMatrix_adapter>(reinterpret_cast<xcrsMatrix_adapter *>(input), params, comm));
155  else if (adapter_name == "BasicVector")
156  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params, comm));
157  else if (adapter_name == "PamgenMesh")
158  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<pamgen_adapter_t>(reinterpret_cast<pamgen_adapter_t*>(input), params, comm));
159 #else
160  if (adapter_name == "BasicIdentifier")
161  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params));
162  else if (adapter_name == "XpetraMultiVector")
163  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<xpetra_mv_adapter>(reinterpret_cast<xpetra_mv_adapter *>(input), params));
164  else if (adapter_name == "XpetraCrsGraph")
165  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<xcrsGraph_adapter>(reinterpret_cast<xcrsGraph_adapter *>(input), params));
166  else if (adapter_name == "XpetraCrsMatrix")
167  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<xcrsMatrix_adapter>(reinterpret_cast<xcrsMatrix_adapter *>(input), params));
168  else if (adapter_name == "BasicVector")
169  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<basic_vector_adapter>(reinterpret_cast<basic_vector_adapter *>(input), params));
170  else if (adapter_name == "PamgenMesh")
171  return reinterpret_cast< Problem<basic_id_t> *>( new Zoltan2::ColoringProblem<pamgen_adapter_t>(reinterpret_cast<pamgen_adapter_t*>(input), params));
172 #endif
173  }
174  return nullptr; // problem type not known
175  }
176  };
177 }
178 #endif // ZOLTAN2_PROBLEM_FACTORY_HPP
179 
keep typedefs that commonly appear in many places localized
ColoringProblem sets up coloring problems for the user.
Defines the ColoringProblem class.
ProblemFactory class contains 1 static factory method.
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
static Problem< basic_id_t > * newProblem(const std::string &kind, const std::string &adapter_name, base_adapter_t *input, ParameterList *params)
Zoltan2::Problem factory method
Provides access for Zoltan2 to Xpetra::CrsGraph data.
common code used by tests
OrderingProblem sets up ordering problems for the user.
Problem base class from which other classes (PartitioningProblem, ColoringProblem, OrderingProblem, MatchingProblem, etc.) derive.
Defines the Problem base class.
BasicVectorAdapter represents a vector (plus optional weights) supplied by the user as pointers to st...
An adapter for Xpetra::MultiVector.
Defines the OrderingProblem class.
PartitioningProblem sets up partitioning problems for the user.
BaseAdapter defines methods required by all Adapters.
Defines the PartitioningProblem class.