LCOV - code coverage report
Current view: top level - src - Team.cc (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 17 69 24.6 %
Date: 2016-06-29 12:30:40 Functions: 5 7 71.4 %

          Line data    Source code
       1             : 
       2             : #include <dash/Team.h>
       3             : 
       4             : #include <dash/util/Locality.h>
       5             : 
       6             : #include <list>
       7             : #include <vector>
       8             : #include <unordered_map>
       9             : #include <memory>
      10             : 
      11             : #include <stdio.h>
      12             : #include <unistd.h>
      13             : 
      14             : 
      15             : namespace dash {
      16             : 
      17             : std::unordered_map<dart_team_t, Team *>
      18           4 : Team::_teams =
      19             :   std::unordered_map<dart_team_t, Team *>();
      20             : 
      21           4 : Team Team::_team_all  { DART_TEAM_ALL,  nullptr };
      22           4 : Team Team::_team_null { DART_TEAM_NULL, nullptr };
      23             : 
      24             : 
      25           4 : std::ostream & operator<<(
      26             :   std::ostream & os,
      27             :   const Team   & team)
      28             : {
      29           4 :   os << "dash::Team(" << team._dartid;
      30           4 :   Team * parent = team._parent;
      31           4 :   while (parent != nullptr &&
      32           0 :          parent->_dartid != DART_TEAM_NULL) {
      33           0 :     os << "." << parent->_dartid;
      34           0 :     parent = parent->_parent;
      35             :   }
      36           4 :   os << ")";
      37           4 :   return os;
      38             : }
      39             : 
      40        1520 : bool operator==(
      41             :   const Team::Deallocator & lhs,
      42             :   const Team::Deallocator & rhs)
      43             : {
      44        1520 :   return lhs.object == rhs.object;
      45             : }
      46             : 
      47             : 
      48           8 : Team::Team(
      49             :   dart_team_t id,
      50             :   Team      * parent,
      51             :   size_t      pos)
      52             : : _dartid(id),
      53             :   _parent(parent),
      54           8 :   _position(pos)
      55             : {
      56           8 :   if (nullptr != parent) {
      57           0 :     if (parent->_child) {
      58           0 :       DASH_THROW(
      59             :         dash::exception::InvalidArgument,
      60             :         "child of team "  << parent->dart_id() << " " <<
      61             :         "already set to " << parent->_child->dart_id() << ", " <<
      62             :         "cannot set to "  << id);
      63             :     } else {
      64           0 :       parent->_child = this;
      65             :     }
      66             :   }
      67             :   // Do not register static Team instances as static variable _team might
      68             :   // not be initialized at the time of their instantiation, yet:
      69           8 :   if (DART_TEAM_NULL != id &&
      70             :       DART_TEAM_ALL != id) {
      71           0 :     Team::register_team(this);
      72             :   }
      73           8 : }
      74             : 
      75             : Team &
      76           0 : Team::split(
      77             :   unsigned nParts)
      78             : {
      79             :   DASH_LOG_DEBUG_VAR("Team.split()", nParts);
      80             :   dart_group_t *  group;
      81             :   dart_group_t ** sub_groups = static_cast<dart_group_t**>(
      82           0 :                                  malloc(sizeof(dart_group_t*) * nParts));
      83             :   size_t size;
      84             : 
      85           0 :   dart_group_sizeof(&size);
      86             : 
      87           0 :   group = static_cast<dart_group_t *>(malloc(size));
      88           0 :   for (unsigned i = 0; i < nParts; i++) {
      89           0 :     sub_groups[i] = static_cast<dart_group_t *>(malloc(size));
      90           0 :     DASH_ASSERT_RETURNS(
      91             :       dart_group_init(sub_groups[i]),
      92             :       DART_OK);
      93             :   }
      94             : 
      95           0 :   Team *result = &(dash::Team::Null());
      96             : 
      97           0 :   if (this->size() <= 1) {
      98             :     DASH_LOG_DEBUG("Team.split >", "Team size is 1, cannot split");
      99           0 :     return *result;
     100             :   }
     101           0 :   DASH_ASSERT_RETURNS(
     102             :     dart_group_init(group),
     103             :     DART_OK);
     104           0 :   DASH_ASSERT_RETURNS(
     105             :     dart_team_get_group(_dartid, group),
     106             :     DART_OK);
     107           0 :   DASH_ASSERT_RETURNS(
     108             :     dart_group_split(group, nParts, sub_groups),
     109             :     DART_OK);
     110           0 :   dart_team_t oldteam = _dartid;
     111             :   // Create a child Team for every part with parent set to
     112             :   // this instance:
     113           0 :   for(unsigned i = 0; i < nParts; i++) {
     114           0 :     dart_team_t newteam = DART_TEAM_NULL;
     115           0 :     DASH_ASSERT_RETURNS(
     116             :       dart_team_create(
     117             :         oldteam,
     118             :         sub_groups[i],
     119             :         &newteam),
     120             :       DART_OK);
     121           0 :     if(newteam != DART_TEAM_NULL) {
     122             :       // Create team instance of child team:
     123           0 :       result = new Team(newteam, this, i);
     124             :     }
     125             :   }
     126             :   DASH_LOG_DEBUG("Team.split >");
     127           0 :   return *result;
     128             : }
     129             : 
     130             : Team &
     131           0 : Team::locality_split(
     132             :   dash::util::Locality::Scope scope,
     133             :   unsigned                    num_parts)
     134             : {
     135             :   DASH_LOG_DEBUG_VAR("Team.locality_split()", scope);
     136             :   DASH_LOG_DEBUG_VAR("Team.locality_split()", num_parts);
     137             : 
     138           0 :   if (num_parts == 0) {
     139           0 :     DASH_THROW(
     140             :       dash::exception::InvalidArgument,
     141             :       "Number of parts to split team must be greater than 0");
     142             :   }
     143             : 
     144             :   dart_locality_scope_t dart_scope = static_cast<dart_locality_scope_t>(
     145           0 :                                         static_cast<int>(scope));
     146             : 
     147             :   // TODO: Replace dynamic arrays with vectors.
     148             : 
     149             :   dart_group_t *  group;
     150             :   dart_group_t ** sub_groups = static_cast<dart_group_t**>(
     151           0 :                                  malloc(sizeof(dart_group_t *) *
     152           0 :                                         num_parts));
     153             :   size_t group_t_size;
     154             : 
     155           0 :   dart_group_sizeof(&group_t_size);
     156             : 
     157           0 :   group = static_cast<dart_group_t *>(malloc(group_t_size));
     158           0 :   for (unsigned i = 0; i < num_parts; i++) {
     159           0 :     sub_groups[i] = static_cast<dart_group_t *>(malloc(group_t_size));
     160           0 :     DASH_ASSERT_RETURNS(
     161             :       dart_group_init(sub_groups[i]),
     162             :       DART_OK);
     163             :   }
     164             : 
     165           0 :   Team * result = &(dash::Team::Null());
     166             : 
     167           0 :   if (this->size() < 2) {
     168             :     DASH_LOG_DEBUG("Team.locality_split >", "Team size < 2, cannot split");
     169           0 :     return *result;
     170             :   }
     171             : 
     172             :   dart_domain_locality_t * domain;
     173           0 :   DASH_ASSERT_RETURNS(
     174             :     dart_domain_team_locality(_dartid, ".", &domain),
     175             :     DART_OK);
     176           0 :   DASH_ASSERT_RETURNS(
     177             :     dart_group_init(group),
     178             :     DART_OK);
     179           0 :   DASH_ASSERT_RETURNS(
     180             :     dart_team_get_group(_dartid, group),
     181             :     DART_OK);
     182           0 :   DASH_ASSERT_RETURNS(
     183             :     dart_group_locality_split(
     184             :       group, domain, dart_scope, num_parts, sub_groups),
     185             :     DART_OK);
     186           0 :   dart_team_t oldteam = _dartid;
     187             : #if DASH_ENABLE_TRACE_LOGGING
     188             :   for(unsigned i = 0; i < num_parts; i++) {
     189             :     size_t sub_group_size = 0;
     190             :     dart_group_size(sub_groups[i], &sub_group_size);
     191             :     std::vector<dart_unit_t> sub_group_unit_ids(sub_group_size);
     192             :     dart_group_getmembers(sub_groups[i], sub_group_unit_ids.data());
     193             :     DASH_LOG_TRACE("Team.locality_split", "child team", i, "units:",
     194             :                    sub_group_unit_ids);
     195             :   }
     196             : #endif
     197             :   // Create a child Team for every part with parent set to
     198             :   // this instance:
     199           0 :   for(unsigned i = 0; i < num_parts; i++) {
     200           0 :     dart_team_t newteam = DART_TEAM_NULL;
     201           0 :     DASH_ASSERT_RETURNS(
     202             :       dart_team_create(
     203             :         oldteam,
     204             :         sub_groups[i],
     205             :         &newteam),
     206             :       DART_OK);
     207           0 :     if(newteam != DART_TEAM_NULL) {
     208           0 :       result = new Team(newteam, this, i);
     209             :     }
     210             :   }
     211             :   DASH_LOG_DEBUG("Team.locality_split >");
     212           0 :   return *result;
     213             : }
     214             : 
     215             : 
     216          12 : } // namespace dash

Generated by: LCOV version 1.12