diff --git a/configure.ac b/configure.ac index 2d0c871..8cda8e0 100644 --- a/configure.ac +++ b/configure.ac @@ -518,21 +518,27 @@ AC_MSG_RESULT([$ivdep]) # Checking ALIGNED -AC_MSG_CHECKING([for aligned_alloc]) +AC_MSG_CHECKING([for posix_memalign]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include ]], [[ int main() { - void * pointer = aligned_alloc(64, 100); - free(pointer); - return 0; + void *ptr; + int ret = posix_memalign(&ptr, 64, 1024); + if (ret != 0) { + return EXIT_FAILURE; + } + free(ptr); + return 0; } ]])], - [have_aligned_alloc=yes], [have_aligned_alloc=no + [have_posix_memalign=yes], [have_posix_memalign=no ]) -AS_IF([test "x$have_aligned_alloc" = "xyes"], [ - AC_DEFINE([HAVE_ALIGNED_ALLOC], [1], [Define to 1 if you have the aligned_alloc function.]) +AS_IF([test "x$have_posix_memalign" = "xyes"], [ + AC_DEFINE([HAVE_POSIX_MEMALIGN], [1], [Define to 1 if you have the posix_memalign function.]) ]) -AC_MSG_RESULT([$have_aligned_alloc]) +AC_MSG_RESULT([$have_posix_memalign]) aligned="" AC_MSG_CHECKING([for vector aligned pragma]) @@ -550,7 +556,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ [aligned='_Pragma("vector aligned")'], [ ]) -AS_IF([test "x$have_aligned_alloc" = "xno"], [ +AS_IF([test "x$have_posix_memalign" = "xno"], [ aligned="" ]) diff --git a/org/qmckl_memory.org b/org/qmckl_memory.org index 64c4a1c..d351fab 100644 --- a/org/qmckl_memory.org +++ b/org/qmckl_memory.org @@ -125,7 +125,7 @@ void* qmckl_malloc(qmckl_context context, ~qmckl_context~. 4. The function then allocates memory: - If the ~HAVE_HPC~ and ~HAVE_ALIGNED_ALLOC~ macros are defined, the memory + If the ~HAVE_HPC~ and ~HAVE_POSIX_MEMALIGN~ macros are defined, the memory allocation is done using the ~aligned_alloc~ function with a 64-byte alignment, rounding up the requested size to the nearest multiple of 64 bytes. Else, the memory allocation is done using the standard ~malloc~ function. @@ -153,11 +153,11 @@ void* qmckl_malloc(qmckl_context context, const qmckl_memory_info_struct info) { qmckl_context_struct* const ctx = (qmckl_context_struct*) context; /* Allocate memory and zero it */ -#if defined(HAVE_HPC) && defined(HAVE_ALIGNED_ALLOC) - assert( ((info.size+64) >> 6) << 6 >= info.size ); - void * pointer = aligned_alloc(64, ((info.size+64) >> 6) << 6 ); + void * pointer = NULL; +#if defined(HAVE_HPC) && defined(HAVE_POSIX_MEMALIGN) + if (posix_memalign(&pointer, 64, info.size) != 0) pointer = NULL; #else - void * pointer = malloc(info.size); + pointer = malloc(info.size); #endif if (pointer == NULL) { return NULL;