Debian Codegraph @

packages/stk/stk_unit_tests/stk_util/parallel/UnitTestParallelReduceBool.cpp

raw
1 #include "gtest/gtest.h"
2 #include "stk_util/parallel/Parallel.hpp"
3 #include "stk_util/parallel/ParallelReduceBool.hpp"
4
5 #ifdef STK_HAS_MPI
6
7 TEST(ParallelReduceBool, MPI_Cxx_Bool)
8 {
9 if (stk::util::get_common_coupling_version() < 7 &&
10 stk::util::get_common_coupling_version() >= 3)
11 {
12 EXPECT_NE(MPI_CXX_BOOL, MPI_DATATYPE_NULL);
13 }
14 }
15
16 //-----------------------------------------------------------------------------
17 // is_true_on_any_proc test
18
19 TEST(ParallelReduceBool, is_true_on_any_proc_all_true)
20 {
21 EXPECT_TRUE(stk::is_true_on_any_proc(MPI_COMM_WORLD, true));
22 }
23
24 TEST(ParallelReduceBool, is_true_on_any_proc_all_false)
25 {
26 EXPECT_FALSE(stk::is_true_on_any_proc(MPI_COMM_WORLD, false));
27 }
28
29 TEST(ParallelReduceBool, is_true_on_any_proc_one_true)
30 {
31 int comm_rank = stk::parallel_machine_rank(MPI_COMM_WORLD);
32 int comm_size = stk::parallel_machine_size(MPI_COMM_WORLD);
33
34 for (int i=0; i < comm_size; ++i)
35 {
36 bool val = comm_rank == i ? true : false;
37 EXPECT_TRUE(stk::is_true_on_any_proc(MPI_COMM_WORLD, val));
38 }
39 }
40
41 //-----------------------------------------------------------------------------
42 // is_true_on_all_procs tests
43
44 TEST(ParallelReduceBool, is_true_on_all_procs_all_true)
45 {
46 EXPECT_TRUE(stk::is_true_on_all_procs(MPI_COMM_WORLD, true));
47 }
48
49 TEST(ParallelReduceBool, is_true_on_all_procs_all_false)
50 {
51 EXPECT_FALSE(stk::is_true_on_all_procs(MPI_COMM_WORLD, false));
52 }
53
54 TEST(ParallelReduceBool, is_true_on_all_procs_one_true)
55 {
56 int comm_rank = stk::parallel_machine_rank(MPI_COMM_WORLD);
57 int comm_size = stk::parallel_machine_size(MPI_COMM_WORLD);
58
59 for (int i=0; i < comm_size; ++i)
60 {
61 bool val = comm_rank == i ? true : false;
62 if (comm_size > 1) {
63 EXPECT_FALSE(stk::is_true_on_all_procs(MPI_COMM_WORLD, val));
64 } else {
65 EXPECT_TRUE(stk::is_true_on_all_procs(MPI_COMM_WORLD, val));
66 }
67 }
68 }
69
70 #endif