linear_partitioner.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // Local Includes
23 #include "libmesh/elem.h"
24 
25 namespace libMesh
26 {
27 
31  const unsigned int n)
32 {
33  const bool mesh_is_serial = mesh.is_serial();
34 
35  // Check for easy returns
36  if (it == end && mesh_is_serial)
37  return;
38 
39  if (n == 1)
40  {
41  this->single_partition_range (it, end);
42  return;
43  }
44 
45  libmesh_assert_greater (n, 0);
46 
47  // Create a simple linear partitioning
48  LOG_SCOPE ("partition_range()", "LinearPartitioner");
49 
50  // This has to be an ordered set
51  std::set<dof_id_type> element_ids;
52 
53  // If we're on a serialized mesh, we know our range is the same on
54  // every processor.
55  if (mesh_is_serial)
56  {
57  const dof_id_type blksize = cast_int<dof_id_type>
58  (std::distance(it, end) / n);
59 
60  dof_id_type e = 0;
61  for (auto & elem : as_range(it, end))
62  {
63  if ((e/blksize) < n)
64  elem->processor_id() = cast_int<processor_id_type>(e/blksize);
65  else
66  elem->processor_id() = 0;
67 
68  e++;
69  }
70  }
71  // If we're on a replicated mesh, we might have different ranges on
72  // different processors, and we'll need to gather the full range.
73  //
74  // This is not an efficient way to do this, but if you want to be
75  // efficient then you want to be using a different partitioner to
76  // begin with; LinearPartitioner is more for debugging than
77  // performance.
78  else
79  {
80  for (const auto & elem : as_range(it, end))
81  element_ids.insert(elem->id());
82 
83  mesh.comm().set_union(element_ids);
84 
85  const dof_id_type blksize = cast_int<dof_id_type>
86  (element_ids.size());
87 
88  dof_id_type e = 0;
89  for (auto eid : element_ids)
90  {
91  Elem * elem = mesh.query_elem_ptr(eid);
92  if (elem)
93  {
94  if ((e/blksize) < n)
95  elem->processor_id() = cast_int<processor_id_type>(e/blksize);
96  else
97  elem->processor_id() = 0;
98  }
99 
100  e++;
101  }
102  }
103 }
104 
105 
106 
108  const unsigned int n)
109 {
110  this->partition_range(mesh,
111  mesh.active_elements_begin(),
112  mesh.active_elements_end(),
113  n);
114 }
115 
116 } // namespace libMesh
The base class for all geometric element types.
Definition: elem.h:100
MeshBase & mesh
IterBase * end
Base class for Mesh.
Definition: mesh_base.h:77
void single_partition_range(MeshBase::element_iterator it, MeshBase::element_iterator end)
Definition: partitioner.C:172
SimpleRange< I > as_range(const std::pair< I, I > &p)
Definition: simple_range.h:57
virtual void partition_range(MeshBase &mesh, MeshBase::element_iterator it, MeshBase::element_iterator end, const unsigned int n) override
processor_id_type processor_id() const
Definition: dof_object.h:717
uint8_t dof_id_type
Definition: id_types.h:64
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override