-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLASs.cpp
48 lines (35 loc) · 970 Bytes
/
BLASs.cpp
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
#include "headers.hpp"
extern int myRank;
extern int nbTasks;
double BLAS1(Vector a, Vector b)
{
double pscLoc = 0;
double pscGlob = 0;
for(int i=0; i<a.rows(); i++)
pscLoc += a(i)*b(i);
MPI_Allreduce(&pscLoc, &pscGlob, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
pscGlob = pscGlob;
return pscGlob;
}
Vector BLAS2(Matrix A, Vector x)
{
Vector pMVGlob = Vector::Zero(A.rows());
Vector a = Vector::Zero(x.rows());
for (int i = 0; i < A.rows(); ++i)
{
for (int j = 0; j < x.rows(); ++j)
a(j) = A(i,j);
pMVGlob(i) = BLAS1(a, x);
}
MPI_Scatter(pMVGlob.data(), x.rows(), MPI_DOUBLE, pMVGlob.data(), x.rows(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
pMVGlob.conservativeResize(x.rows());
return pMVGlob;
}
Vector BLAS3(Matrix A, Vector x)
{
Vector pMVGlob = Vector::Zero(A.rows());
pMVGlob = BLAS2(A, x);
pMVGlob = BLAS2(A, pMVGlob) + pMVGlob + x;
pMVGlob.conservativeResize(x.rows());
return pMVGlob;
}