62 #include "Teuchos_RCP.hpp"
63 #include "Teuchos_XMLParameterListHelpers.hpp"
66 #ifdef HAVE_ZOLTAN2_PARMA
76 using Teuchos::ParameterList;
79 #ifdef HAVE_ZOLTAN2_PARMA
81 void runTest(RCP<
const Teuchos::Comm<int> >& CommT, apf::Mesh2* m,std::string action,
82 std::string parma_method,
int nParts,
double imbalance, std::string output_title );
89 int main(
int narg,
char *arg[]) {
91 Tpetra::ScopeGuard tscope(&narg, &arg);
92 Teuchos::RCP<const Teuchos::Comm<int> > CommT = Tpetra::getDefaultComm();
94 int me = CommT->getRank();
99 <<
"====================================================================\n"
101 <<
"| Example: Partition APF Mesh |\n"
103 <<
"| Questions? Contact Karen Devine (kddevin@sandia.gov), |\n"
104 <<
"| Erik Boman (egboman@sandia.gov), |\n"
105 <<
"| Siva Rajamanickam (srajama@sandia.gov). |\n"
107 <<
"| Pamgen's website: http://trilinos.sandia.gov/packages/pamgen |\n"
108 <<
"| Zoltan2's website: http://trilinos.sandia.gov/packages/zoltan2 |\n"
109 <<
"| Trilinos website: http://trilinos.sandia.gov |\n"
111 <<
"====================================================================\n";
117 std::cout <<
"PARALLEL executable \n";
121 std::cout <<
"SERIAL executable \n";
130 std::string meshFileName(
"4/");
131 std::string modelFileName(
"torus.dmg");
132 std::string action(
"zoltan_hg");
133 std::string parma_method(
"VtxElm");
134 std::string output_loc(
"");
135 int nParts = CommT->getSize();
136 double imbalance=1.1;
139 Teuchos::CommandLineProcessor cmdp (
false,
false);
140 cmdp.setOption(
"meshfile", &meshFileName,
141 "Mesh file with APF specifications (.smb file(s))");
142 cmdp.setOption(
"modelfile", &modelFileName,
143 "Model file with APF specifications (.dmg file)");
144 cmdp.setOption(
"action", &action,
145 "Method to use: mj, scotch, zoltan_rcb, parma or color");
146 cmdp.setOption(
"parma_method", &parma_method,
147 "Method to use: Vertex, Edge, Element, VtxElm, VtxEdgeElm, ElmLtVtx, Ghost, or Shape ");
148 cmdp.setOption(
"nparts", &nParts,
149 "Number of parts to create");
150 cmdp.setOption(
"imbalance", &imbalance,
151 "Target Imbalance for first partitioner");
152 cmdp.setOption(
"output", &output_loc,
153 "Location of new partitioned apf mesh. Ex: 4/torus.smb");
154 cmdp.parse(narg, arg);
168 #ifdef HAVE_ZOLTAN2_PARMA
170 if (me == 0) std::cout <<
"Generating mesh ... \n\n";
177 apf::Mesh2* m = apf::loadMdsMesh(modelFileName.c_str(),meshFileName.c_str());
179 runTest(CommT,m,action,parma_method,nParts,imbalance,
"partition");
181 runTest(CommT,m,
"parma",parma_method,nParts,imbalance,
"parma");
186 if (output_loc!=
"") {
187 m->writeNative(output_loc.c_str());
191 if (me == 0) std::cout <<
"Deleting the mesh ... \n\n";
201 std::cout <<
"PASS" << std::endl;
210 #ifdef HAVE_ZOLTAN2_PARMA
212 void runTest(RCP<
const Teuchos::Comm<int> >& CommT, apf::Mesh2* m,std::string action,
213 std::string parma_method,
int nParts,
double imbalance,std::string output_title) {
215 int me = CommT->getRank();
218 std::string primary=
"region";
219 std::string adjacency=
"face";
220 if (m->getDimension()==2) {
224 bool needSecondAdj=
false;
227 if (me == 0) std::cout <<
"Creating parameter list ... \n\n";
229 Teuchos::ParameterList params(
"test params");
230 params.set(
"timer_output_stream" ,
"std::cout");
232 if (action ==
"mj") {
233 params.set(
"debug_level",
"basic_status");
234 params.set(
"imbalance_tolerance", imbalance);
235 params.set(
"num_global_parts", nParts);
236 params.set(
"algorithm",
"multijagged");
237 params.set(
"rectilinear",
"yes");
239 else if (action ==
"scotch") {
240 params.set(
"debug_level",
"no_status");
241 params.set(
"imbalance_tolerance", imbalance);
242 params.set(
"num_global_parts", nParts);
243 params.set(
"partitioning_approach",
"partition");
244 params.set(
"algorithm",
"scotch");
247 else if (action ==
"zoltan_rcb") {
248 params.set(
"debug_level",
"verbose_detailed_status");
249 params.set(
"imbalance_tolerance", imbalance);
250 params.set(
"num_global_parts", nParts);
251 params.set(
"partitioning_approach",
"partition");
252 params.set(
"algorithm",
"zoltan");
254 else if (action ==
"parma") {
255 params.set(
"debug_level",
"no_status");
256 params.set(
"imbalance_tolerance", imbalance);
257 params.set(
"algorithm",
"parma");
258 Teuchos::ParameterList &pparams = params.sublist(
"parma_parameters",
false);
259 pparams.set(
"parma_method",parma_method);
260 pparams.set(
"step_size",1.1);
261 if (parma_method==
"Ghost") {
262 pparams.set(
"ghost_layers",3);
263 pparams.set(
"ghost_bridge",m->getDimension()-1);
267 else if (action==
"zoltan_hg") {
268 params.set(
"debug_level",
"no_status");
269 params.set(
"imbalance_tolerance", imbalance);
270 params.set(
"algorithm",
"zoltan");
271 params.set(
"num_global_parts", nParts);
272 Teuchos::ParameterList &zparams = params.sublist(
"zoltan_parameters",
false);
273 zparams.set(
"LB_METHOD",
"HYPERGRAPH");
279 Parma_PrintPtnStats(m,output_title+
"_before");
282 if (me == 0) std::cout <<
"Creating mesh adapter ... \n\n";
287 double time_1 = PCU_Time();
289 new inputAdapter_t(*CommT, m,primary,adjacency,needSecondAdj);
290 double time_2 = PCU_Time();
294 if (me == 0) std::cout <<
"Creating partitioning problem ... \n\n";
295 double time_3=PCU_Time();
299 if (me == 0) std::cout <<
"Calling the partitioner ... \n\n";
305 if (me==0) std::cout <<
"Applying Solution to Mesh\n\n";
306 apf::Mesh2** new_mesh = &m;
307 ia->applyPartitioningSolution(m,new_mesh,problem.getSolution());
309 double time_4=PCU_Time();
312 RCP<quality_t> metricObject =
313 rcp(
new quality_t(ia, ¶ms, CommT, &problem.getSolution()));
316 metricObject->printMetrics(std::cout);
320 Parma_PrintPtnStats(m,output_title+
"_after");
325 PCU_Max_Doubles(&time_2,1);
326 PCU_Max_Doubles(&time_4,1);
328 std::cout<<
"\n"<<output_title<<
"Construction time: "<<time_2<<
"\n"
329 <<output_title<<
"Problem time: " << time_4<<
"\n\n";
Defines the ColoringProblem class.
MeshAdapter defines the interface for mesh input.
int main(int narg, char *arg[])
bool runTest(Adapter &ia, const RCP< const Teuchos::Comm< int > > &comm, std::string hi)
Defines the APFMeshAdapter class.
PartitioningProblem sets up partitioning problems for the user.
Defines the PartitioningProblem class.
A class that computes and returns quality metrics.