// we can initialize MPI exactly once, so everything is clubbed into this test
TEST(MpiEnvTest, ExceptionsNoAbort) {
    int argc=1;
    char arg0[]="";
    char* args[]={arg0};
    char** argv=args;

    ASSERT_EQ(0, get_mpi_abort_called()) << "Unexpected initial global counter state";
    ASSERT_FALSE(mpi_is_up());

    try {
      alps::mpi::environment env(argc, argv, false);
        ASSERT_TRUE(mpi_is_up());

        try {
            alps::mpi::environment sub_env(argc, argv);
            throw std::exception();
        } catch (std::exception&) {
            ASSERT_FALSE(mpi_is_down());
            ASSERT_EQ(0, get_mpi_abort_called()) << "MPI_Abort should not be called";
            throw;
        }
    } catch (std::exception&) {
        // MPI env object is destroyed during active exception,
        // should not have called abort (but finalize MPI)
        ASSERT_EQ(0, get_mpi_abort_called()) << "MPI_Abort should not be called";
        ASSERT_TRUE(mpi_is_down());
    }
}
Example #2
0
// we can initialize MPI exactly once, so everything is clubbed into this test
TEST(MpiEnvTest, Environment) {
    int argc=1;
    char arg0[]="";
    char* args[]={arg0};
    char** argv=args;
    ASSERT_FALSE(mpi_is_up());
    ASSERT_FALSE(mpi_is_down());
    ASSERT_FALSE(alps::mpi::environment::initialized()) << "MPI Env should not be initialized";
    ASSERT_FALSE(alps::mpi::environment::finalized()) << "MPI Env should not be finalized";
    {
        alps::mpi::environment env(argc, argv);
        ASSERT_TRUE(mpi_is_up());
        ASSERT_FALSE(mpi_is_down());

        ASSERT_TRUE(alps::mpi::environment::initialized()) << "MPI Env should be initialized by now";
        ASSERT_FALSE(alps::mpi::environment::finalized()) << "MPI Env should not be finalized yet";

        {
            alps::mpi::environment sub_env(argc, argv);
            ASSERT_TRUE(mpi_is_up());
            ASSERT_FALSE(mpi_is_down());
        } // sub_env destroyed
        ASSERT_TRUE(mpi_is_up()) << "MPI should remain initialized after sub-object destruction";
        ASSERT_FALSE(mpi_is_down()) << "MPI should not be finalized after sub-object destruction";
    } // env destroyed

    ASSERT_TRUE(mpi_is_up());
    ASSERT_TRUE(mpi_is_down()) << "MPI should be finalized after environment destruction";

    ASSERT_TRUE(alps::mpi::environment::initialized()) << "MPI Env should be initialized after environment destruction";
    ASSERT_TRUE(alps::mpi::environment::finalized()) << "MPI Env should be finalized after environment destruction";
}