Skip to content

Commit 5a1f67d

Browse files
authored
Merge pull request #3431 from lindsayad/reduce-setup-time-for-fv
Exploring how to reduce setup time for large-element-stencil simulations
2 parents cb01ac8 + de7fc43 commit 5a1f67d

4 files changed

Lines changed: 29 additions & 34 deletions

File tree

include/base/dof_object.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,23 @@ struct CompareDofObjectsByID
13801380
}
13811381
};
13821382

1383+
struct CompareDofObjectsByPIDAndThenID
1384+
{
1385+
bool operator()(const DofObject * a,
1386+
const DofObject * b) const
1387+
{
1388+
libmesh_assert (a);
1389+
libmesh_assert (b);
1390+
1391+
if (a->processor_id() < b->processor_id())
1392+
return true;
1393+
if (b->processor_id() < a->processor_id())
1394+
return false;
1395+
1396+
return a->id() < b->id();
1397+
}
1398+
};
1399+
13831400
} // namespace libMesh
13841401

13851402

include/base/ghosting_functor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "libmesh/id_types.h"
2626
#include "libmesh/mesh_base.h"
2727
#include "libmesh/reference_counted_object.h"
28+
#include "libmesh/dof_object.h"
2829

2930
// C++ Includes
3031
#include <unordered_map>
@@ -228,7 +229,7 @@ class GhostingFunctor : public ReferenceCountedObject<GhostingFunctor>
228229
* What elements do we care about and what variables do we care
229230
* about on each element?
230231
*/
231-
typedef std::unordered_map<const Elem*, const CouplingMatrix*> map_type;
232+
typedef std::map<const Elem*, const CouplingMatrix*, CompareDofObjectsByPIDAndThenID> map_type;
232233

233234
/**
234235
* For the specified range of active elements, what other elements

include/base/sparsity_pattern.h

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -249,38 +249,15 @@ void SparsityPattern::sort_row (const BidirectionalIterator begin,
249249
BidirectionalIterator middle,
250250
const BidirectionalIterator end)
251251
{
252-
if ((begin == middle) || (middle == end)) return;
253-
254-
libmesh_assert_greater (std::distance (begin, middle), 0);
255-
libmesh_assert_greater (std::distance (middle, end), 0);
256-
libmesh_assert (std::unique (begin, middle) == middle);
257-
libmesh_assert (std::unique (middle, end) == end);
258-
259-
while (middle != end)
260-
{
261-
BidirectionalIterator
262-
b = middle,
263-
a = b-1;
264-
265-
// Bubble-sort the middle value downward
266-
while (!(*a < *b)) // *a & *b are less-than comparable, so use <
267-
{
268-
std::swap (*a, *b);
269-
270-
#if defined(__GNUC__) && (__GNUC__ < 4) && !defined(__INTEL_COMPILER)
271-
/* Prohibit optimization at this point since gcc 3.3.5 seems
272-
to have a bug. */
273-
SparsityPattern::_dummy_function();
252+
// Assure we have the conditions for an inplace_merge
253+
#ifdef DEBUG
254+
libmesh_assert(std::is_sorted(begin, middle));
255+
libmesh_assert(std::is_sorted(middle, end));
274256
#endif
257+
libmesh_assert(std::unique(begin, middle) == middle);
258+
libmesh_assert(std::unique(middle, end) == end);
275259

276-
if (a == begin) break;
277-
278-
b=a;
279-
--a;
280-
}
281-
282-
++middle;
283-
}
260+
std::inplace_merge(begin, middle, end);
284261

285262
// Assure the algorithm worked if we are in DEBUG mode
286263
#ifdef DEBUG

tests/base/overlapping_coupling_test.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class OverlappingCouplingFunctor : public GhostingFunctor
6767
(const MeshBase::const_element_iterator & range_begin,
6868
const MeshBase::const_element_iterator & range_end,
6969
processor_id_type p,
70-
std::unordered_map<const Elem *,const CouplingMatrix*> & coupled_elements) override
70+
map_type & coupled_elements) override
7171
{
7272
std::unique_ptr<PointLocatorBase> sub_point_locator = _mesh.sub_point_locator();
7373

@@ -430,8 +430,8 @@ private:
430430

431431
OverlappingCouplingFunctor coupling_functor(system);
432432

433-
std::unordered_map<const Elem *,const CouplingMatrix*> subdomain_one_couplings;
434-
std::unordered_map<const Elem *,const CouplingMatrix*> subdomain_two_couplings;
433+
GhostingFunctor::map_type subdomain_one_couplings;
434+
GhostingFunctor::map_type subdomain_two_couplings;
435435

436436
coupling_functor( _mesh->active_subdomain_elements_begin(1),
437437
_mesh->active_subdomain_elements_end(1),

0 commit comments

Comments
 (0)