parallel_hilbert.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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...
33 #include "hilbert.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 * =nullptr) {
55  }
56 
58  : DataType()
59  {
60  libmesh_call_mpi (MPI_Type_dup (t._datatype, &_datatype));
61  }
62 
63  ~StandardType() { this->free(); }
64 };
65 
66 #endif // LIBMESH_HAVE_MPI
67 
68 #ifdef LIBMESH_ENABLE_UNIQUE_ID
69 typedef std::pair<Hilbert::HilbertIndices, unique_id_type> DofObjectKey;
70 #else
71 typedef Hilbert::HilbertIndices DofObjectKey;
72 #endif
73 
74 
75 } // namespace Parallel
76 
77 
78 } // namespace libMesh
79 
80 
81 namespace Hilbert {
82 
83 // This has to be in the Hilbert namespace for Koenig lookup to work?
84 // g++ doesn't find it if it's in the global namespace.
85 // XCode didn't find it in the libMesh namespace.
86 #ifdef LIBMESH_ENABLE_UNIQUE_ID
87 inline
88 std::ostream & operator << (std::ostream & os,
89  const libMesh::Parallel::DofObjectKey & hilbert_pair)
90 {
91  os << '(' << hilbert_pair.first << ',' << hilbert_pair.second << ')' << std::endl;
92  return os;
93 }
94 #endif
95 
96 }
97 
98 
99 // Appropriate operator< definitions for std::pair let the same code handle
100 // both DofObjectKey types
101 
102 inline
105  int * len, void *)
106 {
107  // When (*in <= *inout), then inout already contains max(*in,*inout)
108  // Otherwise we need to copy from in.
109  for (int i=0; i<*len; i++, in++, inout++)
110  if (*inout < *in)
111  *inout = *in;
112 }
113 
114 inline
117  int * len, void *)
118 {
119  // When (*in >= *inout), then inout already contains min(*in,*inout)
120  // Otherwise we need to copy from in.
121  for (int i=0; i<*len; i++, in++, inout++)
122  if (*in < *inout)
123  *inout = *in;
124 }
125 
126 #endif // LIBMESH_HAVE_LIBHILBERT
127 
128 #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
void dofobjectkey_max_op(libMesh::Parallel::DofObjectKey *in, libMesh::Parallel::DofObjectKey *inout, int *len, void *)
StandardType(const Hilbert::HilbertIndices *=nullptr)
std::ostream & operator<<(std::ostream &os, const libMesh::Parallel::DofObjectKey &hilbert_pair)
StandardType(const StandardType< Hilbert::HilbertIndices > &t)