libMesh
parallel_hilbert.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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_HILBERT_H
20 #define LIBMESH_PARALLEL_HILBERT_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 #include "libmesh/libmesh_config.h"
27 
28 #if defined(LIBMESH_HAVE_LIBHILBERT)
29 
30 // Local includes
31 // So many implicit-fallthrough warnings in crazy libHilbert macros...
32 #include "libmesh/ignore_warnings.h"
33 #include "hilbert.h"
34 #include "libmesh/restore_warnings.h"
35 #include "libmesh/parallel.h"
36 
37 // C++ includes
38 #include <cstddef>
39 
40 namespace libMesh {
41 namespace Parallel {
42 
43 #ifdef LIBMESH_HAVE_MPI
44 // A StandardType<> specialization to return a derived MPI datatype
45 // to handle communication of HilbertIndices. We use a singleton
46 // pattern here because a global variable would have tried to call
47 // MPI functions before MPI got initialized.
48 template <>
49 class StandardType<Hilbert::HilbertIndices> : public DataType
50 {
51 public:
52  explicit
53  StandardType(const Hilbert::HilbertIndices * =libmesh_nullptr) {
54  // _static_type never gets freed, but it only gets committed once
55  // so it's not a *huge* memory leak...
56  static DataType _static_type;
57  static bool _is_initialized = false;
58  if (!_is_initialized)
59  {
61  _is_initialized = true;
62  }
63  _datatype = _static_type;
64  }
65 };
66 
67 #endif // LIBMESH_HAVE_MPI
68 
69 #ifdef LIBMESH_ENABLE_UNIQUE_ID
70 typedef std::pair<Hilbert::HilbertIndices, unique_id_type> DofObjectKey;
71 #else
72 typedef Hilbert::HilbertIndices DofObjectKey;
73 #endif
74 
75 
76 } // namespace Parallel
77 
78 
79 } // namespace libMesh
80 
81 
82 namespace Hilbert {
83 
84 // This has to be in the Hilbert namespace for Koenig lookup to work?
85 // g++ doesn't find it if it's in the global namespace.
86 // XCode didn't find it in the libMesh namespace.
87 #ifdef LIBMESH_ENABLE_UNIQUE_ID
88 inline
89 std::ostream & operator << (std::ostream & os,
90  const libMesh::Parallel::DofObjectKey & hilbert_pair)
91 {
92  os << '(' << hilbert_pair.first << ',' << hilbert_pair.second << ')' << std::endl;
93  return os;
94 }
95 #endif
96 
97 }
98 
99 
100 // Appropriate operator< definitions for std::pair let the same code handle
101 // both DofObjectKey types
102 
103 inline
106  int * len, void *)
107 {
108  // When (*in <= *inout), then inout already contains max(*in,*inout)
109  // Otherwise we need to copy from in.
110  for (int i=0; i<*len; i++, in++, inout++)
111  if (*inout < *in)
112  *inout = *in;
113 }
114 
115 inline
118  int * len, void *)
119 {
120  // When (*in >= *inout), then inout already contains min(*in,*inout)
121  // Otherwise we need to copy from in.
122  for (int i=0; i<*len; i++, in++, inout++)
123  if (*in < *inout)
124  *inout = *in;
125 }
126 
127 #endif // LIBMESH_HAVE_LIBHILBERT && LIBMESH_HAVE_MPI
128 
129 #endif // LIBMESH_PARALLEL_HILBERT_H
void dofobjectkey_min_op(libMesh::Parallel::DofObjectKey *in, libMesh::Parallel::DofObjectKey *inout, int *len, void *)
std::pair< Hilbert::HilbertIndices, unique_id_type > DofObjectKey
const class libmesh_nullptr_t libmesh_nullptr
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
Definition: fe_type.h:164
The libMesh namespace provides an interface to certain functionality in the library.
void dofobjectkey_max_op(libMesh::Parallel::DofObjectKey *in, libMesh::Parallel::DofObjectKey *inout, int *len, void *)
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:255
StandardType(const Hilbert::HilbertIndices *=libmesh_nullptr)
Templated class to provide the appropriate MPI datatype for use with built-in C types or simple C++ c...
Definition: parallel.h:380
Encapsulates the MPI_Datatype.
Definition: parallel.h:289