Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Tpetra::ScopeGuard Class Reference

Scope guard whose destructor automatically calls Tpetra::finalize for you. More...

#include <Tpetra_Core.hpp>

Public Member Functions

 ScopeGuard (int *argc, char ***argv)
 Initialize Tpetra.
 
 ScopeGuard ()=delete
 Default constructor (FORBIDDEN)
 
 ~ScopeGuard ()
 Finalize Tpetra.
 

Detailed Description

Scope guard whose destructor automatically calls Tpetra::finalize for you.

This class' constructor does the same thing as Tpetra::initialize (see above). Its destructor automatically calls Tpetra::finalize. This ensures correct Tpetra finalization even if intervening code throws an exception.

Compare to Kokkos::ScopeGuard and Teuchos::GlobalMPISession.

Always give the ScopeGuard instance a name. Otherwise, you'll create a temporary object whose destructor will be called right away. That's not what you want.

Here is an example of how to use this class:

#include "Tpetra_Core.hpp"
#include "Tpetra_Map.hpp"
int main (int argc, char* argv[]) {
// Never create Tpetra or Kokkos objects (other than
// the ScopeGuard object itself) at main scope.
// Otherwise, their destructors will be called after
// MPI_Finalize and Kokkos::finalize are called, which
// is forbidden.
{
auto comm = Tpetra::getDefaultComm ();
const GO gblNumInds = 1000;
const GO indexBase = 0;
Tpetra::GloballyDistributed);
// ... code that uses map ...
}
return EXIT_SUCCESS;
}
Functions for initializing and finalizing Tpetra.
Struct that holds views of the contents of a CrsMatrix.
Scope guard whose destructor automatically calls Tpetra::finalize for you.
Teuchos::RCP< const Teuchos::Comm< int > > getDefaultComm()
Get Tpetra's default communicator.

Definition at line 219 of file Tpetra_Core.hpp.

Constructor & Destructor Documentation

◆ ScopeGuard() [1/2]

Tpetra::ScopeGuard::ScopeGuard ( int * argc,
char *** argv )

Initialize Tpetra.

If MPI_Init has not yet been called, then call it. If Kokkos::initialize has not yet been called, then call it.

Parameters
argc[in/out] Address of the first argument to main().
argv[in/out] Address of the second argument to main().

Definition at line 347 of file Tpetra_Core.cpp.

◆ ScopeGuard() [2/2]

Tpetra::ScopeGuard::ScopeGuard ( )
delete

Default constructor (FORBIDDEN)

You must give ScopeGuard's constructor argc and argv. Use the constructor above this one.

◆ ~ScopeGuard()

Tpetra::ScopeGuard::~ScopeGuard ( )

Finalize Tpetra.

If the constructor called Kokkos::initialize, then call Kokkos::finalize. If the constructor called MPI_Init, then call MPI_Finalize.

Definition at line 359 of file Tpetra_Core.cpp.


The documentation for this class was generated from the following files: