libMesh
parallel_hilbert.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 // TIMPI includes
31 #include "timpi/standard_type.h"
32 
33 // C/C++ includes
34 
35 // So many implicit-fallthrough warnings in crazy libHilbert macros...
36 #include "libmesh/ignore_warnings.h"
37 #include "hilbert.h"
38 #include "libmesh/restore_warnings.h"
39 
40 #include <cstddef>
41 
42 namespace TIMPI {
43 
44 #ifdef LIBMESH_HAVE_MPI
45 // A StandardType<> specialization to return a derived MPI datatype
46 // to handle communication of HilbertIndices. We use a singleton
47 // pattern here because a global variable would have tried to call
48 // MPI functions before MPI got initialized.
49 template <>
50 class StandardType<Hilbert::HilbertIndices> : public DataType
51 {
52 public:
53  explicit
54  StandardType(const Hilbert::HilbertIndices * =nullptr) {
55  _datatype = DataType(StandardType<Hilbert::inttype>(), 3);
56  }
57 
59  : DataType()
60  {
61  timpi_call_mpi (MPI_Type_dup (t._datatype, &_datatype));
62  }
63 
64  ~StandardType() { this->free(); }
65 };
66 
67 #endif // LIBMESH_HAVE_MPI
68 
69 } // namespace TIMPI
70 
71 
72 namespace libMesh {
73 
74 namespace Parallel {
75 
76 #ifdef LIBMESH_ENABLE_UNIQUE_ID
77 typedef std::pair<Hilbert::HilbertIndices, unique_id_type> DofObjectKey;
78 #else
79 typedef Hilbert::HilbertIndices DofObjectKey;
80 #endif
81 
82 } // namespace Parallel
83 
84 } // namespace libMesh
85 
86 
87 namespace Hilbert {
88 
89 // This has to be in the Hilbert namespace for Koenig lookup to work?
90 // g++ doesn't find it if it's in the global namespace.
91 // XCode didn't find it in the libMesh namespace.
92 #ifdef LIBMESH_ENABLE_UNIQUE_ID
93 inline
94 std::ostream & operator << (std::ostream & os,
95  const libMesh::Parallel::DofObjectKey & hilbert_pair)
96 {
97  os << '(' << hilbert_pair.first << ',' << hilbert_pair.second << ')' << std::endl;
98  return os;
99 }
100 #endif
101 
102 }
103 
104 
105 // Appropriate operator< definitions for std::pair let the same code handle
106 // both DofObjectKey types
107 
108 inline
111  int * len, void *)
112 {
113  // When (*in <= *inout), then inout already contains max(*in,*inout)
114  // Otherwise we need to copy from in.
115  for (int i=0; i<*len; i++, in++, inout++)
116  if (*inout < *in)
117  *inout = *in;
118 }
119 
120 inline
123  int * len, void *)
124 {
125  // When (*in >= *inout), then inout already contains min(*in,*inout)
126  // Otherwise we need to copy from in.
127  for (int i=0; i<*len; i++, in++, inout++)
128  if (*in < *inout)
129  *inout = *in;
130 }
131 
132 #endif // LIBMESH_HAVE_LIBHILBERT
133 
134 #endif // LIBMESH_PARALLEL_HILBERT_H
libMesh::Parallel::DofObjectKey
std::pair< Hilbert::HilbertIndices, unique_id_type > DofObjectKey
Definition: parallel_hilbert.h:77
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
dofobjectkey_max_op
void dofobjectkey_max_op(libMesh::Parallel::DofObjectKey *in, libMesh::Parallel::DofObjectKey *inout, int *len, void *)
Definition: parallel_hilbert.h:109
TIMPI::StandardType< Hilbert::HilbertIndices >
Definition: parallel_hilbert.h:50
TIMPI::StandardType< Hilbert::HilbertIndices >::StandardType
StandardType(const StandardType< Hilbert::HilbertIndices > &t)
Definition: parallel_hilbert.h:58
TIMPI::StandardType< Hilbert::HilbertIndices >::StandardType
StandardType(const Hilbert::HilbertIndices *=nullptr)
Definition: parallel_hilbert.h:54
dofobjectkey_min_op
void dofobjectkey_min_op(libMesh::Parallel::DofObjectKey *in, libMesh::Parallel::DofObjectKey *inout, int *len, void *)
Definition: parallel_hilbert.h:121
standard_type.h
TIMPI
Definition: libmesh_common.h:664
Hilbert::operator<<
std::ostream & operator<<(std::ostream &os, const libMesh::Parallel::DofObjectKey &hilbert_pair)
Definition: parallel_hilbert.h:94
TIMPI::StandardType< Hilbert::HilbertIndices >::~StandardType
~StandardType()
Definition: parallel_hilbert.h:64
Hilbert
Definition: parallel_hilbert.h:87