Answer the question
In order to leave comments, you need to log in
openmp. Parallel solution of SLAE?
Given a lower triangular matrix A and a vector b. Find a solution to the system Ax=b. Help, please, with the algorithm for parallelizing this task using OpenMP. Thanks in advance.
Answer the question
In order to leave comments, you need to log in
I decided, sort of, a problem ... Everything works correctly. Here is the code:
#include <stdio.h>
#include <math.h>
#include <omp.h>
#define N 4
#define eps 0.0001
void jacobi(double a[N][N], double b[N], double x[N])
{
int i, j;
double vectorNorm;
double currentX[N];
do {
vectorNorm = 0.0;
#pragma omp parallel for private(i, j)
for(i = 0; i < N; i++) {
currentX[i] = -b[i];
for(j = 0; j < N; j++) {
if(i != j)
currentX[i] += a[i][j] * x[j];
}
currentX[i] /= -a[i][i];
}
#pragma omp parallel for
for(i = 0; i < N; i++) {
if(fabs(x[i] - currentX[i]) > vectorNorm)
vectorNorm = fabs(x[i] - currentX[i]);
x[i] = currentX[i];
}
}
while(vectorNorm > eps);
}
int main() {
int i, j;
double matrixA[N][N] = {
{2,0,0,0},
{1,2,0,0},
{3,1,2,0},
{3,2,1,3}
};
double vectorB[N] = {1,1,1,1}, vectorX[N];
jacobi(matrixA, vectorB, vectorX);
printf("Vector X:\n");
for (i = 0; i < N; i++) {
printf("%.3f ", vectorX[i]);
}
printf("\n");
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question