1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
//**************************************************************************
// Vector-vector add benchmark
//--------------------------------------------------------------------------
// Author : Andrew Waterman
// TA : Christopher Celio
// Student :
//
// This benchmark adds two vectors and writes the results to a
// third vector. The input data (and reference data) should be
// generated using the vvadd_gendata.pl perl script and dumped
// to a file named dataset.h
// to print out arrays, etc.
//#define DEBUG
//--------------------------------------------------------------------------
// Includes
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
//--------------------------------------------------------------------------
// Input/Reference Data
#include "dataset.h"
//--------------------------------------------------------------------------
// Basic Utilities and Multi-thread Support
#include "util.h"
//--------------------------------------------------------------------------
// vvadd function
extern void __attribute__((noinline)) vvadd(int coreid, int ncores, size_t n, const data_t* x, const data_t* y, data_t* z);
//--------------------------------------------------------------------------
// Main
//
// all threads start executing thread_entry(). Use their "coreid" to
// differentiate between threads (each thread is running on a separate core).
void thread_entry(int cid, int nc)
{
// static allocates data in the binary, which is visible to both threads
static data_t results_data[DATA_SIZE];
// First do out-of-place vvadd
barrier(nc);
stats(vvadd(cid, nc, DATA_SIZE, input1_data, input2_data, results_data); barrier(nc), DATA_SIZE);
if(cid == 0) {
#ifdef DEBUG
printDoubleArray("out-of-place results: ", DATA_SIZE, results_data);
printDoubleArray("out-of-place verify : ", DATA_SIZE, verify_data);
#endif
int res = verifyDouble(DATA_SIZE, results_data, verify_data);
if(res) exit(res);
}
// Second do in-place vvadd
// Copying input
size_t i;
if(cid == 0) {
for (i = 0; i < DATA_SIZE; i++)
results_data[i] = input1_data[i];
}
barrier(nc);
stats(vvadd(cid, nc, DATA_SIZE, results_data, input2_data, results_data); barrier(nc), DATA_SIZE);
if(cid == 0) {
#ifdef DEBUG
printDoubleArray("in-place results: ", DATA_SIZE, results_data);
printDoubleArray("in-place verify : ", DATA_SIZE, verify_data);
#endif
int res = verifyDouble(DATA_SIZE, results_data, verify_data);
if(res) exit(res);
}
barrier(nc);
exit(0);
}
|