$extrastylesheet
parallel_hilbert.h
Go to the documentation of this file.
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_HILBERT_H
00020 #define LIBMESH_PARALLEL_HILBERT_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 #include "libmesh/libmesh_config.h"
00027 
00028 #if defined(LIBMESH_HAVE_LIBHILBERT) && defined(LIBMESH_HAVE_MPI)
00029 
00030 // Local includes
00031 #include "hilbert.h"
00032 #include "libmesh/parallel.h"
00033 
00034 // C++ includes
00035 #include <cstddef>
00036 
00037 namespace libMesh {
00038 namespace Parallel {
00039 // A StandardType<> specialization to return a derived MPI datatype
00040 // to handle communication of HilbertIndices.  We use a singleton
00041 // pattern here because a global variable would have tried to call
00042 // MPI functions before MPI got initialized.
00043 template <>
00044 class StandardType<Hilbert::HilbertIndices> : public DataType
00045 {
00046 public:
00047   explicit
00048   StandardType(const Hilbert::HilbertIndices* =NULL) {
00049     // _static_type never gets freed, but it only gets committed once
00050     // so it's not a *huge* memory leak...
00051     static DataType _static_type;
00052     static bool _is_initialized = false;
00053     if (!_is_initialized)
00054       {
00055         _static_type = DataType(Parallel::StandardType<Hilbert::inttype>(), 3);
00056         _is_initialized = true;
00057       }
00058     _datatype = _static_type;
00059   }
00060 };
00061 } // namespace Parallel
00062 } // namespace libMesh
00063 
00064 #endif // LIBMESH_HAVE_LIBHILBERT && LIBMESH_HAVE_MPI
00065 
00066 #endif // LIBMESH_PARALLEL_HILBERT_H