2d0ca0736114151cc7e15db2e05b2c6a2488c86f
1 //**************************************************************************
2 // Vector-vector add benchmark
3 //--------------------------------------------------------------------------
4 // Author : Andrew Waterman
5 // TA : Christopher Celio
8 // This benchmark adds two vectors and writes the results to a
9 // third vector. The input data (and reference data) should be
10 // generated using the vvadd_gendata.pl perl script and dumped
11 // to a file named dataset.h
13 // to print out arrays, etc.
16 //--------------------------------------------------------------------------
24 //--------------------------------------------------------------------------
25 // Input/Reference Data
30 //--------------------------------------------------------------------------
31 // Basic Utilities and Multi-thread Support
36 //--------------------------------------------------------------------------
39 extern void __attribute__((noinline
)) vvadd(int coreid
, int ncores
, size_t n
, const data_t
* x
, const data_t
* y
, data_t
* z
);
42 //--------------------------------------------------------------------------
45 // all threads start executing thread_entry(). Use their "coreid" to
46 // differentiate between threads (each thread is running on a separate core).
48 void thread_entry(int cid
, int nc
)
50 // static allocates data in the binary, which is visible to both threads
51 static data_t results_data
[DATA_SIZE
];
53 // First do out-of-place vvadd
55 stats(vvadd(cid
, nc
, DATA_SIZE
, input1_data
, input2_data
, results_data
); barrier(nc
), DATA_SIZE
);
59 printDoubleArray("out-of-place results: ", DATA_SIZE
, results_data
);
60 printDoubleArray("out-of-place verify : ", DATA_SIZE
, verify_data
);
62 int res
= verifyDouble(DATA_SIZE
, results_data
, verify_data
);
66 // Second do in-place vvadd
70 for (i
= 0; i
< DATA_SIZE
; i
++)
71 results_data
[i
] = input1_data
[i
];
74 stats(vvadd(cid
, nc
, DATA_SIZE
, results_data
, input2_data
, results_data
); barrier(nc
), DATA_SIZE
);
78 printDoubleArray("in-place results: ", DATA_SIZE
, results_data
);
79 printDoubleArray("in-place verify : ", DATA_SIZE
, verify_data
);
81 int res
= verifyDouble(DATA_SIZE
, results_data
, verify_data
);