Sierra Toolkit  Version of the Day
UnitTestDataTraits.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 
10 #include <stddef.h>
11 #include <stdexcept>
12 #include <sstream>
13 
14 #include <stk_util/parallel/Parallel.hpp>
15 
16 #include <stk_mesh/base/DataTraits.hpp>
17 #include <stk_mesh/base/DataTraitsEnum.hpp>
18 #include <stk_mesh/base/DataTraitsClass.hpp>
19 
20 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
21 
22 using stk_classic::mesh::DataTraits;
23 using stk_classic::mesh::data_traits;
24 using stk_classic::CommAll;
25 
26 //----------------------------------------------------------------------
27 
28 namespace {
29 
30 STKUNIT_UNIT_TEST(TestDataTraits, testVoid)
31 {
32  // Test the DataTrait for void
33 
34  stk_classic::ParallelMachine pm = MPI_COMM_WORLD;
35  MPI_Barrier( pm );
36 
37  const DataTraits & traits = data_traits<void>();
38 
39  STKUNIT_ASSERT( traits.type_info == typeid(void) );
40  STKUNIT_ASSERT_EQUAL( traits.size_of , size_t(0) );
41  STKUNIT_ASSERT_EQUAL( traits.alignment_of , size_t(0) );
42  STKUNIT_ASSERT_EQUAL( traits.stride_of , size_t(0) );
43  STKUNIT_ASSERT_EQUAL( traits.is_void , true );
44  STKUNIT_ASSERT_EQUAL( traits.is_integral , false );
45  STKUNIT_ASSERT_EQUAL( traits.is_floating_point , false );
46  STKUNIT_ASSERT_EQUAL( traits.is_array , false );
47  STKUNIT_ASSERT_EQUAL( traits.is_pointer , false );
48  STKUNIT_ASSERT_EQUAL( traits.is_enum , false );
49  STKUNIT_ASSERT_EQUAL( traits.is_class , false );
50  STKUNIT_ASSERT_EQUAL( traits.is_pod , false );
51  STKUNIT_ASSERT_EQUAL( traits.is_signed , false );
52  STKUNIT_ASSERT_EQUAL( traits.is_unsigned , false );
53 
54  STKUNIT_ASSERT( ! traits.remove_pointer );
55  STKUNIT_ASSERT( traits.enum_info.empty() );
56  STKUNIT_ASSERT( traits.class_info.empty() );
57 
58  STKUNIT_ASSERT_THROW( traits.construct( NULL , 0 ) , std::runtime_error );
59  STKUNIT_ASSERT_THROW( traits.destroy( NULL , 0 ) , std::runtime_error );
60  STKUNIT_ASSERT_THROW( traits.copy( NULL , NULL , 0 ) , std::runtime_error );
61  STKUNIT_ASSERT_THROW( traits.sum( NULL , NULL , 0 ) , std::runtime_error );
62  STKUNIT_ASSERT_THROW( traits.max( NULL , NULL , 0 ) , std::runtime_error );
63  STKUNIT_ASSERT_THROW( traits.min( NULL , NULL , 0 ) , std::runtime_error );
64  STKUNIT_ASSERT_THROW( traits.bit_and( NULL, NULL, 0 ), std::runtime_error );
65  STKUNIT_ASSERT_THROW( traits.bit_or( NULL , NULL, 0 ), std::runtime_error );
66  STKUNIT_ASSERT_THROW( traits.bit_xor( NULL, NULL, 0 ), std::runtime_error );
67  STKUNIT_ASSERT_THROW( traits.print( std::cout, NULL, 0), std::runtime_error);
68 
69  CommAll comm( pm );
70  STKUNIT_ASSERT_THROW( traits.pack( comm.send_buffer(0) , NULL , 0 ), std::runtime_error );
71  comm.allocate_buffers( 0 );
72  comm.communicate();
73  STKUNIT_ASSERT_THROW( traits.unpack( comm.recv_buffer(0) , NULL , 0 ), std::runtime_error );
74 }
75 
76 //----------------------------------------------------------------------
77 
78 template< typename T , bool is_integral , bool is_signed >
79 void test_fundamental_type()
80 {
81  // Test DataTrait for fundamental type T
82 
83  stk_classic::ParallelMachine pm = MPI_COMM_WORLD;
84  int p_rank = stk_classic::parallel_machine_rank( pm );
85  int p_size = stk_classic::parallel_machine_size( pm );
86  MPI_Barrier( pm );
87 
88  // Test data trait properties of type T
89  const DataTraits & traits = data_traits<T>();
90  STKUNIT_ASSERT( traits.type_info == typeid(T) );
91  STKUNIT_ASSERT_EQUAL( traits.size_of , sizeof(T) );
92  STKUNIT_ASSERT_EQUAL( traits.alignment_of , sizeof(T) );
93  STKUNIT_ASSERT_EQUAL( traits.stride_of , sizeof(T) );
94  STKUNIT_ASSERT_EQUAL( traits.is_void , false );
95  STKUNIT_ASSERT_EQUAL( traits.is_integral , is_integral );
96  STKUNIT_ASSERT_EQUAL( traits.is_floating_point , ! is_integral );
97  STKUNIT_ASSERT_EQUAL( traits.is_array , false );
98  STKUNIT_ASSERT_EQUAL( traits.is_pointer , false );
99  STKUNIT_ASSERT_EQUAL( traits.is_enum , false );
100  STKUNIT_ASSERT_EQUAL( traits.is_class , false );
101  STKUNIT_ASSERT_EQUAL( traits.is_pod , true );
102  STKUNIT_ASSERT_EQUAL( traits.is_signed , is_signed );
103  STKUNIT_ASSERT_EQUAL( traits.is_unsigned , is_integral && ! is_signed);
104 
105  STKUNIT_ASSERT( ! traits.remove_pointer );
106  STKUNIT_ASSERT( traits.enum_info.empty() );
107  STKUNIT_ASSERT( traits.class_info.empty() );
108 
109  const unsigned array_size = 3;
110  const T a[array_size] = { T(1) , T(2) , T(4) };
111  T b[array_size] ;
112 
113  // Test data trait basic operations on type T
114  traits.construct( b , array_size );
115  STKUNIT_ASSERT_EQUAL( T(0) , b[0] );
116  STKUNIT_ASSERT_EQUAL( T(0) , b[1] );
117  STKUNIT_ASSERT_EQUAL( T(0) , b[2] );
118 
119  traits.copy( b , a , array_size );
120  STKUNIT_ASSERT_EQUAL( T(1) , b[0] );
121  STKUNIT_ASSERT_EQUAL( T(2) , b[1] );
122  STKUNIT_ASSERT_EQUAL( T(4) , b[2] );
123 
124  traits.sum( b , a , array_size );
125  STKUNIT_ASSERT_EQUAL( T(2) , b[0] );
126  STKUNIT_ASSERT_EQUAL( T(4) , b[1] );
127  STKUNIT_ASSERT_EQUAL( T(8) , b[2] );
128 
129  traits.min( b , a , array_size );
130  STKUNIT_ASSERT_EQUAL( T(1) , b[0] );
131  STKUNIT_ASSERT_EQUAL( T(2) , b[1] );
132  STKUNIT_ASSERT_EQUAL( T(4) , b[2] );
133 
134  traits.sum( b , a , array_size );
135  traits.max( b , a , array_size );
136  STKUNIT_ASSERT_EQUAL( T(2) , b[0] );
137  STKUNIT_ASSERT_EQUAL( T(4) , b[1] );
138  STKUNIT_ASSERT_EQUAL( T(8) , b[2] );
139 
140  if ( is_integral ) {
141  // Test integral-specific operations
142  traits.bit_or( b , a , array_size );
143  STKUNIT_ASSERT_EQUAL( T(3) , b[0] );
144  STKUNIT_ASSERT_EQUAL( T(6) , b[1] );
145  STKUNIT_ASSERT_EQUAL( T(12) , b[2] );
146 
147  traits.bit_and( b , a , array_size );
148  STKUNIT_ASSERT_EQUAL( T(1) , b[0] );
149  STKUNIT_ASSERT_EQUAL( T(2) , b[1] );
150  STKUNIT_ASSERT_EQUAL( T(4) , b[2] );
151 
152  traits.bit_xor( b , a , array_size );
153  STKUNIT_ASSERT_EQUAL( T(0) , b[0] );
154  STKUNIT_ASSERT_EQUAL( T(0) , b[1] );
155  STKUNIT_ASSERT_EQUAL( T(0) , b[2] );
156  }
157  else {
158  // Test unsupported operations
159  STKUNIT_ASSERT_THROW(traits.bit_or (b, a, array_size), std::runtime_error);
160  STKUNIT_ASSERT_THROW(traits.bit_and(b, a, array_size), std::runtime_error);
161  STKUNIT_ASSERT_THROW(traits.bit_xor(b, a, array_size), std::runtime_error);
162  }
163 
164  // Test data trait pack/unpack (communication) of type T
165  traits.construct( b , array_size );
166  CommAll comm( pm );
167  traits.pack( comm.send_buffer(0) , a , array_size );
168  comm.allocate_buffers( 0 );
169  traits.pack( comm.send_buffer(0) , a , array_size );
170  comm.communicate();
171  if (p_rank == 0) {
172  for (int proc_id = 0; proc_id < p_size; ++proc_id) {
173  traits.unpack( comm.recv_buffer(proc_id) , b , array_size );
174  STKUNIT_ASSERT_EQUAL( T(1) , b[0] );
175  STKUNIT_ASSERT_EQUAL( T(2) , b[1] );
176  STKUNIT_ASSERT_EQUAL( T(4) , b[2] );
177  }
178  }
179 
180  // Test data trait print of type T
181  std::ostringstream oss;
182  oss << traits.name << " " ;
183  traits.print( oss , a , array_size );
184  oss << std::endl ;
185 
186  // Test data trait destruction (no-op in this case)
187  traits.destroy( b , array_size );
188 }
189 
190 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_bool)
191 {
192  test_fundamental_type<char, true, true>();
193 }
194 
195 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_unsignedchar)
196 {
197  test_fundamental_type<unsigned char, true, false>();
198 }
199 
200 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_short)
201 {
202  test_fundamental_type<short, true, true>();
203 }
204 
205 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_unsignedshort)
206 {
207  test_fundamental_type<unsigned short, true, false>();
208 }
209 
210 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_int)
211 {
212  test_fundamental_type<int, true, true>();
213 }
214 
215 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_unsignedint)
216 {
217  test_fundamental_type<unsigned int, true, false>();
218 }
219 
220 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_long)
221 {
222  test_fundamental_type<long, true, true>();
223 }
224 
225 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_unsignedlong)
226 {
227  test_fundamental_type<unsigned long, true, false>();
228 }
229 
230 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_float)
231 {
232  test_fundamental_type<float, false, false>();
233 }
234 
235 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_double)
236 {
237  test_fundamental_type<double, false, false>();
238 }
239 
240 //----------------------------------------------------------------------
241 
242 template< typename T >
243 void test_fundamental_pointer()
244 {
245  // Test DataTrait for fundamenter pointer type T*
246 
247  stk_classic::ParallelMachine pm = MPI_COMM_WORLD;
248  MPI_Barrier( pm );
249 
250  // Test data trait properties of type T*
251  const DataTraits & traits = data_traits<T*>();
252  STKUNIT_ASSERT( traits.type_info == typeid(T*) );
253  STKUNIT_ASSERT_EQUAL( traits.size_of , sizeof(T*) );
254  STKUNIT_ASSERT_EQUAL( traits.alignment_of , sizeof(T*) );
255  STKUNIT_ASSERT_EQUAL( traits.stride_of , sizeof(T*) );
256  STKUNIT_ASSERT_EQUAL( traits.is_void , false );
257  STKUNIT_ASSERT_EQUAL( traits.is_integral , false );
258  STKUNIT_ASSERT_EQUAL( traits.is_floating_point , false );
259  STKUNIT_ASSERT_EQUAL( traits.is_array , false );
260  STKUNIT_ASSERT_EQUAL( traits.is_pointer , true );
261  STKUNIT_ASSERT_EQUAL( traits.is_enum , false );
262  STKUNIT_ASSERT_EQUAL( traits.is_class , false );
263  STKUNIT_ASSERT_EQUAL( traits.is_pod , false );
264  STKUNIT_ASSERT_EQUAL( traits.is_signed , false );
265  STKUNIT_ASSERT_EQUAL( traits.is_unsigned , false );
266 
267  STKUNIT_ASSERT( traits.remove_pointer == & data_traits<T>() );
268  STKUNIT_ASSERT( traits.enum_info.empty() );
269  STKUNIT_ASSERT( traits.class_info.empty() );
270 
271  const unsigned array_size = 3;
272  T val[array_size] = { T(1) , T(2) , T(4) };
273  T * const a[array_size] = { val , val + 1 , val + 2 };
274  T * b[array_size] ;
275 
276  // Test data trait basic operations on type T*
277  traits.construct( b , array_size );
278  STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[0] );
279  STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[1] );
280  STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[2] );
281 
282  traits.copy( b , a , array_size );
283  STKUNIT_ASSERT_EQUAL( val + 0 , b[0] );
284  STKUNIT_ASSERT_EQUAL( val + 1 , b[1] );
285  STKUNIT_ASSERT_EQUAL( val + 2 , b[2] );
286 
287  traits.destroy( b , array_size );
288  STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[0] );
289  STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[1] );
290  STKUNIT_ASSERT_EQUAL( static_cast<T*>(NULL) , b[2] );
291 
292  // Test unsupported operations
293  STKUNIT_ASSERT_THROW(traits.sum (b, a, array_size), std::runtime_error);
294  STKUNIT_ASSERT_THROW(traits.max (b, a, array_size), std::runtime_error);
295  STKUNIT_ASSERT_THROW(traits.min (b, a, array_size), std::runtime_error);
296  STKUNIT_ASSERT_THROW(traits.bit_and(b, a, array_size), std::runtime_error);
297  STKUNIT_ASSERT_THROW(traits.bit_or( b, a, array_size), std::runtime_error);
298  STKUNIT_ASSERT_THROW(traits.bit_xor(b, a, array_size), std::runtime_error);
299  STKUNIT_ASSERT_THROW(traits.print (std::cout, NULL, 0), std::runtime_error);
300 
301  CommAll comm( pm );
302  STKUNIT_ASSERT_THROW( traits.pack( comm.send_buffer(0) , a , array_size ), std::runtime_error );
303  comm.allocate_buffers( 0 );
304  comm.communicate();
305  STKUNIT_ASSERT_THROW( traits.unpack( comm.recv_buffer(0) , b , array_size ), std::runtime_error );
306 }
307 
308 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_char_ptr)
309 {
310  test_fundamental_pointer<char>();
311 }
312 
313 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_unsignedchar_ptr)
314 {
315  test_fundamental_pointer<unsigned char>();
316 }
317 
318 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_short_ptr)
319 {
320  test_fundamental_pointer<short>();
321 }
322 
323 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_unsignedshort_ptr)
324 {
325  test_fundamental_pointer<unsigned short>();
326 }
327 
328 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_int_ptr)
329 {
330  test_fundamental_pointer<int>();
331 }
332 
333 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_unsignedint_ptr)
334 {
335  test_fundamental_pointer<unsigned int>();
336 }
337 
338 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_long_ptr)
339 {
340  test_fundamental_pointer<long>();
341 }
342 
343 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_unsignedlong_ptr)
344 {
345  test_fundamental_pointer<unsigned long>();
346 }
347 
348 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_float_ptr)
349 {
350  test_fundamental_pointer<float>();
351 }
352 
353 STKUNIT_UNIT_TEST(TestDataTraits, testFundamental_double_ptr)
354 {
355  test_fundamental_pointer<double>();
356 }
357 
358 }
359 //----------------------------------------------------------------------
360 
361 #ifndef __PGI
362 
363 enum EType { val_a = 'a' , val_b = 'b' , val_c = 'c' };
364 
365 namespace stk_classic {
366 namespace mesh {
367 
368 // This enum will only work within the stk_classic::mesh namespace
369 DATA_TRAITS_ENUM_3( EType , val_a , val_b , val_c )
370 
371 }
372 }
373 
374 namespace {
375 
376 STKUNIT_UNIT_TEST(TestDataTraits, testEnum)
377 {
378  // Test interaction of DataTraits with enums
379 
380  stk_classic::ParallelMachine pm = MPI_COMM_WORLD;
381  int p_rank = stk_classic::parallel_machine_rank( pm );
382  int p_size = stk_classic::parallel_machine_size( pm );
383  MPI_Barrier( pm );
384 
385  typedef EType T ;
386  const DataTraits & traits = data_traits<T>();
387 
388  // Test data trait properties of enum type
389  STKUNIT_ASSERT( traits.type_info == typeid(T) );
390  STKUNIT_ASSERT_EQUAL( traits.size_of , sizeof(T) );
391  STKUNIT_ASSERT_EQUAL( traits.alignment_of , sizeof(T) );
392  STKUNIT_ASSERT_EQUAL( traits.stride_of , sizeof(T) );
393  STKUNIT_ASSERT_EQUAL( traits.is_integral , false );
394  STKUNIT_ASSERT_EQUAL( traits.is_floating_point , false );
395  STKUNIT_ASSERT_EQUAL( traits.is_array , false );
396  STKUNIT_ASSERT_EQUAL( traits.is_pointer , false );
397  STKUNIT_ASSERT_EQUAL( traits.is_enum , true );
398  STKUNIT_ASSERT_EQUAL( traits.is_class , false );
399  STKUNIT_ASSERT_EQUAL( traits.is_pod , true );
400  STKUNIT_ASSERT_EQUAL( traits.is_signed , false );
401  STKUNIT_ASSERT_EQUAL( traits.is_unsigned , false );
402 
403  STKUNIT_ASSERT( ! traits.remove_pointer );
404  STKUNIT_ASSERT( traits.class_info.empty() );
405 
406  STKUNIT_ASSERT_EQUAL( traits.enum_info.size() , size_t(3) );
407  STKUNIT_ASSERT_EQUAL( (traits.enum_info[0].name == "val_a"), true );
408  STKUNIT_ASSERT_EQUAL( (traits.enum_info[1].name == "val_b"), true );
409  STKUNIT_ASSERT_EQUAL( (traits.enum_info[2].name == "val_c"), true );
410  STKUNIT_ASSERT_EQUAL( traits.enum_info[0].value , long(val_a) );
411  STKUNIT_ASSERT_EQUAL( traits.enum_info[1].value , long(val_b) );
412  STKUNIT_ASSERT_EQUAL( traits.enum_info[2].value , long(val_c) );
413 
414  const unsigned array_size = 3;
415  EType a[array_size] = { val_a , val_b , val_c };
416  EType b[array_size] ;
417 
418  // Test data trait basic operations on enum type
419  traits.construct( b , array_size );
420  STKUNIT_ASSERT_EQUAL( val_a , b[0] );
421  STKUNIT_ASSERT_EQUAL( val_a , b[1] );
422  STKUNIT_ASSERT_EQUAL( val_a , b[2] );
423 
424  traits.copy( b , a , array_size );
425  STKUNIT_ASSERT_EQUAL( a[0] , b[0] );
426  STKUNIT_ASSERT_EQUAL( a[1] , b[1] );
427  STKUNIT_ASSERT_EQUAL( a[2] , b[2] );
428 
429  b[0] = val_b ; b[1] = val_b ; b[2] = val_b ;
430 
431  traits.min( b , a , array_size );
432  STKUNIT_ASSERT_EQUAL( val_a , b[0] );
433  STKUNIT_ASSERT_EQUAL( val_b , b[1] );
434  STKUNIT_ASSERT_EQUAL( val_b , b[2] );
435 
436  b[0] = val_b ; b[1] = val_b ; b[2] = val_b ;
437 
438  traits.max( b , a , array_size );
439  STKUNIT_ASSERT_EQUAL( val_b , b[0] );
440  STKUNIT_ASSERT_EQUAL( val_b , b[1] );
441  STKUNIT_ASSERT_EQUAL( val_c , b[2] );
442 
443  // Test unsupported operations
444  STKUNIT_ASSERT_THROW(traits.sum (b, a, array_size), std::runtime_error);
445  STKUNIT_ASSERT_THROW(traits.bit_and(b, a, array_size), std::runtime_error);
446  STKUNIT_ASSERT_THROW(traits.bit_or (b, a, array_size), std::runtime_error);
447  STKUNIT_ASSERT_THROW(traits.bit_xor(b, a, array_size), std::runtime_error);
448 
449  // Test pack/unpack (communication) of enum type
450  traits.construct( b , array_size );
451  CommAll comm( pm );
452  traits.pack( comm.send_buffer(0) , a , array_size );
453  comm.allocate_buffers( 0 );
454  traits.pack( comm.send_buffer(0) , a , array_size );
455  comm.communicate();
456  if (p_rank == 0) {
457  for (int proc_id = 0; proc_id < p_size; ++proc_id) {
458  traits.unpack( comm.recv_buffer(proc_id) , b , array_size );
459  STKUNIT_ASSERT_EQUAL( a[0] , b[0] );
460  STKUNIT_ASSERT_EQUAL( a[1] , b[1] );
461  STKUNIT_ASSERT_EQUAL( a[2] , b[2] );
462  }
463  }
464 
465  // Test printing of enum type
466  std::ostringstream oss;
467  b[2] = static_cast<EType>( 'd' );
468  oss << traits.name << " " ;
469  traits.print( oss , b , array_size );
470  oss << std::endl ;
471 
472  // Test destruction of enum type (no-op in this case)
473  traits.destroy( b , array_size );
474 }
475 
476 }
477 
478 //----------------------------------------------------------------------
479 
480 struct Vec3 { double x , y , z ; };
481 
482 namespace stk_classic {
483 namespace mesh {
484 
485 // This enum will only work within the stk_classic::mesh namespace
486 DATA_TRAITS_POD_CLASS_3( Vec3 , x , y , z )
487 
488 }
489 }
490 
491 namespace {
492 
493 STKUNIT_UNIT_TEST(TestDataTraits, testClass)
494 {
495  // Test interaction of DataTraits with classes
496 
497  stk_classic::ParallelMachine pm = MPI_COMM_WORLD;
498  int p_rank = stk_classic::parallel_machine_rank( pm );
499  int p_size = stk_classic::parallel_machine_size( pm );
500  MPI_Barrier( pm );
501 
502  typedef Vec3 T ;
503  const DataTraits & traits = data_traits<T>();
504 
505  // Test data trait properties of class type
506  STKUNIT_ASSERT( traits.type_info == typeid(T) );
507  STKUNIT_ASSERT_EQUAL( traits.size_of , sizeof(T) );
508  STKUNIT_ASSERT_EQUAL( traits.alignment_of , sizeof(double) );
509  STKUNIT_ASSERT_EQUAL( traits.stride_of , sizeof(T) );
510  STKUNIT_ASSERT_EQUAL( traits.is_integral , false );
511  STKUNIT_ASSERT_EQUAL( traits.is_floating_point , false );
512  STKUNIT_ASSERT_EQUAL( traits.is_array , false );
513  STKUNIT_ASSERT_EQUAL( traits.is_pointer , false );
514  STKUNIT_ASSERT_EQUAL( traits.is_enum , false );
515  STKUNIT_ASSERT_EQUAL( traits.is_class , true );
516  STKUNIT_ASSERT_EQUAL( traits.is_pod , true );
517  STKUNIT_ASSERT_EQUAL( traits.is_signed , false );
518  STKUNIT_ASSERT_EQUAL( traits.is_unsigned , false );
519 
520  STKUNIT_ASSERT( ! traits.remove_pointer );
521  STKUNIT_ASSERT( traits.enum_info.empty() );
522 
523  const Vec3 a = { 1.0 , 2.0 , 3.0 };
524  const size_t dx = reinterpret_cast<const unsigned char *>( & a.x ) -
525  reinterpret_cast<const unsigned char *>( & a );
526  const size_t dy = reinterpret_cast<const unsigned char *>( & a.y ) -
527  reinterpret_cast<const unsigned char *>( & a );
528  const size_t dz = reinterpret_cast<const unsigned char *>( & a.z ) -
529  reinterpret_cast<const unsigned char *>( & a );
530 
531  STKUNIT_ASSERT_EQUAL( traits.class_info.size() , size_t(3) );
532  STKUNIT_ASSERT_EQUAL( (traits.class_info[0].name == "x"), true );
533  STKUNIT_ASSERT_EQUAL( (traits.class_info[1].name == "y"), true );
534  STKUNIT_ASSERT_EQUAL( (traits.class_info[2].name == "z"), true );
535  STKUNIT_ASSERT_EQUAL( traits.class_info[0].traits, & data_traits<double>() );
536  STKUNIT_ASSERT_EQUAL( traits.class_info[1].traits, & data_traits<double>() );
537  STKUNIT_ASSERT_EQUAL( traits.class_info[2].traits, & data_traits<double>() );
538  STKUNIT_ASSERT_EQUAL( traits.class_info[0].offset, dx );
539  STKUNIT_ASSERT_EQUAL( traits.class_info[1].offset, dy );
540  STKUNIT_ASSERT_EQUAL( traits.class_info[2].offset, dz );
541 
542  // Test data trait basic operations on class type
543  const unsigned array_size = 1;
544  Vec3 b ;
545  traits.construct( & b , array_size );
546  traits.copy( & b , & a , array_size );
547  STKUNIT_ASSERT_EQUAL( b.x , a.x );
548  STKUNIT_ASSERT_EQUAL( b.y , a.y );
549  STKUNIT_ASSERT_EQUAL( b.z , a.z );
550 
551  // Test unsupport operations on class type
552  STKUNIT_ASSERT_THROW(traits.sum (NULL, NULL, 0 ), std::runtime_error);
553  STKUNIT_ASSERT_THROW(traits.max (NULL, NULL, 0 ), std::runtime_error);
554  STKUNIT_ASSERT_THROW(traits.min (NULL, NULL, 0 ), std::runtime_error);
555  STKUNIT_ASSERT_THROW(traits.bit_and(NULL, NULL, 0 ), std::runtime_error);
556  STKUNIT_ASSERT_THROW(traits.bit_or (NULL, NULL, 0 ), std::runtime_error);
557  STKUNIT_ASSERT_THROW(traits.bit_xor(NULL, NULL, 0 ), std::runtime_error);
558  STKUNIT_ASSERT_THROW(traits.print (std::cout, NULL, 0), std::runtime_error);
559 
560  // Test data trait pack/unpack (communication) of class type
561  traits.construct( & b , array_size );
562  CommAll comm( pm );
563  traits.pack( comm.send_buffer(0) , & a , array_size );
564  comm.allocate_buffers( 0 );
565  traits.pack( comm.send_buffer(0) , & a , array_size );
566  comm.communicate();
567  if (p_rank == 0) {
568  for (int proc_id = 0; proc_id < p_size; ++proc_id) {
569  traits.unpack( comm.recv_buffer(proc_id) , & b , array_size );
570  STKUNIT_ASSERT_EQUAL( a.x , b.x );
571  STKUNIT_ASSERT_EQUAL( a.y , b.y );
572  STKUNIT_ASSERT_EQUAL( a.z , b.z );
573  }
574  }
575 
576  traits.destroy( & b , array_size );
577 }
578 
579 }
580 
581 #endif
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...
Definition: Parallel.cpp:29
unsigned parallel_machine_size(ParallelMachine parallel_machine)
Member function parallel_machine_size ...
Definition: Parallel.cpp:18
Sierra Toolkit.
MPI_Comm ParallelMachine
Definition: Parallel.hpp:32