Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. //#define N 500
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <malloc.h>
  7. #include <time.h>
  8. #include <omp.h>
  9.  
  10. int main(int argc, char *argv[]) {
  11.  
  12. long i, j, k, l, n;
  13. double begin_to, end_to, c;
  14. double **A, *b, *x;
  15. clock_t begin_t, end_t;
  16.  
  17. n=atoi(argv[1]);
  18.  
  19. A=(double**)malloc((n+1)*sizeof(double*));
  20. b=(double*)malloc((n+1)*sizeof(double*));
  21. x=(double*)malloc((n+1)*sizeof(double*));
  22.  
  23. for(i=1;i<=n;i++)
  24. {
  25. A[i]=(double*)malloc((n+1)*sizeof(double*));
  26. }
  27.  
  28. n=2;
  29. A[1][1]=1;
  30. A[1][2]=2;
  31. A[2][1]=3;
  32. A[2][2]=4;
  33. b[1]=5;
  34. b[2]=6;
  35.  
  36. //etap eliminacji zmiennych
  37. for(k=1; k<=n-1; k++)
  38. {
  39. #pragma omp parallel for shared(A, b, k, n) private(i,j,c)
  40. for(i=k+1; i<=n;i++)
  41. {
  42. c=A[i][k]/A[k][k];
  43.  
  44. for(j=k;j<=n;j++)
  45. {
  46. A[i][j]=A[i][j]-c*A[k][j];
  47. }
  48. b[i]=b[i]-c*b[i];
  49. }
  50. }
  51.  
  52. //postepowanie odwrotne
  53. x[n]=b[n]/A[n][n];
  54.  
  55. for(k=n-1;k>=1;k--)
  56. {
  57. x[k]=b[k];
  58. for(j=k+1;j<=n;j++)
  59. {
  60. x[k]=x[k]-A[k][j]*x[j];
  61. }
  62. x[k]=x[k]/A[k][k];
  63. }
  64.  
  65. printf("Rozw.: x[1], x[2] = %f %f\n", x[1], x[2]);
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement