solver_blas.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Tema 2 ASC
  3. * 2020 Spring
  4. */
  5. #include "utils.h"
  6. /*
  7. * Add your BLAS implementation here
  8. */
  9. #include <string.h>
  10. #include <cblas.h>
  11. double* my_solver(int N, double *A, double *B) {
  12. int i, j;
  13. double *C, *D, *E;
  14. C = (double *) malloc(N * N * sizeof(double));
  15. D = (double *) malloc(N * N * sizeof(double));
  16. E = (double *) malloc(N * N * sizeof(double));
  17. memcpy(D, B, N * N * sizeof(double));
  18. cblas_dtrmm(
  19. CblasRowMajor, /* CBLAS_LAYOUT */
  20. CblasRight, /* CBLAS_SIDE */
  21. CblasUpper, /* CBLAS_UPLO */
  22. CblasTrans, /* CBLAS_TRANSPOSE */
  23. CblasNonUnit, /* CBLAS_DIAG */
  24. N, /* M */
  25. N, /* N */
  26. 1.0, /* ALPHA */
  27. A, /* A */
  28. N, /* LDA */
  29. D, /* B */
  30. N /* LDB */
  31. );
  32. memcpy(E, B, N * N * sizeof(double));
  33. cblas_dtrmm(
  34. CblasRowMajor, /* CBLAS_LAYOUT */
  35. CblasLeft, /* CBLAS_SIDE */
  36. CblasUpper, /* CBLAS_UPLO */
  37. CblasNoTrans, /* CBLAS_TRANSPOSE */
  38. CblasNonUnit, /* CBLAS_DIAG */
  39. N, /* M */
  40. N, /* N */
  41. 1.0, /* ALPHA */
  42. A, /* A */
  43. N, /* LDA */
  44. E, /* B */
  45. N /* LDB */
  46. );
  47. cblas_dtrmm(
  48. CblasRowMajor, /* CBLAS_LAYOUT */
  49. CblasLeft, /* CBLAS_SIDE */
  50. CblasUpper, /* CBLAS_UPLO */
  51. CblasNoTrans, /* CBLAS_TRANSPOSE */
  52. CblasNonUnit, /* CBLAS_DIAG */
  53. N, /* M */
  54. N, /* N */
  55. 1.0, /* ALPHA */
  56. A, /* A */
  57. N, /* LDA */
  58. E, /* B */
  59. N /* LDB */
  60. );
  61. for (i = 0; i < N; i++)
  62. for (j = 0; j < N; j++)
  63. C[(i * N) + j] = D[(i * N) + j] + E[(i * N) + j];
  64. free(D);
  65. free(E);
  66. return C;
  67. }