Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 <Tpetra_ConfigDefs.hpp>
46 #include <Tpetra_Core.hpp>
47 #include <Kokkos_DefaultNode.hpp>
48 #include <Teuchos_DefaultMpiComm.hpp>
49 #include <Teuchos_Describable.hpp>
50 
51 namespace Tpetra {
52 
66  template <class Node>
67  class TPETRA_DEPRECATED MpiPlatform : public Teuchos::Describable {
68  public:
70 
71 
73  typedef Node NodeType;
74 
76 
78 
91  explicit MpiPlatform (const Teuchos::RCP<NodeType>& node) :
92  comm_ (new Teuchos::MpiComm<int> (MPI_COMM_WORLD))
93  {}
94 
108  MpiPlatform (int* argc,
109  char*** argv,
110  const Teuchos::RCP<NodeType>& /* node */) :
111  comm_ (Teuchos::null)
112  {
113  initialize (argc, argv);
114  comm_ = getDefaultComm ();
115  }
116 
139  MpiPlatform (const Teuchos::RCP<NodeType>& /* node */,
140  const Teuchos::RCP<const Teuchos::OpaqueWrapper<MPI_Comm> >& rawMpiComm)
141  : comm_ (Teuchos::null)
142  {
143  TEUCHOS_TEST_FOR_EXCEPTION(
144  rawMpiComm.is_null (), std::invalid_argument, "Tpetra::MpiPlatform "
145  "constructor: The input RCP<OpaqueWrapper<MPI_Comm> > is null. That "
146  "means something different than MPI_COMM_NULL. If you want to give "
147  "MPI_COMM_NULL to this constructor, please wrap MPI_COMM_NULL in a "
148  "nonnull Teuchos::OpaqueWrapper by using the "
149  "Teuchos::opaqueWrapper<MPI_Comm>() nonmember constructor.");
150  comm_ = Teuchos::createMpiComm<int> (rawMpiComm);
151  }
152 
178  MpiPlatform (int* argc,
179  char*** argv,
180  const Teuchos::RCP<NodeType>& /* node */,
181  const Teuchos::RCP<const Teuchos::OpaqueWrapper<MPI_Comm> >& rawMpiComm)
182  : comm_ (Teuchos::null)
183  {
184  TEUCHOS_TEST_FOR_EXCEPTION(
185  rawMpiComm.is_null (), std::invalid_argument, "Tpetra::MpiPlatform "
186  "constructor: The input RCP<OpaqueWrapper<MPI_Comm> > is null. That "
187  "means something different than MPI_COMM_NULL. If you want to give "
188  "MPI_COMM_NULL to this constructor, please wrap MPI_COMM_NULL in a "
189  "nonnull Teuchos::OpaqueWrapper by using the "
190  "Teuchos::opaqueWrapper<MPI_Comm>() nonmember constructor.");
191  comm_ = Teuchos::createMpiComm<int> (rawMpiComm);
192 
193  // NOTE (mfh 29 Jun 2014): The OpaqueWrapper might wrap the
194  // MPI_Comm in something that calls MPI_Comm_free. Thus, we
195  // can't just ignore it; we have to give it to the comm_ so that
196  // its destructor (which might call MPI_Comm_free) will be
197  // called at the right time. This is why we don't set comm
198  // using getDefaultComm(). This is also why we pass comm_
199  // directly to initialize(): that way there aren't two
200  // references to the raw MPI_Comm floating around, and comm_'s
201  // destructor will get to do the right thing.
202  initialize (argc, argv, comm_);
203  }
204 
219  MpiPlatform (const Teuchos::RCP<NodeType>& node, MPI_Comm rawMpiComm)
220  : comm_ (new Teuchos::MpiComm<int> (rawMpiComm))
221  {}
222 
239  MpiPlatform (int* argc,
240  char*** argv,
241  const Teuchos::RCP<NodeType>& /* node */,
242  MPI_Comm rawMpiComm)
243  : comm_ (Teuchos::null)
244  {
245  initialize (argc, argv, rawMpiComm);
246  comm_ = getDefaultComm ();
247  }
248 
250  virtual ~MpiPlatform () {}
251 
253 
255 
257  Teuchos::RCP<const Teuchos::Comm<int> > getComm () const {
258  TEUCHOS_TEST_FOR_EXCEPTION(
259  comm_.is_null (), std::logic_error, "Tpetra::MpiPlatform::getComm: "
260  "The default communicator is null. This should never happen. "
261  "Please report this bug to the Tpetra developers.");
262  return comm_;
263  }
264 
270  Teuchos::RCP<NodeType> getNode () const {
271  return Teuchos::rcp (new NodeType);
272  }
273 
275  protected:
277  Teuchos::RCP<const Teuchos::Comm<int> > comm_;
278 
279  private:
281  MpiPlatform (const MpiPlatform<NodeType>& platform);
283  MpiPlatform& operator= (const MpiPlatform<NodeType>& platform);
284  };
285 
299  template <>
301  public Teuchos::Describable {
302  public:
304 
305 
307  typedef ::Tpetra::Details::DefaultTypes::node_type NodeType;
308 
310 
312 
314  MpiPlatform ();
315 
321  MpiPlatform (int* argc, char*** argv);
322 
338  explicit MpiPlatform (const Teuchos::RCP<NodeType>& node);
339 
353  MpiPlatform (int* argc, char*** argv, const Teuchos::RCP<NodeType>& node);
354 
377  MpiPlatform (const Teuchos::RCP<NodeType>& node,
378  const Teuchos::RCP<const Teuchos::OpaqueWrapper<MPI_Comm> >& rawMpiComm);
379 
405  MpiPlatform (int* argc,
406  char*** argv,
407  const Teuchos::RCP<NodeType>& node,
408  const Teuchos::RCP<const Teuchos::OpaqueWrapper<MPI_Comm> >& rawMpiComm);
409 
424  MpiPlatform (const Teuchos::RCP<NodeType>& node, MPI_Comm rawMpiComm);
425 
442  MpiPlatform (int* argc,
443  char*** argv,
444  const Teuchos::RCP<NodeType>& node,
445  MPI_Comm rawMpiComm);
446 
448  virtual ~MpiPlatform ();
449 
451 
453 
455  Teuchos::RCP<const Teuchos::Comm<int> > getComm () const;
456 
462  Teuchos::RCP<NodeType> getNode () const;
463 
465  private:
467  MpiPlatform (const MpiPlatform<NodeType>& platform);
468 
470  MpiPlatform& operator= (const MpiPlatform<NodeType>& platform);
471 
472  protected:
474  Teuchos::RCP<const Teuchos::Comm<int> > comm_;
475  };
476 
477 } // namespace Tpetra
478 
479 #endif // TPETRA_MPIPLATFORM_HPP
void initialize(int *argc, char ***argv)
Initialize Tpetra.
Implementation of the Platform concept for MPI-based platforms.
Teuchos::RCP< NodeType > getNode() const
The default Kokkos Node instance.
Node NodeType
Kokkos Node type; the template parameter of this class.
virtual ~MpiPlatform()
Destructor (virtual for memory safety of derived classes).
::Tpetra::Details::DefaultTypes::node_type NodeType
Kokkos Node type; the template parameter of this class.
MpiPlatform(const Teuchos::RCP< NodeType > &, const Teuchos::RCP< const Teuchos::OpaqueWrapper< MPI_Comm > > &rawMpiComm)
Constructor that accepts a Kokkos Node and a wrapped MPI communicator.
Teuchos::RCP< const Teuchos::Comm< int > > comm_
Teuchos::Comm object instantiated for the platform.
Teuchos::RCP< const Teuchos::Comm< int > > comm_
Teuchos::Comm object instantiated for the platform.
MpiPlatform(int *argc, char ***argv, const Teuchos::RCP< NodeType > &, const Teuchos::RCP< const Teuchos::OpaqueWrapper< MPI_Comm > > &rawMpiComm)
Constructor that accepts the same arguments as MPI_Init(), plus a Kokkos Node and a wrapped MPI commu...
Functions for initializing and finalizing Tpetra.
MpiPlatform(int *argc, char ***argv, const Teuchos::RCP< NodeType > &, MPI_Comm rawMpiComm)
Constructor that accepts the same arguments as MPI_Init(), plus a Kokkos Node and a raw MPI communica...
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
MpiPlatform(const Teuchos::RCP< NodeType > &node)
Constructor that accepts a Kokkos Node.
Teuchos::RCP< const Teuchos::Comm< int > > getDefaultComm()
Get Tpetra's default communicator.
MpiPlatform(int *argc, char ***argv, const Teuchos::RCP< NodeType > &)
Constructor that accepts the same arguments as MPI_Init(), plus a Kokkos Node.
MpiPlatform(const Teuchos::RCP< NodeType > &node, MPI_Comm rawMpiComm)
Constructor that accepts a Kokkos Node and a raw MPI communicator.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The Teuchos::Comm instance with which this object was created.