preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
precice::testing::TestContext Class Reference

#include <TestContext.hpp>

Collaboration diagram for precice::testing::TestContext:
[legend]

Public Types

using Participants = std::vector<ParticipantState>
 

Public Member Functions

 TestContext (TestSetup setup)
 
 ~TestContext () noexcept
 
std::string config () const
 
std::string prefix (const std::string &filename) const
 
bool hasSize (int size) const
 Check whether this context has a given size.
 
bool isNamed (const std::string &name) const
 Check whether this context has a given name.
 
bool isRank (Rank rank) const
 Check whether this context has a given rank inside the Participant.
 
auto comm ()
 Returns a pointer to the MPI communicator of this context.
 
bool isPrimary () const
 
m2n::PtrM2N connectPrimaryRanks (const std::string &acceptor, const std::string &connector, const ConnectionOptions &options=ConnectionOptions{}) const
 
std::string describe () const
 Provides a user- and log-friendly description of the current context.
 

Public Attributes

std::string name
 the name of the current participant
 
Rank rank = 0
 the rank of the current participant
 
int size = 1
 the size of the Communicator of the current participant
 
bool invalid = false
 whether this context is valid or not
 

Private Member Functions

void setContextFrom (const ParticipantState &p)
 
Initialization
void initialize (const Participants &participants)
 Main entrypoint.
 
void initializeMPI (const Participants &participants)
 
void initializeIntraComm ()
 Initialize the intra-participant communication connection if requested.
 
void initializePetsc ()
 Initialize PETSc if required.
 
void initializeEvents ()
 Initialize Events if required.
 
void initializeGinkgo ()
 Initialize Ginkgo if required.
 

Private Attributes

TestSetup _setup
 
bool _initIntraComm = false
 whether this context needs to initialize the intracomm
 
utils::Parallel::CommStatePtr _contextComm
 the MPI communicator of the context
 
std::set< std::string_names
 contains the name of every known Participant
 

Detailed Description

Type representing the context of a test.

Note
Do not use this type directly. Use PRECICE_TEST() and PRECICE_TEST_SETUP() instead.

This type is responsible for

  1. making sure that there are enough ranks to run the test on.
  2. restricting and splitting the MPI Communicator.
  3. handling invalid contexts (such as unneeded ranks)
  4. initializing the intra-participant communication if requested. initializeIntraComm()
  5. handling further requirements
    See also
    Require
  6. providing a usable context during the test isNamed(), isPrimary(), isRank()
  7. cleaning up after the test case

Definition at line 193 of file TestContext.hpp.

Member Typedef Documentation

◆ Participants

Definition at line 195 of file TestContext.hpp.

Constructor & Destructor Documentation

◆ TestContext()

precice::testing::TestContext::TestContext ( TestSetup setup)

Creates a context for a rank in the given TestSetup

Unneeded ranks are marked as invalid. Provides a TestContext named context which can be used in the test.

Attention
This call synchronizes all ranks
See also
PRECICE_TEST()

Definition at line 73 of file TestContext.cpp.

Here is the call graph for this function:

◆ ~TestContext()

precice::testing::TestContext::~TestContext ( )
noexcept

Cleans-up all initialized parts and synchronizes all ranks

Attention
This call synchronizes all ranks

Definition at line 82 of file TestContext.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ comm()

auto precice::testing::TestContext::comm ( )
inline

Returns a pointer to the MPI communicator of this context.

Definition at line 253 of file TestContext.hpp.

◆ config()

std::string precice::testing::TestContext::config ( ) const

Returns the canonical config name of this test.

The location of integration tests are tied the test name and test suites. This computes the canonical filename of this test's configuration file based on the repository root, the current test suites and name.

Returns
the full filepath of this test's configuration file

Definition at line 109 of file TestContext.cpp.

Here is the call graph for this function:

◆ connectPrimaryRanks()

m2n::PtrM2N precice::testing::TestContext::connectPrimaryRanks ( const std::string & acceptor,
const std::string & connector,
const ConnectionOptions & options = ConnectionOptions{} ) const

Creates a M2N and establishes a primary connection between participants

Parameters
[in]acceptorthe accepting participant
[in]connectorthe requesting participant
[in]optionsa set of options concerning the created connection
Note
This function throws if the acceptor or connector are unknown!
See also
ConnectionOptions

Definition at line 251 of file TestContext.cpp.

Here is the call graph for this function:

◆ describe()

std::string precice::testing::TestContext::describe ( ) const

Provides a user- and log-friendly description of the current context.

Definition at line 288 of file TestContext.cpp.

Here is the call graph for this function:

◆ hasSize()

bool precice::testing::TestContext::hasSize ( int size) const

Check whether this context has a given size.

Definition at line 114 of file TestContext.cpp.

◆ initialize()

void precice::testing::TestContext::initialize ( const Participants & participants)
private

Main entrypoint.

Definition at line 149 of file TestContext.cpp.

Here is the call graph for this function:

◆ initializeEvents()

void precice::testing::TestContext::initializeEvents ( )
private

Initialize Events if required.

Definition at line 216 of file TestContext.cpp.

Here is the call graph for this function:

◆ initializeGinkgo()

void precice::testing::TestContext::initializeGinkgo ( )
private

Initialize Ginkgo if required.

Definition at line 240 of file TestContext.cpp.

Here is the call graph for this function:

◆ initializeIntraComm()

void precice::testing::TestContext::initializeIntraComm ( )
private

Initialize the intra-participant communication connection if requested.

Definition at line 191 of file TestContext.cpp.

Here is the call graph for this function:

◆ initializeMPI()

void precice::testing::TestContext::initializeMPI ( const Participants & participants)
private

Check, restrict and split the MPI communicator Marks unneeded contexts as invalid

Definition at line 160 of file TestContext.cpp.

Here is the call graph for this function:

◆ initializePetsc()

void precice::testing::TestContext::initializePetsc ( )
private

Initialize PETSc if required.

Definition at line 233 of file TestContext.cpp.

Here is the call graph for this function:

◆ isNamed()

bool precice::testing::TestContext::isNamed ( const std::string & name) const

Check whether this context has a given name.

Definition at line 119 of file TestContext.cpp.

Here is the call graph for this function:

◆ isPrimary()

bool precice::testing::TestContext::isPrimary ( ) const

Check whether this context is the primary rank of a participant

Note
This is equivalent to isRank(0)

Definition at line 135 of file TestContext.cpp.

Here is the call graph for this function:

◆ isRank()

bool precice::testing::TestContext::isRank ( Rank rank) const

Check whether this context has a given rank inside the Participant.

Definition at line 127 of file TestContext.cpp.

◆ prefix()

std::string precice::testing::TestContext::prefix ( const std::string & filename) const

Prefixes the given filename with the test directory.

The filename will be located in the same directory as the current test file.

Returns
the full filepath to the filename relative

Definition at line 101 of file TestContext.cpp.

Here is the call graph for this function:

◆ setContextFrom()

void precice::testing::TestContext::setContextFrom ( const ParticipantState & p)
private

set the context from a Participants and the current com Both uniquely identify a context.

See also
Par::current()

Definition at line 140 of file TestContext.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ _contextComm

utils::Parallel::CommStatePtr precice::testing::TestContext::_contextComm
private

the MPI communicator of the context

Definition at line 284 of file TestContext.hpp.

◆ _initIntraComm

bool precice::testing::TestContext::_initIntraComm = false
private

whether this context needs to initialize the intracomm

Definition at line 281 of file TestContext.hpp.

◆ _names

std::set<std::string> precice::testing::TestContext::_names
private

contains the name of every known Participant

Definition at line 287 of file TestContext.hpp.

◆ _setup

TestSetup precice::testing::TestContext::_setup
private

Definition at line 278 of file TestContext.hpp.

◆ invalid

bool precice::testing::TestContext::invalid = false

whether this context is valid or not

Definition at line 207 of file TestContext.hpp.

◆ name

std::string precice::testing::TestContext::name

the name of the current participant

Definition at line 198 of file TestContext.hpp.

◆ rank

Rank precice::testing::TestContext::rank = 0

the rank of the current participant

Definition at line 201 of file TestContext.hpp.

◆ size

int precice::testing::TestContext::size = 1

the size of the Communicator of the current participant

Definition at line 204 of file TestContext.hpp.


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