-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.c
47 lines (36 loc) · 872 Bytes
/
add.c
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
//********************************************
//
// This is a simple example to demonstrate
// autovectorization. To enable autovectorization
// build with:
//
// icc -O2 add.c (or higher)
// gcc -O3 add.c
//
//********************************************
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv )
{
if (argc != 2) {
printf("usage: ./vec_add vec_size\n");
exit(-1);
}
int vec_size = atoi(argv[1]);
float * a = malloc( vec_size * sizeof(float) );
float * b = malloc( vec_size * sizeof(float) );
float * c = malloc( vec_size * sizeof(float) );
int i;
for (i=0; i<vec_size ; i++)
{
a[i] = (float)i;
b[i] = 2.0 * (float)i + 1.0;
c[i] = a[i] + b[i];
}
if ( vec_size > 10 )
printf("i: %d, c[i]: %f\n",10,c[10]);
free(a);
free(b);
free(c);
return 0;
}