Skip to content

Commit

Permalink
ShyLU-Basker : resize only if needed
Browse files Browse the repository at this point in the history
Signed-off-by: iyamazaki <[email protected]>
  • Loading branch information
iyamazaki committed Jan 31, 2025
1 parent 4e4cece commit bd27c8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/shylu/shylu_node/basker/src/shylubasker_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ namespace BaskerNS
#ifdef BASKER_KOKKOS
// ----------------------------------------------------------------------------------------------
// Allocate & Initialize blocks
#if 1//def BASKER_PARALLEL_INIT_FACTOR
#ifdef BASKER_PARALLEL_INIT_FACTOR
kokkos_sfactor_init_factor<Int,Entry,Exe_Space>
iF(this);
Kokkos::parallel_for(TeamPolicy(num_threads,1), iF);
Expand Down
38 changes: 20 additions & 18 deletions packages/shylu/shylu_node/basker/src/shylubasker_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_INT_1DARRAY_PAIRS(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC malloc_pairs_1d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
Kokkos::resize(a, s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -171,7 +171,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_INT_1DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC int_1d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
Kokkos::resize(a, s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -181,23 +181,25 @@ enum BASKER_INCOMPLETE_CODE
{ \
BASKER_ASSERT(s0>0, "BASKER ASSERT MALLOC int_rank2d: size to alloc > 0 fails"); \
BASKER_ASSERT(s1>0, "BASKER ASSERT MALLOC int_rank2d: size to alloc > 0 fails"); \
Kokkos::resize(a, s0,s1); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
if (a.extent(0) != s0 || a.extent(1) != s1) { \
Kokkos::resize(a, s0,s1); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
} \
}
#define MALLOC_INT_2DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0,"BASKER ASSERT MALLOC int_2d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
a = INT_2DARRAY(Kokkos::view_alloc("int_2d", Kokkos::SequentialHostInit),s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
} \
if(a.data() == NULL) \
throw std::bad_alloc(); \
} \
}
#define MALLOC_ENTRY_1DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC entry_1d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
Kokkos::resize(a, s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -206,7 +208,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_ENTRY_2DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC entry_2d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
a = ENTRY_2DARRAY(Kokkos::view_alloc("matrix_2d", Kokkos::SequentialHostInit),s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -215,7 +217,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_BOOL_1DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC bool_1d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
Kokkos::resize(a, s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -224,7 +226,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_BOOL_2DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC bool_2d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
Kokkos::resize(a, s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -233,7 +235,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_MATRIX_1DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC matrix_1d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
a = MATRIX_1DARRAY(Kokkos::view_alloc("matrix_1d", Kokkos::SequentialHostInit),s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -242,7 +244,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_MATRIX_2DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC matrix_2d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
a = MATRIX_2DARRAY(Kokkos::view_alloc("matrix_2d", Kokkos::SequentialHostInit),s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -251,7 +253,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_MATRIX_VIEW_1DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC matrix_view_1d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
a = MATRIX_VIEW_1DARRAY(Kokkos::view_alloc("matrix_view_1d", Kokkos::SequentialHostInit),s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -260,7 +262,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_MATRIX_VIEW_2DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC matrix_view_2d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
a = MATRIX_VIEW_2DARRAY(Kokkos::view_alloc("matrix_view_2d", Kokkos::SequentialHostInit),s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand All @@ -269,7 +271,7 @@ enum BASKER_INCOMPLETE_CODE
#define MALLOC_THREAD_1DARRAY(a,s) \
{ \
BASKER_ASSERT(s >= 0, "BASKER ASSERT MALLOC thread_1d: size to alloc >= 0 fails"); \
if (s > 0) { \
if (s > 0 && a.extent(0) != s) { \
a = THREAD_1DARRAY(Kokkos::view_alloc("thread_1d", Kokkos::SequentialHostInit),s); \
if(a.data() == NULL) \
throw std::bad_alloc(); \
Expand Down

0 comments on commit bd27c8c

Please sign in to comment.