Start Task 3
This commit is contained in:
parent
4134eda893
commit
3eb349f81c
32 changed files with 475 additions and 16 deletions
38
2025.03.28/03Ex/matrix.c
Normal file
38
2025.03.28/03Ex/matrix.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "matrix.h"
|
||||
#include <math.h>
|
||||
|
||||
void init_vec_b(const double * restrict a, double * restrict b, int n)
|
||||
{
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
double sum = 0;
|
||||
|
||||
#pragma omp simd reduction(+:sum)
|
||||
for (int k = 1; k < n; k+=2)
|
||||
sum += a[i * n + k];
|
||||
|
||||
b[i] = sum;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* OLD VERSION
|
||||
void matvec_mul(int n, const double * restrict A, const double * restrict x, double * restrict x_k)
|
||||
{
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
double sum = 0;
|
||||
#pragma omp simd reduction(+:sum)
|
||||
for (int j = 0; j < n; j++)
|
||||
sum += A[i * n + j] * x[j];
|
||||
x_k[i] = sum;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void matvec_mul(int n, const double * restrict A, const double * restrict x, double * restrict x_k)
|
||||
{
|
||||
cblas_dgemv(CblasRowMajor, CblasdNoTrans, n, n, 1.0, A, n, x, 1, 0.0, x_k, 1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue