libMesh
include
parallel
parallel_histogram.h
Go to the documentation of this file.
1
// The libMesh Finite Element Library.
2
// Copyright (C) 2002-2019 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_HISTOGRAM_H
20
#define LIBMESH_PARALLEL_HISTOGRAM_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
27
// C++ includes
28
#include "libmesh/libmesh_common.h"
// for libmesh_assert()
29
#include "libmesh/parallel_object.h"
30
31
// Local includes
32
#include <vector>
33
#include <iterator>
34
35
namespace
libMesh
36
{
37
38
namespace
Parallel
39
{
40
50
template
<
typename
KeyType,
typename
IdxType=
unsigned
int
>
51
class
Histogram
:
public
ParallelObject
52
{
53
// The type of iterator we will be using is inferred from KeyType
54
typedef
typename
std::vector<KeyType>::const_iterator
IterType
;
55
56
public
:
57
61
explicit
62
Histogram
(
const
Parallel::Communicator &
comm
,
63
const
std::vector<KeyType> & d);
64
70
void
make_histogram
(
const
IdxType nbins,
71
KeyType max,
72
KeyType min);
73
78
void
build_histogram
();
79
83
const
std::vector<IdxType> &
get_histogram
()
const
;
84
88
IdxType
n_bins
()
const
;
89
93
IdxType
local_bin_size
(
const
IdxType bin)
const
;
94
100
IdxType
global_bin_size
(
const
IdxType bin)
const
;
101
105
double
lower_bound
(
const
IdxType bin)
const
;
106
110
double
upper_bound
(
const
IdxType bin)
const
;
111
112
113
private
:
114
115
const
std::vector<KeyType> &
data
;
116
std::vector<IdxType>
hist
;
// The actual histogram
117
std::vector<double>
bin_bounds
;
// The boundary values of each bin
118
std::vector<IterType>
bin_iters
;
// Iterators to the bin boundaries in data
119
};
120
121
122
123
template
<
typename
KeyType,
typename
IdxType>
124
inline
125
const
std::vector<IdxType> &
Histogram<KeyType,IdxType>::get_histogram
()
const
126
{
127
return
hist;
128
}
129
130
131
132
template
<
typename
KeyType,
typename
IdxType>
133
inline
134
IdxType
Histogram<KeyType,IdxType>::n_bins
()
const
135
{
136
if
(bin_iters.empty())
137
return
0;
138
139
return
cast_int<IdxType>(bin_iters.size()-1);
140
}
141
142
143
144
template
<
typename
KeyType,
typename
IdxType>
145
inline
146
IdxType
Histogram<KeyType,IdxType>::local_bin_size
(
const
IdxType bin)
const
147
{
148
libmesh_assert_less ((bin+1), bin_iters.size());
149
150
// The number of entries in the bin (locally)
151
return
cast_int<IdxType>
152
(
std::distance
(bin_iters[bin], bin_iters[bin+1]));
153
}
154
155
156
157
template
<
typename
KeyType,
typename
IdxType>
158
inline
159
IdxType
Histogram<KeyType,IdxType>::global_bin_size
(
const
IdxType bin)
const
160
{
161
libmesh_assert_less (bin, hist.size());
162
163
// The number of entries in the bin (globally)
164
return
hist[bin];
165
}
166
167
168
169
template
<
typename
KeyType,
typename
IdxType>
170
inline
171
double
Histogram<KeyType,IdxType>::lower_bound
(
const
IdxType bin)
const
172
{
173
libmesh_assert_less ((bin+1), bin_bounds.size());
174
175
return
bin_bounds[bin];
176
}
177
178
179
180
template
<
typename
KeyType,
typename
IdxType>
181
inline
182
double
Histogram<KeyType,IdxType>::upper_bound
(
const
IdxType bin)
const
183
{
184
libmesh_assert_less ((bin+1), bin_bounds.size());
185
186
return
bin_bounds[bin+1];
187
}
188
189
}
190
191
}
// namespace libMesh
192
193
#endif // LIBMESH_PARALLEL_HISTOGRAM_H
libMesh::Parallel::Histogram::bin_iters
std::vector< IterType > bin_iters
Definition:
parallel_histogram.h:118
libMesh::Parallel::Histogram::global_bin_size
IdxType global_bin_size(const IdxType bin) const
Definition:
parallel_histogram.h:159
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition:
factoryfunction.C:55
libMesh::Parallel::Histogram::Histogram
Histogram(const Parallel::Communicator &comm, const std::vector< KeyType > &d)
Constructor.
Definition:
parallel_histogram.C:35
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition:
parallel_object.h:94
libMesh::Parallel::Histogram::IterType
std::vector< KeyType >::const_iterator IterType
Definition:
parallel_histogram.h:54
libMesh::Parallel::Histogram::n_bins
IdxType n_bins() const
The number of bins in the histogram.
Definition:
parallel_histogram.h:134
libMesh::Parallel::Histogram
Defines a histogram to be used in parallel in conjunction with a BinSorter.
Definition:
parallel_histogram.h:51
libMesh::Parallel::Histogram::local_bin_size
IdxType local_bin_size(const IdxType bin) const
Definition:
parallel_histogram.h:146
libMesh::Parallel::Histogram::upper_bound
double upper_bound(const IdxType bin) const
Definition:
parallel_histogram.h:182
distance
Real distance(const Point &p)
Definition:
subdomains_ex3.C:50
libMesh::Parallel::Histogram::bin_bounds
std::vector< double > bin_bounds
Definition:
parallel_histogram.h:117
libMesh::Parallel::Histogram::make_histogram
void make_histogram(const IdxType nbins, KeyType max, KeyType min)
The actual function which sorts the data into nbins.
Definition:
parallel_histogram.C:46
libMesh::Parallel::Histogram::get_histogram
const std::vector< IdxType > & get_histogram() const
Definition:
parallel_histogram.h:125
libMesh::Parallel::Histogram::hist
std::vector< IdxType > hist
Definition:
parallel_histogram.h:116
libMesh::Parallel::Histogram::lower_bound
double lower_bound(const IdxType bin) const
Definition:
parallel_histogram.h:171
libMesh::Parallel::Histogram::data
const std::vector< KeyType > & data
Definition:
parallel_histogram.h:115
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition:
parallel_object.h:55
libMesh::Parallel::Histogram::build_histogram
void build_histogram()
Build the histogram across all processors and store the result in the input vector hist.
Definition:
parallel_histogram.C:91
Generated on Sat Jan 25 2020 12:06:54 for libMesh by
1.8.16