Permalink
Browse files

Finish basic vector add.

  • Loading branch information...
inducer committed Sep 5, 2012
1 parent 37253a5 commit 99a22400b041755bb862768487337c94cbaadd5d
Showing with 153 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. 0 000-timing-example.c → 00-timing-soln.c
  3. +46 −0 01-sequential-soln.c
  4. +33 −0 01-sequential-start.c
  5. +46 −0 02-flexible-soln.c
  6. +17 −2 notes.txt
  7. +5 −0 reset.sh
  8. +5 −0 set-governor
View
@@ -1,3 +1,4 @@
a.out
.*.swp
*~
+*-demo.c
File renamed without changes.
View
@@ -0,0 +1,46 @@
+#include "timing.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ if (argc != 2)
+ {
+ // STRIP
+ fprintf(stderr, "need two arguments!\n");
+ abort();
+ }
+
+ const long n = atol(argv[1]);
+ double *x = (double *) malloc(sizeof(double) * n);
+ if (!x) { perror("alloc x"); abort(); }
+ double *y = (double *) malloc(sizeof(double) * n);
+ if (!y) { perror("alloc y"); abort(); }
+ double *z = (double *) malloc(sizeof(double) * n);
+ if (!z) { perror("alloc z"); abort(); }
+
+ for (int i = 0; i < n; ++i)
+ {
+ x[i] = i;
+ y[i] = 2*i;
+ }
+
+ struct timespec time1, time2;
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
+
+ const int ntrips = 2;
+ for (int trip = 0; trip < ntrips; ++trip)
+ {
+ for (int i = 0; i < n; ++i)
+ {
+ z[i] = x[i] + y[i];
+ }
+ }
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
+ double elapsed = timespec_diff_in_seconds(time1,time2)/ntrips;
+ printf("%f GB/s\n",
+ 3*n*sizeof(double)/1e9/elapsed);
+ printf("%f GFlops/s\n",
+ n/1e9/elapsed);
+}
View
@@ -0,0 +1,33 @@
+#include "timing.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ if (argc != 2)
+ {
+ // FIXME
+ }
+
+ const long n = atol(argv[1]);
+ double *x = (double *) malloc(sizeof(double) * n);
+ double *y = (double *) malloc(sizeof(double) * n);
+ double *z = (double *) malloc(sizeof(double) * n);
+
+ for (int i = 0; i < n; ++i)
+ {
+ x[i] = i;
+ y[i] = 2*i;
+ }
+
+ struct timespec time1, time2;
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
+
+ // FIXME
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
+ printf("%f seconds for %d entries\n",
+ timespec_diff_in_seconds(time1,time2),
+ n);
+}
+
View
@@ -0,0 +1,46 @@
+#include "timing.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ if (argc != 2)
+ {
+ // STRIP
+ fprintf(stderr, "need two arguments!\n");
+ abort();
+ }
+
+ const long n = atol(argv[1]);
+ double *x = (double *) malloc(sizeof(double) * n);
+ if (!x) { perror("alloc x"); abort(); }
+ double *y = (double *) malloc(sizeof(double) * n);
+ if (!y) { perror("alloc y"); abort(); }
+ double *z = (double *) malloc(sizeof(double) * n);
+ if (!z) { perror("alloc z"); abort(); }
+
+ for (int i = 0; i < n; ++i)
+ {
+ x[i] = i;
+ y[i] = 2*i;
+ }
+
+ struct timespec time1, time2;
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
+
+ const int ntrips = 2;
+ for (int trip = 0; trip < ntrips; ++trip)
+ {
+ for (int i = 0; i < n; ++i)
+ {
+ z[i] = x[i] + y[i];
+ }
+ }
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
+ double elapsed = timespec_diff_in_seconds(time1,time2)/ntrips;
+ printf("%f GB/s\n",
+ 3*n*sizeof(double)/1e9/elapsed);
+ printf("%f GFlops/s\n",
+ n/1e9/elapsed);
+}
View
@@ -1,8 +1,23 @@
-000-timing-example.c:
+colorscheme evening
+
+00-timing-example.c:
- basic timing
- run into all errors
- -O3
- enable result printing
- time again
-001-simple.c:
+01-simple.c:
+- simple timing
+- run into segfault
+ - debug it
+- what do the numbers mean?
+- timing repeatability
+- O3
+- set-governor performance/ondemand
+- run through a few decades
+ - why is it doing what it's doing?!
+ - Control flow overhead
+ - Cache
+
+02-flexible.c:
View
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+for i in *-start.c; do
+ echo cp $i ${i%%-start.c}-demo.c
+done
View
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+for i in 0 1 2 3; do
+ cpufreq-set -g $1 -c 1
+done

0 comments on commit 99a2240

Please sign in to comment.