[ET Trac] [Einstein Toolkit] #1339: Memory alignment in CarpetLib failing
Einstein Toolkit
trac-noreply at einsteintoolkit.org
Fri Apr 26 16:49:07 CDT 2013
#1339: Memory alignment in CarpetLib failing
---------------------+------------------------------------------------------
Reporter: rhaas | Owner: eschnett
Type: defect | Status: new
Priority: minor | Milestone:
Component: Carpet | Version:
Resolution: | Keywords:
---------------------+------------------------------------------------------
Comment (by eschnett):
I am testing a patch.
FYI:
{{{
$ git diff
diff --git a/Carpet/CarpetLib/src/mem.cc b/Carpet/CarpetLib/src/mem.cc
index 89d8fb2..0a5f369 100644
--- a/Carpet/CarpetLib/src/mem.cc
+++ b/Carpet/CarpetLib/src/mem.cc
@@ -105,6 +105,7 @@ mem (size_t const vectorlength, size_t const nelems,
size_t const max_cache_linesize = get_max_cache_linesize();
size_t const vector_size = CCTK_REAL_VEC_SIZE * sizeof(T);
size_t const alignment = align_up(max_cache_linesize, vector_size);
+ assert(alignment >= 1);
// Safety check
assert(alignment <= 1024);
// Assume optimistically that operator new returns well-aligned
@@ -123,7 +124,8 @@ mem (size_t const vectorlength, size_t const nelems,
} else {
allocate_with_alignment:
// Operator new needs manual alignment
- size_t const max_padding = alignment / sizeof(T) - 1;
+ size_t const max_padding = div_up(alignment, sizeof(T)) - 1;
+ assert((ptrdiff_t)max_padding >= 0);
storage_base_ = new T [vectorlength * nelems + max_padding];
storage_ = (T*) (size_t(storage_base_ + max_padding) &
~(alignment-1));
assert(size_t(storage_) >= size_t(storage_base_ )
and
}}}
(This corrects a rounding error, and adds more safety checks.)
--
Ticket URL: <https://trac.einsteintoolkit.org/ticket/1339#comment:3>
Einstein Toolkit <http://einsteintoolkit.org>
The Einstein Toolkit
More information about the Trac
mailing list