/usr/include/trilinos/Tpetra_SerialPlatform.hpp is in libtrilinos-tpetra-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | // @HEADER
// ***********************************************************************
//
// Tpetra: Templated Linear Algebra Services Package
// Copyright (2008) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ************************************************************************
// @HEADER
#ifndef TPETRA_SERIALPLATFORM_HPP
#define TPETRA_SERIALPLATFORM_HPP
#include <Tpetra_ConfigDefs.hpp>
#include <Tpetra_Core.hpp>
#include <Kokkos_DefaultNode.hpp>
#include <Teuchos_DefaultSerialComm.hpp>
#include <Teuchos_Describable.hpp>
namespace Tpetra {
/// \brief Implementation of the Platform concept for non-MPI platforms.
///
/// \warning This class will be DEPRECATED, in favor of the
/// initialize() functions in Tpetra_Core.hpp. Please use those
/// functions for safe, consistent initialization Kokkos, on which
/// Tpetra depends. If you must use this class, please prefer the
/// constructors that take \c argc and \c argv. Those
/// constructors will call initialize() for you.
///
/// SerialPlatform is an implementation of Tpetra's Platform
/// concept. Classes implementing the Platform concept are
/// templated on the Kokkos Node type. They have at least the
/// following public interface:
/// \code
/// // This is not a real class; it just illustrates the concept.
/// template<class Node>
/// class Platform {
/// public:
/// typedef Node NodeType;
/// explicit Platform (const RCP<Node>& node);
/// RCP<const Comm<int> > getComm() const;
/// RCP<Node> getNode() const;
/// };
/// \endcode
/// SerialPlatform uses a "communicator" containing one process. It
/// is available whether or not Trilinos was built with MPI (the
/// Message-Passing Interface which provides a distributed-memory
/// parallel programming model).
template <class Node>
class SerialPlatform : public Teuchos::Describable {
public:
//! @name Typedefs
//@{
//! Kokkos Node type; the template parameter of this class.
typedef Node NodeType;
//@}
//! @name Constructors and destructor
//@{
/// \brief Constructor that accepts the same arguments as
/// Tpetra::initialize().
///
/// \param argc [in/out] First argument of Tpetra::initialize().
/// \param argv [in/out] Second argument of Tpetra::initialize().
explicit SerialPlatform (int* argc, char*** argv) :
comm_ (Teuchos::null),
node_ (Teuchos::null)
{
initialize (argc, argv);
comm_ = getDefaultComm ();
// mfh 29 Jun 2014: Don't initialize the Node yet. This ensures
// that (new) Kokkos won't get initialized with the wrong
// command-line arguments, at least not until getNode() is
// called. Initializing Kokkos with the wrong command-line
// arguments may result in poor performance due to the wrong
// assignment of software threads to hardware execution units.
//
// if (node_.is_null ()) {
// node_ = KokkosClassic::Details::getNode<NodeType> ();
// }
}
/// Constructor that accepts a Kokkos Node.
///
/// \param node [in/out] The Kokkos Node instance. If null, this
/// class will create a Node with default parameters, at some
/// time no later than during the first call to getNode().
explicit SerialPlatform (const Teuchos::RCP<NodeType>& node) :
comm_ (Teuchos::rcp (new Teuchos::SerialComm<int> ())),
node_ (node)
{
// mfh 29 Jun 2014: Don't initialize the Node yet. See above note.
}
/// \brief Constructor that accepts the same arguments as
/// Tpetra::initialize(), plus a Kokkos Node.
///
/// \param argc [in/out] First argument of Tpetra::initialize().
/// \param argv [in/out] Second argument of Tpetra::initialize().
/// \param node [in/out] The Kokkos Node instance. If null, this
/// class will create a Node with default parameters, at some
/// time no later than during the first call to getNode().
explicit SerialPlatform (int* argc, char*** argv,
const Teuchos::RCP<NodeType>& node) :
comm_ (Teuchos::null),
node_ (node)
{
initialize (argc, argv);
comm_ = getDefaultComm ();
// mfh 29 Jun 2014: Don't initialize the Node yet. See above note.
}
//! Destructor (virtual for memory safety of derived classes).
virtual ~SerialPlatform () {}
//@}
//! @name Methods to access the communicator and Kokkos Node.
//@{
//! The Teuchos::Comm instance with which this object was created.
Teuchos::RCP<const Teuchos::Comm<int> > getComm () const {
return comm_;
}
//! The Kokkos Node instance with which this object was created.
Teuchos::RCP<Node> getNode () const {
typedef SerialPlatform<NodeType> this_type;
if (node_.is_null ()) {
// NOTE (mfh 29 Jun 2014): Creating an instance of one of the
// new Kokkos wrapper Nodes _must_ call Kokkos::initialize.
// If Kokkos has not been initialized yet, this may result in
// Kokkos being initialized correctly, since we have no way to
// pass it the command-line arguments at this point. This is
// why we should prefer the *Platform constructors that take
// argc and argv, since they can (and do) call
// Kokkos::initialize (by calling Tpetra::initialize).
//
// mfh 29 Jun 2014: We're only keeping the *Platform classes
// for backwards compatibility anyway, so I don't feel bad
// about the const_cast here.
const_cast<this_type*> (this)->node_ =
KokkosClassic::Details::getNode<NodeType> ();
TEUCHOS_TEST_FOR_EXCEPTION(
node_.is_null (), std::logic_error, "Tpetra::MpiPlatform::getNode: "
"KokkosClassic::Details::getNode<NodeType>() returned null. "
"This should never happen. "
"Please report this bug to the Tpetra developers.");
}
return node_;
}
//@}
protected:
//! Teuchos::Comm object instantiated for the platform.
Teuchos::RCP<const Teuchos::Comm<int> > comm_;
//! Kokkos Node object instantiated for the platform.
Teuchos::RCP<NodeType> node_;
private:
//! Unimplemented copy constructor (syntactically forbidden).
SerialPlatform (const SerialPlatform<NodeType>& platform);
//! Unimplemented assignment operator (syntactically forbidden).
SerialPlatform& operator= (const SerialPlatform<NodeType>& platform);
};
/// \class SerialPlatform<Tpetra::Details::DefaultTypes::node_type>
/// \brief SerialPlatform specialization for the default Node type.
///
/// \note Tpetra::Details::DefaultTypes::node_type is a typedef, and
/// may have a different type, depending on Trilinos' build
/// options.
///
/// \note In the past (up to and including the 10.8 Trilinos
/// release), the specialization of SerialPlatform for the default
/// Node type delayed instantiation of the default Node instance
/// until getNode() was called. We have changed this behavior to
/// simplify the code and make the specialization of
/// SerialPlatform conform more closely to the generic version of
/// SerialPlatform.
template <>
class SerialPlatform<Tpetra::Details::DefaultTypes::node_type> :
public Teuchos::Describable {
public:
//! @name Typedefs
//@{
//! Kokkos Node type; the template parameter of this class.
typedef Tpetra::Details::DefaultTypes::node_type NodeType;
//@}
//! @name Constructors and destructor
//@{
/// \brief Default constructor: uses Kokkos default node.
///
/// The specialization of SerialPlatform for the default Node type
/// includes a default constructor. At some point before the
/// first call to getNode() returns, this class will create a Node
/// with default parameters.
SerialPlatform () :
comm_ (Teuchos::rcp (new Teuchos::SerialComm<int> ())),
node_ (Teuchos::null)
{
// mfh 29 Jun 2014: Don't initialize the Node yet. This ensures
// that (new) Kokkos won't get initialized with the wrong
// command-line arguments, at least not until getNode() is
// called. Initializing Kokkos with the wrong command-line
// arguments may result in poor performance due to the wrong
// assignment of software threads to hardware execution units.
}
/// \brief Constructor that accepts the same arguments as
/// Tpetra::initialize().
///
/// \param argc [in/out] First argument of Tpetra::initialize().
/// \param argv [in/out] Second argument of Tpetra::initialize().
explicit SerialPlatform (int* argc, char*** argv) :
comm_ (Teuchos::null),
node_ (Teuchos::null)
{
initialize (argc, argv);
comm_ = getDefaultComm ();
// mfh 29 Jun 2014: Don't initialize the Node yet. See above note.
}
/// \brief Constructor that accepts a Kokkos Node.
///
/// This version of the constructor is declared "explicit" to
/// forbid silent type conversions from the Node instance to a
/// SerialPlatform. (A single-argument constructor that is not
/// declared "explicit" defines a type conversion method from the
/// input type to the constructor's class's type.) The "explicit"
/// declaration does not affect typical use of this constructor.
///
/// \param node [in/out] The Kokkos Node instance. If null, this
/// class will create a Node with default parameters, at some
/// time no later than during the first call to getNode().
explicit SerialPlatform (const Teuchos::RCP<NodeType>& node) :
comm_ (Teuchos::rcp (new Teuchos::SerialComm<int> ())),
node_ (node)
{
// mfh 29 Jun 2014: Don't initialize the Node yet. See above note.
}
/// \brief Constructor that accepts the same arguments as
/// Tpetra::initialize(), plus a Kokkos Node.
///
/// \param argc [in/out] First argument of Tpetra::initialize().
/// \param argv [in/out] Second argument of Tpetra::initialize().
/// \param node [in/out] The Kokkos Node instance. If null, this
/// class will create a Node with default parameters, at some
/// time no later than during the first call to getNode().
explicit SerialPlatform (int* argc, char*** argv,
const Teuchos::RCP<NodeType>& node) :
comm_ (Teuchos::null),
node_ (node)
{
initialize (argc, argv);
comm_ = getDefaultComm ();
// mfh 29 Jun 2014: Don't initialize the Node yet. See above note.
}
//! Destructor (virtual for memory safety of derived classes).
virtual ~SerialPlatform () {}
//@}
//! @name Methods to access the communicator and Kokkos Node.
//@{
//! The Teuchos::Comm instance with which this object was created.
Teuchos::RCP<const Teuchos::Comm<int> > getComm() const {
return comm_;
}
//! The Kokkos Node instance with which this object was created.
Teuchos::RCP<Tpetra::Details::DefaultTypes::node_type> getNode () const {
typedef SerialPlatform<NodeType> this_type;
if (node_.is_null ()) {
// NOTE (mfh 29 Jun 2014): Creating an instance of one of the
// new Kokkos wrapper Nodes _must_ call Kokkos::initialize.
// If Kokkos has not been initialized yet, this may result in
// Kokkos being initialized correctly, since we have no way to
// pass it the command-line arguments at this point. This is
// why we should prefer the *Platform constructors that take
// argc and argv, since they can (and do) call
// Kokkos::initialize (by calling Tpetra::initialize).
//
// mfh 29 Jun 2014: We're only keeping the *Platform classes
// for backwards compatibility anyway, so I don't feel bad
// about the const_cast here.
const_cast<this_type*> (this)->node_ =
KokkosClassic::Details::getNode<NodeType> ();
TEUCHOS_TEST_FOR_EXCEPTION(
node_.is_null (), std::logic_error, "Tpetra::MpiPlatform::getNode: "
"KokkosClassic::Details::getNode<NodeType>() returned null. "
"This should never happen. "
"Please report this bug to the Tpetra developers.");
}
return node_;
}
//@}
private:
//! Unimplemented copy constructor (syntactically forbidden).
SerialPlatform (const SerialPlatform<NodeType>& platform);
//! Unimplemented assignment operator (syntactically forbidden).
SerialPlatform& operator= (const SerialPlatform<NodeType>& platform);
protected:
//! Teuchos::Comm object instantiated for the platform.
Teuchos::RCP<const Teuchos::Comm<int> > comm_;
//! Node object instantiated for the platform.
Teuchos::RCP<NodeType> node_;
};
} // namespace Tpetra
#endif // TPETRA_SERIALPLATFORM_HPP
|