-
Notifications
You must be signed in to change notification settings - Fork 0
/
sp.c
49 lines (40 loc) · 1.16 KB
/
sp.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
47
48
49
/*
*
* Note that the result matrix r is not initisialised to 0.
*/
#include <stdio.h>
#include <string.h>
#include "smat.h"
#include "mm.c"
#include "strassenParallel.c"
void smat_memset(struct smat *m)
{
int i;
for (i = 0; i < m->rows; i++)
memset (m->data[i],'0', m->cols * sizeof(double));
}
/* Matrix multiplication, r = a x b */
void smat_mult(const struct smat *a, const struct smat *b, struct smat *r)
{
smat_memset(r);
strassenParallel(a->data, b->data, r->data, a->rows);
}
/*
* Matrix-vector multiplication, r = a x v
* NOTE: a is the matrix, v is the vector. This means v->cols is always 1.
* The result is always a vector (r->cols == 1).
*/
void smat_vect(const struct smat *a, const struct smat *v, struct smat *r)
{
parallelOperation(a->data, v->data, r->data, a->rows, VECTOR);
}
/* Matrix addition, i.e. r = a + b */
void smat_add(const struct smat *a, const struct smat *b, struct smat *r)
{
parallelOperation(a->data, b->data, r->data, a->rows, ADD);
}
/* Scale matrix a by constant alpha */
void smat_scale(const struct smat *a, const struct smat *alpha, struct smat *r)
{
parallelOperation(a->data, alpha->data, r->data, a->rows, SCALE);
}