parallel_bin_sorter.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 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" // libmesh_cast_int 00028 00029 // C++ includes 00030 #include <vector> 00031 #include <iterator> 00032 00033 namespace libMesh 00034 { 00035 00036 namespace Parallel { 00037 00038 template <typename KeyType, typename IdxType=unsigned int> 00042 class BinSorter 00043 { 00044 // The type of iterator we will be using is inferred from KeyType 00045 typedef typename std::vector<KeyType>::const_iterator IterType; 00046 00047 public: 00048 00049 // Constructor 00050 explicit 00051 BinSorter (const std::vector<KeyType>& d); 00052 00053 // The actual function which sorts the data into 00054 // nbins. Currently based on the global min and 00055 // max which you must provide e.g. by using MPI. 00056 void binsort (const IdxType nbins, 00057 KeyType max, 00058 KeyType min); 00059 00060 // Returns the size of bin b as an unsigned int. 00061 IdxType sizeof_bin (const IdxType bin) const; 00062 00063 00064 private: 00065 00066 const std::vector<KeyType>& data; 00067 std::vector<IterType> bin_iters; // Iterators to the bin boundaries 00068 // in data 00069 }; 00070 00071 00072 00073 //-------------------------------------------------------------------------- 00074 template <typename KeyType, typename IdxType> 00075 inline 00076 IdxType BinSorter<KeyType,IdxType>::sizeof_bin (const IdxType bin) const 00077 { 00078 libmesh_assert_less ((bin+1), bin_iters.size()); 00079 00080 // The size of the bin is defined by the distance between 00081 // its bounding iterators 00082 return libmesh_cast_int<IdxType> 00083 (std::distance (bin_iters[bin], bin_iters[bin+1])); 00084 } 00085 00086 } 00087 00088 } // namespace libMesh 00089 00090 #endif // LIBMESH_PARALLEL_BIN_SORTER_H 00091
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: