Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define N 500
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <malloc.h>
- #include <time.h>
- #include <omp.h>
- int main(int argc, char *argv[]) {
- long i, j, k, l, n;
- double begin_to, end_to, c;
- double **A, *b, *x;
- clock_t begin_t, end_t;
- n=atoi(argv[1]);
- A=(double**)malloc((n+1)*sizeof(double*));
- b=(double*)malloc((n+1)*sizeof(double*));
- x=(double*)malloc((n+1)*sizeof(double*));
- for(i=1;i<=n;i++)
- {
- A[i]=(double*)malloc((n+1)*sizeof(double*));
- }
- n=2;
- A[1][1]=1;
- A[1][2]=2;
- A[2][1]=3;
- A[2][2]=4;
- b[1]=5;
- b[2]=6;
- //etap eliminacji zmiennych
- for(k=1; k<=n-1; k++)
- {
- #pragma omp parallel for shared(A, b, k, n) private(i,j,c)
- for(i=k+1; i<=n;i++)
- {
- c=A[i][k]/A[k][k];
- for(j=k;j<=n;j++)
- {
- A[i][j]=A[i][j]-c*A[k][j];
- }
- b[i]=b[i]-c*b[i];
- }
- }
- //postepowanie odwrotne
- x[n]=b[n]/A[n][n];
- for(k=n-1;k>=1;k--)
- {
- x[k]=b[k];
- for(j=k+1;j<=n;j++)
- {
- x[k]=x[k]-A[k][j]*x[j];
- }
- x[k]=x[k]/A[k][k];
- }
- printf("Rozw.: x[1], x[2] = %f %f\n", x[1], x[2]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement