libMesh
include
parallel
parallel_bin_sorter.h
Go to the documentation of this file.
1
// The libMesh Finite Element Library.
2
// Copyright (C) 2002-2024 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
#ifndef LIBMESH_PARALLEL_BIN_SORTER_H
20
#define LIBMESH_PARALLEL_BIN_SORTER_H
21
22
// This class contains all the functionality for bin sorting
23
// Templated on the type of keys you will be sorting and the
24
// type of iterator you will be using.
25
26
// libMesh includes
27
#include "libmesh/libmesh_common.h"
// cast_int
28
#include "libmesh/parallel_object.h"
29
30
// C++ includes
31
#include <vector>
32
#include <iterator>
33
34
namespace
libMesh
35
{
36
37
namespace
Parallel
38
{
39
48
template
<
typename
KeyType,
typename
IdxType=
unsigned
int
>
49
class
BinSorter
:
public
ParallelObject
50
{
51
// the type of iterator we will be using is inferred from KeyType
52
typedef
typename
std::vector<KeyType>::const_iterator
IterType
;
53
54
public
:
55
56
// Constructor
57
explicit
58
BinSorter
(
const
Parallel::Communicator
&
comm
,
59
const
std::vector<KeyType> & d);
60
66
void
binsort
(
const
IdxType nbins,
67
KeyType max,
68
KeyType min);
69
73
IdxType
sizeof_bin
(
const
IdxType bin)
const
;
74
75
76
private
:
77
78
const
std::vector<KeyType> &
data
;
79
std::vector<IterType>
bin_iters
;
// Iterators to the bin boundaries
80
// in data
81
};
82
83
84
85
//--------------------------------------------------------------------------
86
template
<
typename
KeyType,
typename
IdxType>
87
inline
88
IdxType
BinSorter<KeyType,IdxType>::sizeof_bin
(
const
IdxType bin)
const
89
{
90
libmesh_assert_less ((bin+1), bin_iters.size());
91
92
// The size of the bin is defined by the distance between
93
// its bounding iterators
94
return
cast_int<IdxType>
95
(
std::distance
(bin_iters[bin], bin_iters[bin+1]));
96
}
97
98
}
99
100
}
// namespace libMesh
101
102
#endif // LIBMESH_PARALLEL_BIN_SORTER_H
libMesh::Parallel::BinSorter::bin_iters
std::vector< IterType > bin_iters
Definition:
parallel_bin_sorter.h:79
libMesh::Parallel::BinSorter::BinSorter
BinSorter(const Parallel::Communicator &comm, const std::vector< KeyType > &d)
Definition:
parallel_bin_sorter.C:38
libMesh::Parallel::BinSorter::data
const std::vector< KeyType > & data
Definition:
parallel_bin_sorter.h:78
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition:
parallel_object.h:97
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
distance
Real distance(const Point &p)
Definition:
subdomains_ex3.C:51
TIMPI::Communicator
libMesh::Parallel::BinSorter
Perform a parallel sort using a bin-sort method.
Definition:
parallel_bin_sorter.h:49
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition:
parallel_object.h:58
libMesh::Parallel::BinSorter::sizeof_bin
IdxType sizeof_bin(const IdxType bin) const
Definition:
parallel_bin_sorter.h:88
libMesh::Parallel::BinSorter::IterType
std::vector< KeyType >::const_iterator IterType
Definition:
parallel_bin_sorter.h:52
libMesh::Parallel::BinSorter::binsort
void binsort(const IdxType nbins, KeyType max, KeyType min)
The actual function which sorts the data into nbins.
Definition:
parallel_bin_sorter.C:49
Generated on Wed Apr 17 2024 11:03:45 for libMesh by
1.8.14