mymkl.c 1.2 KB
Newer Older
1
2
#include <stdio.h>
#include <stdlib.h>
3
#include <math.h>
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 "mymkl.h"
/**********************************************/

void rcopy (int *n, double *x, int *incx, double *y, int *incy) {
  int i, dim = *n, ix = *incx, iy = *incy;
  double *px = x, *py = y;

  for (i=0; i<dim; i++) {
    *py = *px; px += ix; py += iy;
  }
}

void rscal (int *n, double *alpha, double *x, int *incx) {
  int i, dim = *n, ix = *incx;
  double *px = x, a = *alpha;

  for (i=0; i<dim; i++) {
    *px *= a; px += ix;
  }
}

void raxpy (int *n, double *alpha, double *x, int *incx, double *y, int *incy) {
  int i, dim = *n, ix = *incx, iy = *incy;
  double *px = x, *py = y, a = *alpha;

  for (i=0; i<dim; i++) {
    *py += *px * a; px += ix; py += iy;
  }
}

double rdot (int *n, double *x, int *incx, double *y, int *incy) {
  int i, dim = *n, ix = *incx, iy = *incy;
  double aux = 0.0, *px = x, *py = y;

  for (i=0; i<dim; i++) {
    aux += *py * *px; px += ix; py += iy;
  }

  return aux;
}

45
46
47
48
49
50
51
52
53
54
double rnrm2(int *n, double *x, int *incx) {
  int i, dim = *n, ix = *incx;
  double *px = x, sum = 0.0;

  for (i = 0; i < dim; i++) {
    sum += *px * *px; px += ix;
  }
  return sqrt(sum);
}

55
56
/**********************************************/