COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-zoltan.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for zoltan load balancing library"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/Log.hpp"
13 #include "common/OptionList.hpp"
14 #include "common/PropertyList.hpp"
15 #include "common/Core.hpp"
16 #include "common/Environment.hpp"
17 #include "common/Foreach.hpp"
18 #include "common/OSystem.hpp"
19 #include "common/OSystemLayer.hpp"
20 
21 #include "common/PE/Comm.hpp"
22 #include "common/PE/debug.hpp"
23 
24 #include "mesh/Mesh.hpp"
25 #include "mesh/Dictionary.hpp"
26 #include "mesh/Field.hpp"
27 #include "mesh/Region.hpp"
28 #include "mesh/MeshReader.hpp"
29 #include "mesh/MeshWriter.hpp"
30 #include "mesh/MeshGenerator.hpp"
31 #include "mesh/MeshPartitioner.hpp"
32 #include "mesh/MeshTransformer.hpp"
33 
34 using namespace boost;
35 using namespace cf3;
36 using namespace cf3::mesh;
37 using namespace cf3::common;
38 using namespace cf3::common::PE;
39 
41 
43 {
46  {
47  // uncomment if you want to use arguments to the test executable
48  m_argc = boost::unit_test::framework::master_test_suite().argc;
49  m_argv = boost::unit_test::framework::master_test_suite().argv;
50 
51  }
52 
55  {
56 
57  }
58 
60 
61  int m_argc;
62  char** m_argv;
63 };
64 
65 
67 
68 BOOST_FIXTURE_TEST_SUITE( ZoltanTests_TestSuite, ZoltanTests_Fixture )
69 
70 
73 {
74  Core::instance().initiate(m_argc,m_argv);
75  PE::Comm::instance().init(m_argc,m_argv);
76 
77 }
78 
79 
80 
82 {
83 
85  for (Uint pid=0; pid<PE::Comm::instance().size(); ++pid)
86  {
87  const unsigned int procup = (PE::Comm::instance().rank() + pid) %
88  PE::Comm::instance().size();
89  const unsigned int procdown = (PE::Comm::instance().size() +
90  PE::Comm::instance().rank() - pid) %
91  PE::Comm::instance().size();
92 
93  std::cout << PERank << procup << " / " << procdown << std::endl;
94  }
95  )
96 }
98 /*
99 BOOST_AUTO_TEST_CASE( MeshPartitioner_test_quadtriag )
100 {
101  Core::instance().environment().options().set("log_level",(Uint)DEBUG);
102  CFinfo << "MeshPartitioner_test" << CFendl;
103  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
104  meshreader->options().set("read_boundaries",false);
105 
106  // the file to read from
107  URI fp_in ("../../resources/quadtriag.neu");
108 
109  // the mesh to store in
110  Handle< Mesh > mesh_ptr = meshreader->create_mesh_from(fp_in);
111  Mesh& mesh = *mesh_ptr;
112 
113  boost::shared_ptr< MeshTransformer > glb_numbering = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.GlobalNumbering","glb_numbering");
114  glb_numbering->transform(mesh_ptr);
115  boost::shared_ptr< MeshTransformer > glb_connectivity = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.GlobalConnectivity","glb_connectivity");
116  glb_connectivity->transform(mesh_ptr);
117 
118  boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
119  URI fp_out_1 ("quadtriag.msh");
120  meshwriter->write_from_to(*mesh_ptr,fp_out_1);
121 
122  boost::shared_ptr< MeshPartitioner > partitioner_ptr = build_component_abstract_type<MeshTransformer>("cf3.mesh.zoltan.Partitioner","partitioner")->as_ptr<MeshPartitioner>();
123 
124  MeshPartitioner& p = *partitioner_ptr;
125  BOOST_CHECK_EQUAL(p.name(),"partitioner");
126 
127  Core::instance().initiate(m_argc,m_argv);
128 
129  //p.options().set("nb_parts", (Uint) 4);
130  p.options().set("graph_package", std::string("PHG"));
131  p.options().set("debug_level", 2u);
132  BOOST_CHECK(true);
133  p.initialize(mesh);
134 
135  BOOST_CHECK_EQUAL(p.proc_of_obj(0), 0u);
136  BOOST_CHECK_EQUAL(p.proc_of_obj(7), 0u);
137  BOOST_CHECK_EQUAL(p.proc_of_obj(8), 0u);
138  BOOST_CHECK_EQUAL(p.proc_of_obj(15), 0u);
139  BOOST_CHECK_EQUAL(p.proc_of_obj(16), 1u);
140  BOOST_CHECK_EQUAL(p.proc_of_obj(23), 1u);
141  BOOST_CHECK_EQUAL(p.proc_of_obj(24), 1u);
142  BOOST_CHECK_EQUAL(p.proc_of_obj(31), 1u);
143 
144  BOOST_CHECK_EQUAL(p.is_node(0), true);
145  BOOST_CHECK_EQUAL(p.is_node(7), true);
146  BOOST_CHECK_EQUAL(p.is_node(8), false);
147  BOOST_CHECK_EQUAL(p.is_node(15), false);
148  BOOST_CHECK_EQUAL(p.is_node(16), true);
149  BOOST_CHECK_EQUAL(p.is_node(23), true);
150  BOOST_CHECK_EQUAL(p.is_node(24), false);
151  BOOST_CHECK_EQUAL(p.is_node(31), false);
152 
153  Uint comp_idx;
154  Handle< Component > comp;
155  Uint idx;
156  bool found;
157  if ( PE::Comm::instance().rank() == 0)
158  {
159  boost::tie(comp,idx) = p.to_local(0);
160  boost::tie(comp_idx,idx,found) = p.to_local_indices_from_glb_obj(0);
161  BOOST_CHECK( is_not_null(comp->as_ptr<Dictionary>()) );
162  BOOST_CHECK_EQUAL(comp_idx, 0);
163  BOOST_CHECK_EQUAL(idx, 0);
164  BOOST_CHECK_EQUAL(found, true);
165 
166  boost::tie(comp_idx,idx,found) = p.to_local_indices_from_glb_obj(7);
167  BOOST_CHECK_EQUAL(comp_idx, 0);
168  BOOST_CHECK_EQUAL(idx, 7);
169  BOOST_CHECK_EQUAL(found, true);
170 
171  }
172 
173  BOOST_CHECK(true);
174  p.partition_graph();
175  BOOST_CHECK(true);
176  p.show_changes();
177  BOOST_CHECK(true);
178  p.migrate();
179  BOOST_CHECK(true);
180 
181  boost::shared_ptr< MeshTransformer > glb_node_numbering = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.GlobalNumberingNodes","glb_node_numbering");
182  glb_node_numbering->options().set("debug",true);
183  glb_node_numbering->transform(mesh);
184 
185 
186  PEProcessSortedExecute(-1,
187  std::cout << "rank = " << Comm::instance().rank() << std::endl;
188  std::cout << "nodes = " << mesh.geometry_fields().glb_idx() << std::endl;
189  std::cout << "ranks = " << mesh.geometry_fields().rank() << std::endl;
190  boost_foreach(const Entities& entities, mesh.topology().elements_range())
191  {
192  //std::cout << "elems = " << entities.glb_idx() << std::endl;
193  }
194 
195  )
196 
197  URI fp_out_2 ("quadtriag_repartitioned.msh");
198  meshwriter->write_from_to(*mesh_ptr,fp_out_2);
199 }
200 */
201 BOOST_AUTO_TEST_CASE( MeshPartitioner_test_quadtriag )
202 {
203  Core::instance().environment().options().set("log_level",(Uint)DEBUG);
204  boost::shared_ptr< MeshGenerator > meshgenerator = build_component_abstract_type<MeshGenerator>("cf3.mesh.SimpleMeshGenerator","1Dgenerator");
205 
206  meshgenerator->options().set("mesh",URI("//rect"));
207  std::vector<Uint> nb_cells(2); nb_cells[0] = 3; nb_cells[1] = 2;
208  std::vector<Real> lengths(2); lengths[0] = nb_cells[0]; lengths[1] = nb_cells[1];
209  meshgenerator->options().set("nb_cells",nb_cells);
210  meshgenerator->options().set("lengths",lengths);
211  meshgenerator->options().set("bdry",false);
212  Mesh& mesh = meshgenerator->generate();
213 
214 
215  boost::shared_ptr< MeshTransformer > glb_numbering = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.GlobalNumbering","glb_numbering");
216  glb_numbering->transform(mesh);
217  boost::shared_ptr< MeshTransformer > glb_connectivity = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.GlobalConnectivity","glb_connectivity");
218  glb_connectivity->transform(mesh);
219 
220  boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
221  meshwriter->write_from_to(mesh,"rect.msh");
222 
223  boost::shared_ptr< MeshPartitioner > partitioner_ptr = boost::dynamic_pointer_cast<MeshPartitioner>(build_component_abstract_type<MeshTransformer>("cf3.mesh.zoltan.Partitioner","partitioner"));
224 
225  MeshPartitioner& p = *partitioner_ptr;
226  BOOST_CHECK_EQUAL(p.name(),"partitioner");
227 
228  Core::instance().initiate(m_argc,m_argv);
229 
230  //p.options().set("nb_parts", (Uint) 4);
231  p.options().set("graph_package", std::string("PHG"));
232  p.options().set("debug_level", 2u);
233  BOOST_CHECK(true);
234  p.initialize(mesh);
235  BOOST_CHECK(true);
236  p.partition_graph();
237  BOOST_CHECK(true);
238  p.show_changes();
239  BOOST_CHECK(true);
240  p.migrate();
241  BOOST_CHECK(true);
242 
243  boost::shared_ptr< MeshTransformer > glb_node_numbering = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.GlobalNumberingNodes","glb_node_numbering");
244  glb_node_numbering->options().set("debug",true);
245  glb_node_numbering->transform(mesh);
246 
247 
249  std::cout << PERank << "nodes = " << mesh.geometry_fields().coordinates() << std::endl;
250  std::cout << PERank << "ranks = " << mesh.geometry_fields().rank() << std::endl;
251  boost_foreach(const Entities& entities, mesh.topology().elements_range())
252  {
253  //std::cout << "elems = " << entities.glb_idx() << std::endl;
254  }
255 
256  )
257 
258 
259  boost::shared_ptr< MeshWriter > tecwriter = build_component_abstract_type<MeshWriter>("cf3.mesh.tecplot.Writer","meshwriter");
260  tecwriter->write_from_to(mesh,"rect_repartitioned.plt");
261  meshwriter->write_from_to(mesh,"rect_repartitioned.msh");
262 
263  CFinfo << "zoltan version:" << p.properties().value<Real>("Zoltan_version") << CFendl;
264 
265 }
266 
268 
269 BOOST_AUTO_TEST_CASE( finalize_mpi )
270 {
271  PE::Comm::instance().finalize();
272 
273  Core::instance().terminate();
274 }
275 
277 
278 BOOST_AUTO_TEST_SUITE_END()
279 
280 
#define CFinfo
these are always defined
Definition: Log.hpp:104
virtual void partition_graph()=0
external boost library namespace
ConstElementsRange elements_range() const
Definition: Region.cpp:142
common::List< Uint > & rank()
Return the rank of every field row.
Definition: Dictionary.hpp:90
#define boost_foreach
lowercase version of BOOST_FOREACH
Definition: Foreach.hpp:16
const std::string & name() const
Access the name of the component.
Definition: Component.hpp:146
const Field & coordinates() const
Definition: Dictionary.cpp:481
BOOST_AUTO_TEST_CASE(init_mpi)
#define CFendl
Definition: Log.hpp:109
int m_argc
possibly common functions used on the tests below
~ZoltanTests_Fixture()
common tear-down for each test case
ZoltanTests_Fixture()
common setup for each test case
PropertyList & properties()
Definition: Component.cpp:842
Basic Classes for Mesh applications used by COOLFluiD.
TYPE value(const std::string &pname) const
Top-level namespace for coolfluid.
Definition: Action.cpp:18
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
void migrate()
Migrate the elements and nodes to corresponding processors.
Classes offering a MPI interface for COOLFluiD.
Definition: all_gather.hpp:39
Region & topology() const
Definition: Mesh.hpp:51
OptionList & options()
Definition: Component.cpp:856
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
#define PERank
Definition: debug.hpp:36
void set(const std::string &pname, const boost::any &val)
Definition: OptionList.cpp:132
Most basic kernel library.
Definition: Action.cpp:19
#define PEProcessSortedExecute(irank, expression)
Definition: debug.hpp:43
Send comments to:
COOLFluiD Web Admin