PIPS
vecacc-time.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <sys/time.h>
5 #include <time.h>
6 #include "tools.h"
7 
8 void vecacc(int n, float* src1, float* src2, float* result)
9 {
10  int i;
11 /*#pragma vector aligned
12 #pragma ivdep*/
13  for(i=0;i<n;i++)
14  result[i]+=src1[i]*src2[i];
15 }
16 
17 int main(int argc, char **argv)
18 {
19  int n;
20  float *src1, *src2, *result;
21  n = atoi(argv[1]);
22 
23 #define xmalloc(p) \
24  do { \
25  if (posix_memalign((void **) &p, 32, n * sizeof(float))) \
26  return 3; \
27  } while(0);
28 
29 #define vmalloc(p)\
30  do { \
31  p=(float*)malloc(n*sizeof(float));\
32  } while(0);
33 
34  vmalloc(src1);
35  vmalloc(src2);
36  vmalloc(result);
37 
38  init_data_file(argv[2]);
39  init_data_float(src1, n);
40  init_data_float(src2, n);
42 
43  //struct timeval start,end;
44  //gettimeofday(&start, NULL);
45  struct timespec start,end;
46  clock_gettime(CLOCK_MONOTONIC, &start);
47  vecacc(n, src1, src2, result);
48  clock_gettime(CLOCK_MONOTONIC, &end);
49  double tdiff = end.tv_sec*1000.0+(end.tv_nsec/1000000.0) - (start.tv_sec*1000.0+(start.tv_nsec/1000000.0));
50  printf("Time: %f\n", tdiff);
51 
52  free(src1);
53  free(src2);
54  free(result);
55 
56  return 0;
57 }
58 
59 
static char start[1024]
The name of the variable from which to start counting domain numbers.
Definition: genLisp.c:55
void free(void *)
char end
Definition: gtk_status.c:82
int printf()
void close_data_file()
Definition: tools.c:48
int init_data_float(float *ptr, const unsigned int n)
Definition: tools.c:125
void init_data_file(const char *data_file)
Definition: tools.c:36
int main(int argc, char **argv)
Definition: vecacc-time.c:17
#define vmalloc(p)
void vecacc(int n, float *src1, float *src2, float *result)
Definition: vecacc-time.c:8