mirror of
https://github.com/TREX-CoE/qmckl.git
synced 2024-12-22 12:23:56 +01:00
Now using posix_memalign
This commit is contained in:
parent
eaa44b45c4
commit
a7523fbf77
24
configure.ac
24
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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
]], [[
|
||||
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=""
|
||||
])
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user