|
Boost Users : |
Subject: Re: [Boost-users] Boost test and openmpi
From: Martin Vymazal (martin.vymazal_at_[hidden])
Date: 2014-03-21 06:27:13
Hi,
it doesn't work for me. I tried the following code:
/// Generate automatically the 'main' function for the test module
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE mpi_test
#include <boost/test/unit_test.hpp>
#include <iostream>
#include "mpi.h"
struct MPIFixture
{
MPIFixture()
{
std::cout << "Global fixture constructor:" << std::endl;
int argc = boost::unit_test::framework::master_test_suite().argc;
char** argv = boost::unit_test::framework::master_test_suite().argv;
MPI_Init(&argc,&argv);
int is_initialized;
int is_finalized;
MPI_Initialized(&is_initialized);
MPI_Finalized(&is_finalized);
std::cout << "MPI environment is initialized: " << is_initialized <<
std::endl;
std::cout << "MPI environment is finalized: " << is_finalized <<
std::endl;
}
~MPIFixture()
{
std::cout << "Global fixture destructor" << std::endl;
int is_initialized;
int is_finalized;
MPI_Initialized(&is_initialized);
MPI_Finalized(&is_finalized);
std::cout << "MPI environment is initialized: " << is_initialized <<
std::endl;
std::cout << "MPI environment is finalized: " << is_finalized <<
std::endl;
MPI_Finalize();
MPI_Initialized(&is_initialized);
MPI_Finalized(&is_finalized);
std::cout << "MPI environment is initialized: " << is_initialized <<
std::endl;
std::cout << "MPI environment is finalized: " << is_finalized <<
std::endl;
}
};
struct MyTestSuiteFixture { };
BOOST_GLOBAL_FIXTURE( MPIFixture )
BOOST_FIXTURE_TEST_SUITE( MyTestSuite, MyTestSuiteFixture )
BOOST_AUTO_TEST_CASE( dummy_test )
{
std::cout << "Running dummy test case" << std::endl;
}
BOOST_AUTO_TEST_SUITE_END()
The output when running with mpirun:
Global fixture constructor:
MPI environment is initialized: 1
MPI environment is finalized: 0
Running 1 test case...
Running dummy test case
Global fixture destructor
MPI environment is initialized: 1
MPI environment is finalized: 0
MPI environment is initialized: 1
MPI environment is finalized: 1
Output when running directly the executable:
Global fixture constructor:
MPI environment is initialized: 1
MPI environment is finalized: 0
Running 1 test case...
Running dummy test case
Global fixture destructor
MPI environment is initialized: 1
MPI environment is finalized: 0
Segmentation fault (core dumped)
I'm using boost 1.55.0 and gcc 4.8.2 on linux.
Best regards,
Martin Vymazal
On Friday 21 February 2014 10:38:21 Rhys Ulerich wrote:
> > A global fixture seems like a more appropriate solution than implementing
> > main().
> >
> > BOOST_GLOBAL_FIXTURE
>
> Indeed. Something like the following works just fine:
>
> struct MPIFixture {
> MPIFixture() { MPI_Init(NULL, NULL); }
> ~MPIFixture() { MPI_Finalize(); }
> };
> BOOST_GLOBAL_FIXTURE(MPIFixture);
>
>
> - Rhys
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net