Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace memalign() with posix_memalign() #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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