bench_blas3.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*****************************************************************************
  2. *
  3. * MODULE: Grass PDE Numerical Library
  4. * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2007
  5. * soerengebbert <at> gmx <dot> de
  6. *
  7. * PURPOSE: Unit benchs for les creation
  8. *
  9. * COPYRIGHT: (C) 2007 by the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General Public
  12. * License (>=v2). Read the file COPYING that comes with GRASS
  13. * for details.
  14. *
  15. *****************************************************************************/
  16. #include <grass/gis.h>
  17. #include <grass/glocale.h>
  18. #include <grass/gmath.h>
  19. #include <math.h>
  20. #include "test_gmath_lib.h"
  21. #include <sys/time.h>
  22. /* prototypes */
  23. static void bench_blas_level_3_double(int rows);
  24. /* *************************************************************** */
  25. /* Perfrome the blas level 3 benchs ****************************** */
  26. /* *************************************************************** */
  27. int bench_blas_level_3(int rows)
  28. {
  29. G_message(_("\n++ Running blas level 3 benchmark ++"));
  30. bench_blas_level_3_double(rows);
  31. return 1;
  32. }
  33. /* *************************************************************** */
  34. /* ************** D O U B L E ************************************ */
  35. /* *************************************************************** */
  36. void bench_blas_level_3_double(int rows)
  37. {
  38. struct timeval tstart;
  39. struct timeval tend;
  40. double **A, **B, **C, *x, *y;
  41. x = G_alloc_vector(rows);
  42. y = G_alloc_vector(rows);
  43. A = G_alloc_matrix(rows, rows);
  44. B = G_alloc_matrix(rows, rows);
  45. C = G_alloc_matrix(rows, rows);
  46. fill_d_vector_range_1(x, 1, rows);
  47. fill_d_vector_range_1(y, 1, rows);
  48. fill_d_vector_range_1(A[0], 1, rows*rows);
  49. fill_d_vector_range_1(B[0], 1, rows*rows);
  50. gettimeofday(&tstart, NULL);
  51. #pragma omp parallel default(shared)
  52. {
  53. G_math_d_aA_B(A, B, 4.0 , C, rows , rows);
  54. }
  55. gettimeofday(&tend, NULL);
  56. printf("Computation time G_math_d_aA_B: %g\n", compute_time_difference(tstart, tend));
  57. gettimeofday(&tstart, NULL);
  58. #pragma omp parallel default(shared)
  59. {
  60. G_math_d_AB(A, B, C, rows , rows , rows);
  61. }
  62. gettimeofday(&tend, NULL);
  63. printf("Computation time G_math_d_AB: %g\n", compute_time_difference(tstart, tend));
  64. if(x)
  65. G_free_vector(x);
  66. if(y)
  67. G_free_vector(y);
  68. if(A)
  69. G_free_matrix(A);
  70. if(B)
  71. G_free_matrix(B);
  72. if(C)
  73. G_free_matrix(C);
  74. return;
  75. }