Skip to content

Commit

Permalink
Merge pull request #103 from dash-project/bug-3-mat-row-copy
Browse files Browse the repository at this point in the history
Stability: Zero-Array, Global Null Pointers
  • Loading branch information
fuchsto authored Nov 15, 2016
2 parents c5760e1 + 02b8ef4 commit 8d915e5
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 63 deletions.
10 changes: 2 additions & 8 deletions dart-impl/base/src/internal/domain_locality.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ dart_ret_t dart__base__locality__domain__copy(

dart__base__locality__domain__init(domain_dst);

*domain_dst = *domain_src;

strncpy(domain_dst->domain_tag, domain_src->domain_tag,
DART_LOCALITY_DOMAIN_TAG_MAX_SIZE);

strncpy(domain_dst->host, domain_src->host,
DART_LOCALITY_HOST_MAX_SIZE);
memcpy(domain_dst, domain_src, sizeof(dart_domain_locality_t));

/* Copy unit ids:
*/
Expand Down Expand Up @@ -178,7 +172,7 @@ dart_ret_t dart__base__locality__domain__copy(
DART_LOG_ERROR("dart__base__locality__domain__copy: domain %s "
"has num_domains = %d, expected domains = NULL",
domain_src->domain_tag, domain_src->num_domains);
// return DART_ERR_OTHER;
return DART_ERR_OTHER;
}
domain_dst->domains = NULL;
}
Expand Down
5 changes: 5 additions & 0 deletions dart-impl/mpi/src/dart_globmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ dart_ret_t dart_team_memfree(
return DART_ERR_INVAL;
}

if (DART_GPTR_ISNULL(gptr)) {
/* corresponds to free(NULL) which is a valid operation */
return DART_OK;
}

dart_team_myid(teamid, &unitid);

win = dart_team_data[index].window;
Expand Down
8 changes: 2 additions & 6 deletions dash/include/dash/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,7 @@ class Array
DASH_LOG_TRACE_VAR("Array.allocate", team.dart_id());
// Check requested capacity:
if (nelem == 0) {
DASH_THROW(
dash::exception::InvalidArgument,
"Tried to allocate dash::Array with size 0");
DASH_LOG_WARN("Array.allocate", "allocating dash::Array with size 0");
}
if (m_team == nullptr || *m_team == dash::Team::Null()) {
DASH_LOG_TRACE("Array.allocate",
Expand Down Expand Up @@ -1132,9 +1130,7 @@ class Array
m_size = m_pattern.capacity();
m_team = &(m_pattern.team());
if (m_size == 0) {
DASH_THROW(
dash::exception::InvalidArgument,
"Tried to allocate dash::Array with size 0");
DASH_LOG_WARN("Array.allocate", "allocating dash::Array with size 0");
}
// Initialize members:
m_lsize = m_pattern.local_size();
Expand Down
16 changes: 4 additions & 12 deletions dash/include/dash/Atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class Atomic
{
DASH_LOG_DEBUG("Atomic.get()");
DASH_LOG_TRACE_VAR("Atomic.get", _gptr);
DASH_ASSERT(
!DART_GPTR_EQUAL(
_gptr, DART_GPTR_NULL));
DASH_ASSERT(!DART_GPTR_ISNULL(_gptr));
reference ref(_gptr);
DASH_LOG_DEBUG_VAR("Atomic.get >", static_cast<ValueType>(ref));
return ref;
Expand All @@ -98,9 +96,7 @@ class Atomic
{
DASH_LOG_DEBUG("Atomic.cget()");
DASH_LOG_TRACE_VAR("Atomic.cget", _gptr);
DASH_ASSERT(
!DART_GPTR_EQUAL(
_gptr, DART_GPTR_NULL));
DASH_ASSERT(!DART_GPTR_ISNULL(_gptr));
const_reference cref(_gptr);
DASH_LOG_DEBUG_VAR("Atomic.cget >", static_cast<ValueType>(cref));
return cref;
Expand All @@ -119,9 +115,7 @@ class Atomic
DASH_LOG_TRACE_VAR("Atomic.add", _gptr);
DASH_LOG_TRACE_VAR("Atomic.add", _team);
DASH_ASSERT(_team != nullptr);
DASH_ASSERT(
!DART_GPTR_EQUAL(
_gptr, DART_GPTR_NULL));
DASH_ASSERT(!DART_GPTR_ISNULL(_gptr));
value_type acc = value;
DASH_LOG_TRACE("Atomic.add", "dart_accumulate");
dart_ret_t ret = dart_accumulate(
Expand Down Expand Up @@ -153,9 +147,7 @@ class Atomic
DASH_LOG_DEBUG_VAR("Atomic.fetch_and_op()", val);
DASH_LOG_TRACE_VAR("Atomic.fetch_and_op", _gptr);
DASH_ASSERT(_team != nullptr);
DASH_ASSERT(
!DART_GPTR_EQUAL(
_gptr, DART_GPTR_NULL));
DASH_ASSERT(!DART_GPTR_ISNULL(_gptr));
value_type acc;
dart_ret_t ret = dart_fetch_and_op(
_gptr,
Expand Down
4 changes: 2 additions & 2 deletions dash/include/dash/GlobDynamicMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ class GlobDynamicMem
bucket.lptr = nullptr;
bucket.attached = true;
bucket.gptr = _allocator.attach(bucket.lptr, bucket.size);
DASH_ASSERT(bucket.gptr != DART_GPTR_NULL);
DASH_ASSERT(!DART_GPTR_ISNULL(bucket.gptr));
_buckets.push_back(bucket);
num_attached_buckets++;
DASH_LOG_TRACE("GlobDynamicMem.commit_attach", "attached null bucket:",
Expand Down Expand Up @@ -1333,7 +1333,7 @@ class GlobDynamicMem
DASH_ASSERT_LT(bucket_phase, bucket_it->size,
"bucket phase out of bounds");
}
if (DART_GPTR_EQUAL(dart_gptr, DART_GPTR_NULL)) {
if (DART_GPTR_ISNULL(dart_gptr)) {
DASH_LOG_TRACE("GlobDynamicMem.dart_gptr_at",
"bucket.gptr is DART_GPTR_NULL");
dart_gptr = DART_GPTR_NULL;
Expand Down
6 changes: 3 additions & 3 deletions dash/include/dash/GlobMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class GlobMem
return;
}
_begptr = _allocator.allocate(_nlelem);
DASH_ASSERT_NE(DART_GPTR_NULL, _begptr, "allocation failed");
DASH_ASSERT_MSG(!DART_GPTR_ISNULL(_begptr), "allocation failed");

_lbegin = lbegin(dash::myid());
_lend = lend(dash::myid());
Expand Down Expand Up @@ -156,7 +156,7 @@ class GlobMem
DASH_LOG_DEBUG("GlobMem(lvals,team)", "nothing to allocate");
} else {
_begptr = _allocator.allocate(_nlelem);
DASH_ASSERT_NE(DART_GPTR_NULL, _begptr, "allocation failed");
DASH_ASSERT_MSG(!DART_GPTR_ISNULL(_begptr), "allocation failed");

_lbegin = lbegin(dash::myid());
_lend = lend(dash::myid());
Expand Down Expand Up @@ -442,7 +442,7 @@ class GlobMem
IndexType local_index) const
{
DASH_LOG_DEBUG("GlobMem.at(unit,l_idx)", unit, local_index);
if (_nunits == 0 || DART_GPTR_NULL == _begptr) {
if (_nunits == 0 || DART_GPTR_ISNULL(_begptr)) {
DASH_LOG_DEBUG("GlobMem.at(unit,l_idx) >",
"global memory not allocated");
return dash::GlobPtr<value_type>(nullptr);
Expand Down
4 changes: 2 additions & 2 deletions dash/include/dash/GlobPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ class GlobPtr
*/
bool operator==(const self_t & other) const
{
return _dart_gptr == other._dart_gptr;
return DART_GPTR_EQUAL(_dart_gptr, other._dart_gptr);
}

/**
* Inequality comparison operator.
*/
bool operator!=(const self_t & other) const
{
return _dart_gptr != other._dart_gptr;
return !(*this == other);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions dash/include/dash/GlobSharedRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class GlobSharedRef
if (_lptr != nullptr) {
DASH_LOG_TRACE_VAR("GlobSharedRef.T()", _lptr);
return *_lptr;
} else if (!DART_GPTR_EQUAL(DART_GPTR_NULL, _gptr)) {
} else if (!DART_GPTR_ISNULL(_gptr)) {
DASH_LOG_TRACE_VAR("GlobSharedRef.T()", _gptr);
T t;
dart_get_blocking(static_cast<void *>(&t), _gptr, sizeof(T));
Expand All @@ -188,7 +188,7 @@ class GlobSharedRef
if (_lptr != nullptr) {
DASH_LOG_TRACE_VAR("GlobSharedRef.T()", _lptr);
t = *_lptr;
} else if (!DART_GPTR_EQUAL(DART_GPTR_NULL, _gptr)) {
} else if (!DART_GPTR_ISNULL(_gptr)) {
DASH_LOG_TRACE_VAR("GlobSharedRef.T()", _gptr);
dart_get_blocking(static_cast<void *>(&t), _gptr, sizeof(T));
}
Expand All @@ -200,7 +200,7 @@ class GlobSharedRef
if (_lptr != nullptr) {
DASH_LOG_TRACE_VAR("GlobSharedRef.T()", _lptr);
*_lptr = val;
} else if (!DART_GPTR_EQUAL(DART_GPTR_NULL, _gptr)) {
} else if (!DART_GPTR_ISNULL(_gptr)) {
DASH_LOG_TRACE_VAR("GlobSharedRef.T()", _gptr);
dart_put_blocking(_gptr, static_cast<void *>(&val), sizeof(T));
}
Expand All @@ -218,7 +218,7 @@ class GlobSharedRef
if (_lptr != nullptr) {
DASH_LOG_TRACE_VAR("GlobSharedRef.=", _lptr);
*_lptr = val;
} else if (!DART_GPTR_EQUAL(DART_GPTR_NULL, _gptr)) {
} else if (!DART_GPTR_ISNULL(_gptr)) {
DASH_LOG_TRACE_VAR("GlobSharedRef.=", _gptr);
dart_put_blocking(_gptr, static_cast<const void *>(&val), sizeof(T));
}
Expand Down
17 changes: 4 additions & 13 deletions dash/include/dash/Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ class Shared {
DASH_LOG_DEBUG_VAR("Shared.set()", val);
DASH_LOG_DEBUG_VAR("Shared.set", _owner);
DASH_LOG_DEBUG_VAR("Shared.set", _ptr);
DASH_ASSERT(
!DART_GPTR_EQUAL(
_ptr.dart_gptr(), DART_GPTR_NULL));
DASH_ASSERT(!DART_GPTR_ISNULL(_ptr.dart_gptr()));
*_ptr = val;
DASH_LOG_DEBUG("Shared.set >");
}
Expand All @@ -135,9 +133,7 @@ class Shared {
DASH_LOG_DEBUG("Shared.cget()");
DASH_LOG_DEBUG_VAR("Shared.cget", _owner);
DASH_LOG_DEBUG_VAR("Shared.cget", _ptr);
DASH_ASSERT(
!DART_GPTR_EQUAL(
_ptr.dart_gptr(), DART_GPTR_NULL));
DASH_ASSERT(!DART_GPTR_ISNULL(_ptr.dart_gptr()));
const_reference ref = *_ptr;
DASH_LOG_DEBUG_VAR("Shared.cget >", static_cast<ElementType>(ref));
return ref;
Expand All @@ -151,9 +147,7 @@ class Shared {
DASH_LOG_DEBUG("Shared.get()");
DASH_LOG_DEBUG_VAR("Shared.get", _owner);
DASH_LOG_DEBUG_VAR("Shared.get", _ptr);
DASH_ASSERT(
!DART_GPTR_EQUAL(
_ptr.dart_gptr(), DART_GPTR_NULL));
DASH_ASSERT(!DART_GPTR_ISNULL(_ptr.dart_gptr()));
reference ref = *_ptr;
DASH_LOG_DEBUG_VAR("Shared.get >", static_cast<ElementType>(ref));
return ref;
Expand All @@ -164,10 +158,7 @@ class Shared {
*/
void flush()
{
DASH_ASSERT(
!DART_GPTR_EQUAL(
_ptr.dart_gptr(),
DART_GPTR_NULL));
DASH_ASSERT(!DART_GPTR_ISNULL(_ptr.dart_gptr()));
DASH_ASSERT_RETURNS(
dart_flush(_ptr.dart_gptr()),
DART_OK);
Expand Down
13 changes: 8 additions & 5 deletions dash/include/dash/algorithm/Copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ dash::Future<ValueType *> copy_async(
*/
template <
typename ValueType,
class GlobInputIt >
class GlobInputIt >
ValueType * copy(
GlobInputIt in_first,
GlobInputIt in_last,
Expand Down Expand Up @@ -865,6 +865,7 @@ ValueType * copy(
DASH_LOG_TRACE("dash::copy",
"global index range of local subrange:",
"begin:", g_l_offset_begin, "end:", g_l_offset_end);

// Global position of input start iterator:
auto g_offset_begin = g_in_first.pos();
// Convert local subrange to global iterators:
Expand All @@ -873,12 +874,16 @@ ValueType * copy(
DASH_LOG_TRACE("dash::copy", "global it. range of local subrange:",
"begin:", g_l_in_first.pos(), "end:", g_l_in_last.pos());
DASH_LOG_TRACE_VAR("dash::copy", g_l_in_last.pos());

auto num_prelocal_elem = g_l_in_first.pos() - g_in_first.pos();
auto num_postlocal_elem = in_last.pos() - g_l_offset_end;
DASH_LOG_TRACE_VAR("dash::copy", num_prelocal_elem);
DASH_LOG_TRACE_VAR("dash::copy", num_postlocal_elem);

//
// -----------------------------------------------------------------------
// Copy remote elements preceding the local subrange:
//
auto num_prelocal_elem = g_l_in_first.pos() - g_in_first.pos();
DASH_LOG_TRACE_VAR("dash::copy", num_prelocal_elem);
if (num_prelocal_elem > 0) {
DASH_LOG_TRACE("dash::copy",
"copy global range preceding local subrange",
Expand Down Expand Up @@ -937,8 +942,6 @@ ValueType * copy(
// -----------------------------------------------------------------------
// Copy remote elements succeeding the local subrange:
//
auto num_postlocal_elem = in_last.pos() - g_l_offset_end;
DASH_LOG_TRACE_VAR("dash::copy", num_postlocal_elem);
if (num_postlocal_elem > 0) {
DASH_LOG_TRACE("dash::copy",
"copy global range succeeding local subrange",
Expand Down
1 change: 1 addition & 0 deletions dash/include/dash/allocator/CollectiveAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class CollectiveAllocator
_allocated.erase(
std::remove(_allocated.begin(), _allocated.end(), gptr),
_allocated.end());
DASH_LOG_DEBUG("CollectiveAllocator.deallocate >");
}

private:
Expand Down
4 changes: 2 additions & 2 deletions dash/include/dash/allocator/DynamicAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class DynamicAllocator
{
local_pointer lmem = allocate_local(num_local_elem);
pointer gmem = attach(lmem, num_local_elem);
if (DART_GPTR_EQUAL(gmem, DART_GPTR_NULL)) {
if (DART_GPTR_ISNULL(gmem)) {
// Attach failed, free requested local memory:
deallocate_local(lmem);
}
Expand Down Expand Up @@ -351,7 +351,7 @@ class DynamicAllocator
e.first);
delete[] e.first;
}
if (!DART_GPTR_EQUAL(e.second, DART_GPTR_NULL)) {
if (!DART_GPTR_ISNULL(e.second)) {
DASH_LOG_DEBUG("DynamicAllocator.clear", "detach global memory:",
e.second);
// Cannot use DASH_ASSERT due to noexcept qualifier:
Expand Down
10 changes: 9 additions & 1 deletion dash/include/dash/internal/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int myid();
#endif

//
// Always log error messages:
// Always log error and warning messages:
//
#define DASH_LOG_ERROR(...) \
dash::internal::logging::LogWrapper(\
Expand All @@ -49,6 +49,14 @@ int myid();
dash::internal::logging::LogVarWrapper(\
"ERROR", __FILE__, __LINE__, context, #var, (var))

#define DASH_LOG_WARN(...) \
dash::internal::logging::LogWrapper(\
"WARN ", __FILE__, __LINE__, __VA_ARGS__)

#define DASH_LOG_WARN_VAR(context, var) \
dash::internal::logging::LogVarWrapper(\
"WARN ", __FILE__, __LINE__, context, #var, (var))

//
// Debug and trace log messages:
//
Expand Down
2 changes: 1 addition & 1 deletion dash/include/dash/map/UnorderedMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class UnorderedMap
// Convert to mapped type pointer:
lptr_mapped = reinterpret_cast<mapped_type *>(b_lptr_mapped);
}
if (!DART_GPTR_EQUAL(DART_GPTR_NULL, gptr_mapped)) {
if (!DART_GPTR_ISNULL(gptr_mapped)) {
DASH_ASSERT_RETURNS(
dart_gptr_incaddr(&gptr_mapped, mapped_offs),
DART_OK);
Expand Down
2 changes: 1 addition & 1 deletion dash/include/dash/map/UnorderedMapLocalRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class UnorderedMapLocalRef
// Convert to mapped type pointer:
lptr_mapped = reinterpret_cast<mapped_type *>(b_lptr_mapped);
}
if (!DART_GPTR_EQUAL(DART_GPTR_NULL, gptr_mapped)) {
if (!DART_GPTR_ISNULL(gptr_mapped)) {
DASH_ASSERT_RETURNS(
dart_gptr_incaddr(&gptr_mapped, mapped_offs),
DART_OK);
Expand Down
4 changes: 3 additions & 1 deletion dash/include/dash/pattern/BlockPattern1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,9 @@ class Pattern<1, Arrangement, IndexType>
SizeType underfilled_blocksize(
dim_t dimension) const {
// Underflow blocksize = regular blocksize - overflow blocksize:
auto ovf_blocksize = _size % _blocksize;
auto ovf_blocksize = (_blocksize == 0)
? 0
: _size % _blocksize;
if (ovf_blocksize == 0) {
return 0;
} else {
Expand Down
4 changes: 2 additions & 2 deletions dash/test/FindTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ TEST_F(FindTest, SingleMatchInEveryUnit)

TEST_F(FindTest, EmptyContainer)
{
SKIP_TEST();

Element_t find_me = 1;

dash::Array<Element_t> array;

array.allocate(0, dash::BLOCKED);

return;

// Run find on complete array
auto found_gptr = dash::find(array.begin(), array.end(), find_me);

Expand Down
Loading

0 comments on commit 8d915e5

Please sign in to comment.