Tpetra Matrix/Vector Services  Version of the Day
Tpetra_MpiPlatform.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_MPIPLATFORM_HPP
43 #define TPETRA_MPIPLATFORM_HPP
44 
45 #include <Teuchos_DefaultMpiComm.hpp>
46 #include <Teuchos_Describable.hpp>
47 #include <Tpetra_ConfigDefs.hpp>
48 #include <Kokkos_DefaultNode.hpp>
49 
50 namespace Tpetra {
51 
74  template <class Node>
76  public:
78 
79 
81  typedef Node NodeType;
82 
84 
86 
96  explicit MpiPlatform (const RCP<Node> &node) :
97  comm_ (Teuchos::createMpiComm<int> (Teuchos::opaqueWrapper<MPI_Comm> (MPI_COMM_WORLD))),
98  node_ (node.is_null () ? Kokkos::Details::getNode<Node> () : node)
99  {}
100 
119  MpiPlatform (const RCP<Node> &node,
120  const RCP<const Teuchos::OpaqueWrapper<MPI_Comm> > &rawMpiComm)
121  : comm_ (Teuchos::createMpiComm<int> (rawMpiComm)),
122  node_ (node.is_null () ? Kokkos::Details::getNode<Node> () : node)
123  {}
124 
135  MpiPlatform (const RCP<Node> &node, MPI_Comm rawMpiComm)
136  : comm_ (Teuchos::createMpiComm<int> (Teuchos::opaqueWrapper<MPI_Comm> (rawMpiComm))),
137  node_ (node.is_null () ? Kokkos::Details::getNode<Node> () : node)
138  {}
139 
141  virtual ~MpiPlatform() {}
142 
144 
146 
149  return comm_;
150  }
151 
153  RCP<Node> getNode() const {
154  return node_;
155  }
156 
158  protected:
163 
164  private:
166  MpiPlatform (const MpiPlatform<Node> &platform);
168  MpiPlatform& operator= (const MpiPlatform<Node> &platform);
169  };
170 
186  template <>
187  class MpiPlatform<Kokkos::DefaultNode::DefaultNodeType> :
188  public Teuchos::Describable {
189  public:
191 
192 
194  typedef Kokkos::DefaultNode::DefaultNodeType NodeType;
195 
197 
199 
207  comm_ (Teuchos::createMpiComm<int> (Teuchos::opaqueWrapper<MPI_Comm> (MPI_COMM_WORLD))),
208  node_ (Kokkos::DefaultNode::getDefaultNode ())
209  {}
210 
226  comm_ (Teuchos::createMpiComm<int> (Teuchos::opaqueWrapper<MPI_Comm> (MPI_COMM_WORLD))),
227  node_ (node.is_null() ? Kokkos::DefaultNode::getDefaultNode() : node)
228  {}
229 
248  const RCP<const Teuchos::OpaqueWrapper<MPI_Comm> > &rawMpiComm)
249  : comm_ (Teuchos::createMpiComm<int> (rawMpiComm)),
250  node_ (node.is_null() ? Kokkos::DefaultNode::getDefaultNode() : node)
251  {}
252 
263  MPI_Comm rawMpiComm)
264  : comm_ (Teuchos::createMpiComm<int> (Teuchos::opaqueWrapper<MPI_Comm> (rawMpiComm))),
265  node_ (node.is_null() ? Kokkos::DefaultNode::getDefaultNode() : node)
266  {}
267 
269  virtual ~MpiPlatform() {}
270 
272 
274 
277  return comm_;
278  }
279 
282  return node_;
283  }
284 
286  private:
289 
292 
293  protected:
296 
299  };
300 
301 } // namespace Tpetra
302 
303 #endif // TPETRA_MPIPLATFORM_HPP
MpiPlatform(const RCP< Kokkos::DefaultNode::DefaultNodeType > &node, MPI_Comm rawMpiComm)
Constructor that accepts a Kokkos Node and a raw MPI communicator.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
bool is_null(const boost::shared_ptr< T > &p)
Implementation of the Platform concept for MPI-based platforms.
RCP< Kokkos::DefaultNode::DefaultNodeType > node_
Kokkos Node object instantiated for the platform.
MpiPlatform(const RCP< Node > &node)
Constructor that accepts a Kokkos Node.
Node NodeType
Kokkos Node type; the template parameter of this class.
RCP< Kokkos::DefaultNode::DefaultNodeType > getNode() const
The Kokkos Node instance for this platform to use.
RCP< const Comm< int > > getComm() const
The Teuchos::Comm instance with which this object was created.
virtual ~MpiPlatform()
Destructor (virtual for memory safety of derived classes).
MpiPlatform(const RCP< Kokkos::DefaultNode::DefaultNodeType > &node, const RCP< const Teuchos::OpaqueWrapper< MPI_Comm > > &rawMpiComm)
Constructor that accepts a Kokkos Node and a wrapped MPI communicator.
Implementation details of Tpetra.
RCP< Teuchos::MpiComm< int > > comm_
Teuchos::Comm object instantiated for the platform.
RCP< Teuchos::MpiComm< int > > comm_
Teuchos::Comm object instantiated for the platform.
MpiPlatform(const RCP< Node > &node, MPI_Comm rawMpiComm)
Constructor that accepts a Kokkos Node and a raw MPI communicator.
virtual ~MpiPlatform()
Destructor (virtual for memory safety of derived classes).
MpiPlatform(const RCP< Kokkos::DefaultNode::DefaultNodeType > &node)
Constructor that accepts a Kokkos Node.
RCP< Node > getNode() const
The Kokkos Node instance with which this object was created.
MpiPlatform(const RCP< Node > &node, const RCP< const Teuchos::OpaqueWrapper< MPI_Comm > > &rawMpiComm)
Constructor that accepts a Kokkos Node and a wrapped MPI communicator.
RCP< const Comm< int > > getComm() const
The Teuchos::Comm instance with which this object was created.
MpiPlatform()
Default constructor: uses Kokkos default node and MPI_COMM_WORLD.
MpiPlatform specialization for Kokkos::DefaultNode::DefaultNodeType.
Kokkos::DefaultNode::DefaultNodeType NodeType
Kokkos Node type; the template parameter of this class.
RCP< Node > node_
Kokkos Node object instantiated for the platform.