$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 #ifndef LIBMESH_PARALLEL_BIN_SORTER_H 00020 #define LIBMESH_PARALLEL_BIN_SORTER_H 00021 00022 // This class contains all the functionality for bin sorting 00023 // Templated on the type of keys you will be sorting and the 00024 // type of iterator you will be using. 00025 00026 // libMesh includes 00027 #include "libmesh/libmesh_common.h" // cast_int 00028 #include "libmesh/parallel_object.h" 00029 00030 // C++ includes 00031 #include <vector> 00032 #include <iterator> 00033 00034 namespace libMesh 00035 { 00036 00037 namespace Parallel { 00038 00039 template <typename KeyType, typename IdxType=unsigned int> 00043 class BinSorter : public ParallelObject 00044 { 00045 // the type of iterator we will be using is inferred from KeyType 00046 typedef typename std::vector<KeyType>::const_iterator IterType; 00047 00048 public: 00049 00050 // Constructor 00051 explicit 00052 BinSorter (const Parallel::Communicator &comm, 00053 const std::vector<KeyType>& d); 00054 00055 // The actual function which sorts the data into 00056 // nbins. Currently based on the global min and 00057 // max which you must provide e.g. by using MPI. 00058 void binsort (const IdxType nbins, 00059 KeyType max, 00060 KeyType min); 00061 00062 // Returns the size of bin b as an unsigned int. 00063 IdxType sizeof_bin (const IdxType bin) const; 00064 00065 00066 private: 00067 00068 const std::vector<KeyType>& data; 00069 std::vector<IterType> bin_iters; // Iterators to the bin boundaries 00070 // in data 00071 }; 00072 00073 00074 00075 //-------------------------------------------------------------------------- 00076 template <typename KeyType, typename IdxType> 00077 inline 00078 IdxType BinSorter<KeyType,IdxType>::sizeof_bin (const IdxType bin) const 00079 { 00080 libmesh_assert_less ((bin+1), bin_iters.size()); 00081 00082 // The size of the bin is defined by the distance between 00083 // its bounding iterators 00084 return cast_int<IdxType> 00085 (std::distance (bin_iters[bin], bin_iters[bin+1])); 00086 } 00087 00088 } 00089 00090 } // namespace libMesh 00091 00092 #endif // LIBMESH_PARALLEL_BIN_SORTER_H