COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-parallel-datatype.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 //
7 // IMPORTANT:
8 // run it both on 1 and many cores
9 // for example: mpirun -np 4 ./test-parallel-environment --report_level=confirm or --report_level=detailed
10 
11 #define BOOST_TEST_DYN_LINK
12 #define BOOST_TEST_MODULE "Test module for cf3::common 's parallel environment - part of checking datatype handling."
13 
15 
16 #include <boost/test/unit_test.hpp>
17 
18 #include "common/Log.hpp"
19 #include "common/PE/Comm.hpp"
20 #include "common/PE/datatype.hpp"
21 
22 #include "common/PE/debug.hpp"
23 
25 
26 using namespace cf3;
27 using namespace cf3::common;
28 
30 
32 {
35  {
36  m_argc = boost::unit_test::framework::master_test_suite().argc;
37  m_argv = boost::unit_test::framework::master_test_suite().argv;
38  }
39 
42 
44  int m_argc;
45  char** m_argv;
46 
49  {
50  int i1,i2,i3,i4,i5;
51  };
53  {
54  double d1,d2,d3,d4,d5,d6,d7,d8,d9;
55  };
57  {
58  char c1,c2,c3,c4,c5,c6,c7;
59  };
60 };
61 
63 
67 
69 
70 BOOST_FIXTURE_TEST_SUITE( PEDatatypeSuite, PEDatatypeFixture )
71 
72 
75 {
76  PE::Comm::instance().init(m_argc,m_argv);
77  BOOST_CHECK_EQUAL( PE::Comm::instance().is_active() , true );
78  PEProcessSortedExecute(-1,CFinfo << "Proccess " << PE::Comm::instance().rank() << "/" << PE::Comm::instance().size() << " reports in." << CFendl;);
79 }
80 
82 
83 BOOST_AUTO_TEST_CASE( datatype_default_types )
84 {
85  char test_char;
86  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_char),MPI_CHAR);
87  unsigned char test_unsigned_char;
88  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_unsigned_char),MPI_UNSIGNED_CHAR);
89  short test_short;
90  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_short),MPI_SHORT);
91  unsigned short test_unsigned_short;
92  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_unsigned_short),MPI_UNSIGNED_SHORT);
93  int test_int;
94  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_int),MPI_INT);
95  unsigned int test_unsigned_int;
96  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_unsigned_int),MPI_UNSIGNED);
97  long test_long;
98  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_long),MPI_LONG);
99  unsigned long test_unsigned_long;
100  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_unsigned_long),MPI_UNSIGNED_LONG);
101  long long test_long_long;
102  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_long_long),MPI_LONG_LONG);
103  unsigned long long test_unsigned_long_long;
104  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_unsigned_long_long),MPI_UNSIGNED_LONG_LONG);
105  float test_float;
106  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_float),MPI_FLOAT);
107  double test_double;
108  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_double),MPI_DOUBLE);
109  long double test_long_double;
110  BOOST_CHECK_EQUAL(PE::get_mpi_datatype(test_long_double),MPI_LONG_DOUBLE);
111 }
112 
114 
115 BOOST_AUTO_TEST_CASE( datatype_registered_types )
116 {
117  // check if registering goes fine
118  user_struct_i usi;
120  BOOST_CHECK_NE(mpi_datatype_usi,(PE::Datatype)nullptr);
121  user_struct_d usd;
123  BOOST_CHECK_NE(mpi_datatype_usd,(PE::Datatype)nullptr);
124 
125  // check if no glitch and separate types go to separate static variables
126  BOOST_CHECK_NE(mpi_datatype_usd,mpi_datatype_usi);
127 
128  // check if re-registration does not alter the Datatype (avoid committing the same type over and over)
129  BOOST_CHECK_EQUAL(mpi_datatype_usi,PE::get_mpi_datatype(usi));
130  BOOST_CHECK_EQUAL(mpi_datatype_usd,PE::get_mpi_datatype(usd));
131 }
132 
134 
135 BOOST_AUTO_TEST_CASE( datatype_registered_types_are_really_static )
136 {
137  // check if re-registration does not alter the Datatype (avoid committing the same type over and over)
138  user_struct_i usi;
139  BOOST_CHECK_EQUAL(mpi_datatype_usi,PE::get_mpi_datatype(usi));
140  user_struct_d usd;
141  BOOST_CHECK_EQUAL(mpi_datatype_usd,PE::get_mpi_datatype(usd));
142 }
143 
145 
146 BOOST_AUTO_TEST_CASE( internal_mechanism_returns_nullptr_for_non_registered_types )
147 {
148  // detail::get_mpi
149  // this is just to be sure that nothing fishy happens if data type is unknown,
150  // normally you shouldn't call ::detail functions
151  user_struct_c usc;
152  BOOST_CHECK_EQUAL(PE::detail::get_mpi_datatype_impl(usc),(PE::Datatype)nullptr);
153 }
154 
156 
158 {
159  PEProcessSortedExecute(-1,CFinfo << "Proccess " << PE::Comm::instance().rank() << "/" << PE::Comm::instance().size() << " says good bye." << CFendl;);
161  BOOST_CHECK_EQUAL( PE::Comm::instance().is_active() , false );
162 }
163 
165 
166 BOOST_AUTO_TEST_SUITE_END()
167 
168 
170 
#define CFinfo
these are always defined
Definition: Log.hpp:104
MPI_Datatype Datatype
datatype
Definition: types.hpp:47
Datatype get_mpi_datatype(const T &ref_of_type)
ACCESS AND REGISTRATION MECHANISM.
Definition: datatype.hpp:49
#define CFendl
Definition: Log.hpp:109
PE::Datatype mpi_datatype_usi
data stays in scope for checking if registration is really static
Datatype get_mpi_datatype_impl(const T &)
Definition: datatype.hpp:43
void init(int argc=0, char **args=0)
Definition: Comm.cpp:80
Top-level namespace for coolfluid.
Definition: Action.cpp:18
BOOST_AUTO_TEST_CASE(init)
~PEDatatypeFixture()
coemmon tear-down for each test case
PE::Datatype mpi_datatype_usd
PEDatatypeFixture()
common setup for each test case
static Comm & instance()
Return a reference to the current PE.
Definition: Comm.cpp:44
Most basic kernel library.
Definition: Action.cpp:19
#define PEProcessSortedExecute(irank, expression)
Definition: debug.hpp:43
Send comments to:
COOLFluiD Web Admin