-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallel_non.c
More file actions
66 lines (54 loc) · 1.25 KB
/
parallel_non.c
File metadata and controls
66 lines (54 loc) · 1.25 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//#include <omp.h>
//#include <mpi.h>
#include "config.c"
// function to add the elements of two arrays
// serial
//
void add(int n, float *x, float *y)
{
//
//
for (int i = 0; i < n; i++)
{
y[i] = x[i] + y[i];
}
}
int main()
{
//
//
//
x = calloc(N,sizeof(*x));
y = calloc(N,sizeof(*y));
// initialize x and y arrays on the host
for (int i = 0; i < N; i++) {
x[i] = 1.0;
y[i] = 2.0;
}
//=========================================================
// Run kernel on 1M elements on the CPU
//-------------------------------------
start = timeInMilliseconds();
//----------
for (int i = 0; i<rep; i++)
{
add(N, x, y);
}
//-----------
end = timeInMilliseconds();
//-------------------------------------
//=========================================================
cpu_time_used = ((double) (end-start));
// Check for errors (all values should be 3.0f)
float maxError = 0.0;
for (int i = 0; i < N; i++)
maxError = fmax(maxError, fabs(y[i]-(2.0+rep)));
printf("1:1\t%f\t%f\n",cpu_time_used,maxError);
// Free memory
free(x);
free(y);
return 0;
}