Skip to content
Newer
Older
100644 50 lines (41 sloc) 1.01 KB
99a2240 @inducer Finish basic vector add.
inducer authored Sep 5, 2012
1 #include "timing.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 int main(int argc, char **argv)
6 {
8a38be3 @inducer Start work on omp.
inducer authored Sep 5, 2012
7 if (argc != 3)
99a2240 @inducer Finish basic vector add.
inducer authored Sep 5, 2012
8 {
9 fprintf(stderr, "need two arguments!\n");
10 abort();
11 }
12
13 const long n = atol(argv[1]);
14 double *x = (double *) malloc(sizeof(double) * n);
15 if (!x) { perror("alloc x"); abort(); }
16 double *y = (double *) malloc(sizeof(double) * n);
17 if (!y) { perror("alloc y"); abort(); }
18 double *z = (double *) malloc(sizeof(double) * n);
19 if (!z) { perror("alloc z"); abort(); }
20
21 for (int i = 0; i < n; ++i)
22 {
23 x[i] = i;
24 y[i] = 2*i;
25 }
26
8a38be3 @inducer Start work on omp.
inducer authored Sep 5, 2012
27 const int ntrips = atoi(argv[2]);
28 printf("doing %d trips...\n", ntrips);
29
fc40978 @inducer Update all demos to new timing code.
inducer authored Sep 9, 2012
30 timestamp_type time1, time2;
31 get_timestamp(&time1);
99a2240 @inducer Finish basic vector add.
inducer authored Sep 5, 2012
32
33 for (int trip = 0; trip < ntrips; ++trip)
34 {
35 for (int i = 0; i < n; ++i)
36 {
37 z[i] = x[i] + y[i];
38 }
39 }
40
fc40978 @inducer Update all demos to new timing code.
inducer authored Sep 9, 2012
41 get_timestamp(&time2);
42 double elapsed = timestamp_diff_in_seconds(time1,time2)/ntrips;
99a2240 @inducer Finish basic vector add.
inducer authored Sep 5, 2012
43 printf("%f GB/s\n",
44 3*n*sizeof(double)/1e9/elapsed);
45 printf("%f GFlops/s\n",
46 n/1e9/elapsed);
cd23a4a @inducer Add MPI example. Add return 0 to places.
inducer authored Sep 5, 2012
47
48 return 0;
99a2240 @inducer Finish basic vector add.
inducer authored Sep 5, 2012
49 }
Something went wrong with that request. Please try again.