preCICE v3.1.2
Loading...
Searching...
No Matches
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 () 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 &requestor, const ConnectionOptions &options=ConnectionOptions{}) const
 
std::string describe () const
 Provides a user- and log-friendly description of the current context.
 
Construction
 TestContext ()=default
 Create a context representing an unnamed serial Participant.
 
template<class... T>
 TestContext (Ranks ranks)
 
template<class... T>
 TestContext (Ranks ranks, T... args)
 
template<class... T>
 TestContext (T... args)
 

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)
 
Option Handling
void handleOption (Participants &participants, ParticipantState participant)
 
void handleOption (Participants &participants, testing::Require requirement)
 
template<class LastOption >
void handleOptions (Participants &participants, LastOption &last)
 
template<class NextOption , class... Rest>
void handleOptions (Participants &participants, NextOption &next, Rest &... rest)
 
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.
 

Private Attributes

bool _petsc = false
 whether to initialize PETSc
 
bool _events = false
 whether to initialize events
 
bool _simple = false
 whether this Context was created with a Ranks constructor
 
bool _initIntraComm = false
 whether to initialize an intra-participant connection
 
utils::Parallel::CommStatePtr _contextComm
 the MPI communicator of the context
 
std::vector< 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() 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 152 of file TestContext.hpp.

Member Typedef Documentation

◆ Participants

Definition at line 154 of file TestContext.hpp.

Constructor & Destructor Documentation

◆ TestContext() [1/4]

precice::testing::TestContext::TestContext ( )
default

Create a context representing an unnamed serial Participant.

◆ TestContext() [2/4]

template<class... T>
precice::testing::TestContext::TestContext ( Ranks ranks)
inline

Create a context representing an unnamed Participant running on a given count of Ranks

Note
You need to construct a Participant if you require initializing an intra-participant connection "Serial"_on(3_ranks).setupIntraComm()
Attention
This call synchronizes all ranks

Definition at line 183 of file TestContext.hpp.

Here is the call graph for this function:

◆ TestContext() [3/4]

template<class... T>
precice::testing::TestContext::TestContext ( Ranks ranks,
T... args )
inline

Create a context representing an unnamed Participant running on a given count of Ranks and some requirements

Note
You need to construct a Participant if you require initializing an intra-participant connection "Serial"_on(3_ranks).setupIntraComm()
Attention
This call synchronizes all ranks
See also
Require

Definition at line 200 of file TestContext.hpp.

Here is the call graph for this function:

◆ TestContext() [4/4]

template<class... T>
precice::testing::TestContext::TestContext ( T... args)
inline

Create a context representing one or more participants

Attention
This call synchronizes all ranks
See also
Require

Definition at line 215 of file TestContext.hpp.

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 33 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 257 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 60 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 & requestor,
const ConnectionOptions & options = ConnectionOptions{} ) const

Creates a M2N and establishes a primary connection between participants

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

Definition at line 216 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 252 of file TestContext.cpp.

Here is the call graph for this function:

◆ handleOption() [1/2]

void precice::testing::TestContext::handleOption ( Participants & participants,
ParticipantState participant )
private

Definition at line 107 of file TestContext.cpp.

Here is the call graph for this function:

◆ handleOption() [2/2]

void precice::testing::TestContext::handleOption ( Participants & participants,
testing::Require requirement )
private

Definition at line 91 of file TestContext.cpp.

Here is the call graph for this function:

◆ handleOptions() [1/2]

template<class LastOption >
void precice::testing::TestContext::handleOptions ( Participants & participants,
LastOption & last )
inlineprivate

Definition at line 306 of file TestContext.hpp.

Here is the call graph for this function:

◆ handleOptions() [2/2]

template<class NextOption , class... Rest>
void precice::testing::TestContext::handleOptions ( Participants & participants,
NextOption & next,
Rest &... rest )
inlineprivate

Definition at line 312 of file TestContext.hpp.

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 65 of file TestContext.cpp.

◆ initialize()

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

Main entrypoint.

Definition at line 126 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 192 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 167 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 136 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 209 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 70 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 86 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 78 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 52 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 117 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 295 of file TestContext.hpp.

◆ _events

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

whether to initialize events

Definition at line 286 of file TestContext.hpp.

◆ _initIntraComm

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

whether to initialize an intra-participant connection

Definition at line 292 of file TestContext.hpp.

◆ _names

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

contains the name of every known Participant

Definition at line 298 of file TestContext.hpp.

◆ _petsc

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

whether to initialize PETSc

Definition at line 283 of file TestContext.hpp.

◆ _simple

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

whether this Context was created with a Ranks constructor

Definition at line 289 of file TestContext.hpp.

◆ invalid

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

whether this context is valid or not

Definition at line 166 of file TestContext.hpp.

◆ name

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

the name of the current participant

Definition at line 157 of file TestContext.hpp.

◆ rank

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

the rank of the current participant

Definition at line 160 of file TestContext.hpp.

◆ size

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

the size of the Communicator of the current participant

Definition at line 163 of file TestContext.hpp.


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