LCOV - code coverage report
Current view: top level - test - ArrayTest.cc (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 73 76 96.1 %
Date: 2016-06-29 12:30:40 Functions: 20 20 100.0 %

          Line data    Source code
       1             : #include <libdash.h>
       2             : #include <gtest/gtest.h>
       3             : #include "TestBase.h"
       4             : #include "ArrayTest.h"
       5             : 
       6             : // global var
       7           4 : dash::Array<int> array_global;
       8             : 
       9          20 : TEST_F(ArrayTest, Allocation)
      10             : {
      11           8 :   dash::Array<int> array_local;
      12             : 
      13             :   DASH_LOG_DEBUG("Delayed allocate");
      14           4 :   array_global.allocate(19 * dash::size(), dash::BLOCKED);
      15           4 :   array_local.allocate(19 * dash::size(), dash::BLOCKED);
      16           4 : }
      17             : 
      18          20 : TEST_F(ArrayTest, SingleWriteMultipleRead)
      19             : {
      20             :   typedef int                                         value_t;
      21             :   typedef typename dash::Array<value_t>::pattern_type pattern_t;
      22             : 
      23           4 :   size_t array_size = _num_elem * _dash_size;
      24             :   // Create array instances using varying constructor options
      25             :   LOG_MESSAGE("Array size: %d", array_size);
      26             :   try {
      27             :     // Initialize arrays
      28             :     LOG_MESSAGE("Initialize arr1");
      29           8 :     dash::Array<value_t> arr1(array_size);
      30             :     LOG_MESSAGE("Initialize arr2");
      31             :     dash::Array<value_t> arr2(array_size,
      32           8 :                               dash::BLOCKED);
      33             :     LOG_MESSAGE("Initialize arr3");
      34             :     dash::Array<value_t> arr3(array_size,
      35           8 :                               dash::Team::All());
      36             :     LOG_MESSAGE("Initialize arr4");
      37             :     dash::Array<value_t> arr4(array_size,
      38             :                               dash::CYCLIC,
      39           8 :                               dash::Team::All());
      40             :     LOG_MESSAGE("Initialize arr5");
      41             :     dash::Array<value_t> arr5(array_size,
      42           8 :                               dash::BLOCKCYCLIC(12));
      43             :     LOG_MESSAGE("Initialize arr6");
      44           4 :     pattern_t pat(array_size);
      45           8 :     dash::Array<value_t> arr6(pat);
      46             :     // Check array sizes
      47           4 :     ASSERT_EQ(array_size, arr1.size());
      48           4 :     ASSERT_EQ(array_size, arr2.size());
      49           4 :     ASSERT_EQ(array_size, arr3.size());
      50           4 :     ASSERT_EQ(array_size, arr4.size());
      51           4 :     ASSERT_EQ(array_size, arr5.size());
      52           4 :     ASSERT_EQ(array_size, arr6.size());
      53             :     // Fill arrays with incrementing values
      54           4 :     if(_dash_id == 0) {
      55             :       LOG_MESSAGE("Assigning array values");
      56         401 :       for(size_t i = 0; i < array_size; ++i) {
      57         400 :         arr1[i] = i;
      58         400 :         arr2[i] = i;
      59         400 :         arr3[i] = i;
      60         400 :         arr4[i] = i;
      61         400 :         arr5[i] = i;
      62         400 :         arr6[i] = i;
      63             :       }
      64             :     }
      65             :     // Units waiting for value initialization
      66           4 :     dash::Team::All().barrier();
      67             :     // Read and assert values in arrays
      68        1604 :     for(size_t i = 0; i < array_size; ++i) {
      69        1600 :       ASSERT_EQ_U(i, static_cast<value_t>(arr1[i]));
      70        1600 :       ASSERT_EQ_U(i, static_cast<value_t>(arr2[i]));
      71        1600 :       ASSERT_EQ_U(i, static_cast<value_t>(arr3[i]));
      72        1600 :       ASSERT_EQ_U(i, static_cast<value_t>(arr4[i]));
      73        1600 :       ASSERT_EQ_U(i, static_cast<value_t>(arr5[i]));
      74        1600 :       ASSERT_EQ_U(i, static_cast<value_t>(arr6[i]));
      75             :     }
      76           0 :   } catch (dash::exception::InvalidArgument & ia) {
      77             :     LOG_MESSAGE("ERROR: %s", ia.what());
      78           0 :     ASSERT_FAIL();
      79             :   }
      80             : }
      81             : 
      82          20 : TEST_F(ArrayTest, TileSize)
      83             : {
      84             :   typedef int                                            value_t;
      85             :   typedef long long                                      index_t;
      86             :   typedef dash::TilePattern<1, dash::ROW_MAJOR, index_t> pattern_t;
      87             :   typedef dash::Array<value_t, index_t, pattern_t>       array_t;
      88             : 
      89           4 :   size_t nunits          = dash::Team::All().size();
      90           4 :   size_t tilesize        = 1024;
      91           4 :   size_t blocks_per_unit = 3;
      92           4 :   size_t size            = nunits * tilesize * blocks_per_unit;
      93             : 
      94           8 :   array_t arr(size, dash::TILE(tilesize));
      95             : 
      96           4 :   ASSERT_EQ_U(arr.pattern().blocksize(0),
      97             :               arr.pattern().block(0).extent(0));
      98             : 
      99           4 :   auto block_0         = arr.pattern().local_block(0);
     100           4 :   auto block_1         = arr.pattern().local_block(1);
     101             : 
     102           4 :   auto block_0_gend    = block_0.offset(0) + block_0.extent(0);
     103           4 :   auto block_1_gbegin  = block_1.offset(0);
     104             : 
     105           4 :   auto block_glob_dist = block_1_gbegin - block_0_gend;
     106             : 
     107             :   // Blocked distribution, expect (nunits-1) blocks between to local blocks.
     108           4 :   EXPECT_EQ_U(tilesize * (nunits - 1),
     109           0 :               block_glob_dist);
     110             : }
     111             : 
     112          20 : TEST_F(ArrayTest, PatternAllocate)
     113             : {
     114             :         typedef long                                                                                                                     index_t;
     115             :         typedef dash::Pattern<1, dash::ROW_MAJOR, index_t> pattern_t;
     116           4 :         const size_t size     = 115;
     117           4 :         const size_t tilesize = 10;
     118           8 :         dash::Array<int, index_t, pattern_t> array;
     119             : 
     120             :         // Fill
     121             :   std::function< void(const int &, index_t)>
     122         230 :   fill = [&array](int el, index_t i) {
     123         115 :     auto coords = array.pattern().coords(i);
     124         230 :     array[i] = coords[0];
     125         123 :   };
     126             : 
     127             :         // Verify
     128             :         std::function< void(const int &, index_t)>
     129         115 :         verify = [&array](int el, index_t i) {
     130         115 :         auto coords  = array.pattern().coords(i);
     131         115 :         auto desired = coords[0];
     132         115 :         ASSERT_EQ_U(
     133             :         desired,
     134             :         el);
     135           8 :         };
     136             : 
     137             :         {
     138             :     const pattern_t pattern(
     139             :        dash::SizeSpec<1>(size),
     140           8 :        dash::DistributionSpec<1>(dash::TILE(tilesize)),
     141             :        dash::TeamSpec<1>(),
     142          16 :        dash::Team::All());
     143             : 
     144           4 :                 array.allocate(pattern);
     145             :         }
     146             : 
     147             :         // Fill
     148             :   dash::for_each_with_index(
     149           8 :     array.begin(),
     150           8 :     array.end(),
     151           4 :     fill);
     152             : 
     153             :   dash::for_each_with_index(
     154           8 :     array.begin(),
     155           8 :     array.end(),
     156           4 :     verify);
     157          16 : }

Generated by: LCOV version 1.12