Skip to content

Commit 8706b69

Browse files
committed
Test false sharing effects
1 parent bbe96c4 commit 8706b69

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/transition/solver.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ class CG_Data {
237237
* @param[in] buffer_size The size of the given \a buffer. Used for sanity
238238
* checking the use of the buffer.
239239
*
240-
*
241240
* @param[in] buffer_deleter How the given \a buffer should be deleted on
242241
* destruction of this instance.
243242
*
@@ -261,6 +260,9 @@ class CG_Data {
261260
assert( a != nullptr );
262261
assert( ja != nullptr );
263262
assert( ia != nullptr );
263+
constexpr size_t align = (64 % sizeof(int) == 0)
264+
? 64
265+
: (64 + (sizeof(int) - (64 % sizeof(int))));
264266
if( buffer_size < workspaceSize( n, false ) ) {
265267
throw std::invalid_argument( "The given buffer size is too small" );
266268
}
@@ -275,7 +277,7 @@ class CG_Data {
275277
}
276278
workspace_ptr += n * sizeof( T );
277279
workspace_ptr +=
278-
(sizeof(int) - (reinterpret_cast<uintptr_t>(workspace_ptr) % sizeof(int)));
280+
(align - (reinterpret_cast<uintptr_t>(workspace_ptr) % align));
279281
assert( static_cast< char * >(buffer) + buffer_size >= workspace_ptr + n );
280282
{
281283
T * const workspace_vector = reinterpret_cast< T * >(workspace_ptr);
@@ -284,7 +286,7 @@ class CG_Data {
284286
}
285287
workspace_ptr += n * sizeof( T );
286288
workspace_ptr +=
287-
(sizeof(int) - (reinterpret_cast<uintptr_t>(workspace_ptr) % sizeof(int)));
289+
(align - (reinterpret_cast<uintptr_t>(workspace_ptr) % align));
288290
assert( static_cast< char * >(buffer) + buffer_size >= workspace_ptr + n );
289291
{
290292
T * const workspace_vector = reinterpret_cast< T * >(workspace_ptr);
@@ -294,7 +296,7 @@ class CG_Data {
294296
if( buffer_size >= workspaceSize( n, true ) ) {
295297
workspace_ptr += n * sizeof( T );
296298
workspace_ptr +=
297-
(sizeof(int) - (reinterpret_cast<uintptr_t>(workspace_ptr) % sizeof(int)));
299+
(align - (reinterpret_cast<uintptr_t>(workspace_ptr) % align));
298300
assert( static_cast< char * >(buffer) + buffer_size >= workspace_ptr + n );
299301
T * const workspace_vector = reinterpret_cast< T * >(workspace_ptr);
300302
grb::Vector< T > tmp = grb::internal::wrapRawVector( n, workspace_vector );
@@ -440,7 +442,7 @@ static sparse_err_t sparse_cg_init_impl_no_buffer(
440442
const bool support_preconditioning, const bool numa
441443
) {
442444
const size_t allocSize = CG_Data< T, NZI, RSI >::
443-
workspaceSize( n, support_preconditioning );
445+
workspaceSize( n, support_preconditioning ) + 256; // TODO hide this const
444446
void * buffer = nullptr;
445447
#ifdef _GRB_NO_LIBNUMA
446448
if( numa ) {

0 commit comments

Comments
 (0)