Using Boost::Test for parallel code
boost, c++, mpi, unit-testing
Solution
Boost Test has fixture support, which allows you to perform setup/cleanup per test case, test suite, or globally. Sounds like you should put the call to `MPI::Init` in a global fixture.
struct MPIFixture {
MPIFixture() { MPI::Init(); }
~MPIFixture() { /* I bet there's a deinit you should call */ }
};
BOOST_GLOBAL_FIXTURE(MPIFixture);
If you have trouble working with that, or if you are working in a framework that provides its own `main` function, then you can `#define BOOST_TEST_NO_MAIN` before including the Boost headers. Then you can invoke `boost::unit_test::unit_test_main` yourself to run your test suites.
Problem
I want to create some tests with boost::unit_test for my parallel (mpi based) C++ codes. I have some basic experiences in using the test framework. For me the main problem, when going to parallel codes, is where to put MPI::Init, such that it is called first. In the test suites I have created there is no main function. Furthermore, does Boost::Test exists correctly (with respect to mpi) when some assertions fail on a subset of the existing ranks?