Permalink
Browse files

Allow stream to dynamically allocate its memory, and make

that mode the default.  A compile time change is needed to
change it back to its original behavior.
  • Loading branch information...
Greg Smith Greg Smith
Greg Smith authored and Greg Smith committed Jul 3, 2011
1 parent 8a7c936 commit bc4cbf9d41c3226fccd8069220d72638fd54bf74
Showing with 14 additions and 0 deletions.
  1. +14 −0 stream.c
View
@@ -94,9 +94,14 @@
# define MAX(x,y) ((x)>(y)?(x):(y))
# endif
+#ifdef DYNALLOC
+#include <stdlib.h>
+static double *a, *b, *c;
+#else
static double a[N+OFFSET],
b[N+OFFSET],
c[N+OFFSET];
+#endif
static double avgtime[4] = {0}, maxtime[4] = {0},
mintime[4] = {FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX};
@@ -130,6 +135,15 @@ main()
register int j, k;
double scalar, t, times[4][NTIMES];
+#ifdef DYNALLOC
+ /* Allocate memory dynamically */
+ if (((a = malloc((N + OFFSET) * sizeof(double))) == NULL) ||
+ ((b = malloc((N + OFFSET) * sizeof(double))) == NULL) ||
+ ((c = malloc((N + OFFSET) * sizeof(double))) == NULL)) {
+ printf("Failed to allocate work memory");
+ exit(1);
+ }
+#endif
/* --- SETUP --- determine precision and check timing --- */
printf(HLINE);

0 comments on commit bc4cbf9

Please sign in to comment.