Skip to content

Commit

Permalink
Replace memalign() with posix_memalign()
Browse files Browse the repository at this point in the history
Memalign() is absent on some systems, use posix_memalign() instead.
  • Loading branch information
ppenzin committed Mar 14, 2024
1 parent badf9ad commit a79c614
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/common.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* Make glibc happy with posix_memalign() */
#define _POSIX_C_SOURCE 200112L

#include "common.h"
#include "array_defs.h"

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

void set_1d_array(real_t * arr, int length, real_t value, int stride);
Expand Down Expand Up @@ -155,8 +156,13 @@ void set_2d_array(real_t arr[LEN_2D][LEN_2D], real_t value, int stride)
}

void init(int** ip, real_t* s1, real_t* s2){
xx = (real_t*) memalign(ARRAY_ALIGNMENT, LEN_1D*sizeof(real_t));
*ip = (int *) memalign(ARRAY_ALIGNMENT, LEN_1D*sizeof(real_t));
int xx_errno = posix_memalign((void**)&xx, ARRAY_ALIGNMENT, LEN_1D*sizeof(real_t));
int ip_errno = posix_memalign((void**)ip, ARRAY_ALIGNMENT, LEN_1D*sizeof(real_t));

if (xx_errno || ip_errno) {
fprintf(stderr, "init: failed to allocate arrays\n");
exit(1);
}

for (int i = 0; i < LEN_1D; i = i+5){
(*ip)[i] = (i+4);
Expand Down

0 comments on commit a79c614

Please sign in to comment.