parallel_bin_sorter.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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" // libmesh_cast_int
29 
30 // C++ includes
31 #include <vector>
32 #include <iterator>
33 
34 namespace libMesh
35 {
36 
37 namespace Parallel {
38 
39 template <typename KeyType, typename IdxType=unsigned int>
43 class BinSorter : public ParallelObject
44 {
45  // the type of iterator we will be using is inferred from KeyType
46  typedef typename std::vector<KeyType>::const_iterator IterType;
47 
48 public:
49 
50  // Constructor
51  explicit
53  const std::vector<KeyType>& d);
54 
55  // The actual function which sorts the data into
56  // nbins. Currently based on the global min and
57  // max which you must provide e.g. by using MPI.
58  void binsort (const IdxType nbins,
59  KeyType max,
60  KeyType min);
61 
62  // Returns the size of bin b as an unsigned int.
63  IdxType sizeof_bin (const IdxType bin) const;
64 
65 
66 private:
67 
68  const std::vector<KeyType>& data;
69  std::vector<IterType> bin_iters; // Iterators to the bin boundaries
70  // in data
71 };
72 
73 
74 
75 //--------------------------------------------------------------------------
76 template <typename KeyType, typename IdxType>
77 inline
78 IdxType BinSorter<KeyType,IdxType>::sizeof_bin (const IdxType bin) const
79 {
80  libmesh_assert_less ((bin+1), bin_iters.size());
81 
82  // The size of the bin is defined by the distance between
83  // its bounding iterators
84  return libmesh_cast_int<IdxType>
85  (std::distance (bin_iters[bin], bin_iters[bin+1]));
86 }
87 
88 }
89 
90 } // namespace libMesh
91 
92 #endif // LIBMESH_PARALLEL_BIN_SORTER_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo