daxpy.c 684 Bytes
Newer Older
kuhnm's avatar
kuhnm committed
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
#include<stdio.h>
#define N 8  // size of vector
#define R 10 // number of repetitions


// daxpy: Y = aX + Y (n size vector, a constant, X,Y vectors)
void daxpy(double* x, double* y, double a, int n)
{
  int i;
  for (i = 0; i < n; i++) {
    y[i] = a * x[i] + y[i];
  }
}

// pretty print vector
void print_vector(double* vec, int n)
{
  int i;
  for (i=0; i<n-1; i++) {
    printf("%f,\t",vec[i]);
  }
  printf("%f",vec[n-1]);
  printf("\n");
}

void main()
{
  static double x[N], y[N];
  double a = 5.5;
  int i;
  
  for (i = 0; i<N; i++) {
    x[i] = 7.833667;
    y[i] = 0;
  }

  print_vector(y, N);

  for (i = 0; i<R; i++) {
    daxpy(x,y,a,N);
  }

  print_vector(y,N);
}