1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #include <exception>
8 #include <alps/utilities/mpi.hpp>
9 
10 #include <gtest/gtest.h>
11 
12 #include "mpi_test_support.hpp"
13 
14 /* Test MPI environment wrapper functionality: abort on exceptions. */
15 
16 // we can initialize MPI exactly once, so everything is clubbed into this test
TEST(MpiEnvTest,ExceptionsAbort)17 TEST(MpiEnvTest, ExceptionsAbort) {
18     int argc=1;
19     char arg0[]="";
20     char* args[]={arg0};
21     char** argv=args;
22 
23     ASSERT_EQ(0, get_mpi_abort_called()) << "Unexpected initial global counter state";
24     ASSERT_FALSE(mpi_is_up());
25 
26     try {
27         alps::mpi::environment env(argc, argv);
28         ASSERT_TRUE(mpi_is_up());
29 
30         try {
31             alps::mpi::environment sub_env(argc, argv);
32             throw std::exception();
33         } catch (std::exception&) {
34             ASSERT_FALSE(mpi_is_down());
35             ASSERT_EQ(0, get_mpi_abort_called()) << "MPI_Abort should not be called";
36             throw;
37         }
38     } catch (std::exception&) {
39         // MPI env object is destroyed during active exception,
40         // should have called abort (and finalize MPI)
41         ASSERT_EQ(1, get_mpi_abort_called()) << "MPI_Abort should be called by now";
42         ASSERT_TRUE(mpi_is_down());
43     }
44 }
45 
46