bench_blas2.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*****************************************************************************
  2. *
  3. * MODULE: Grass PDE Numerical Library
  4. * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
  5. * soerengebbert <at> gmx <dot> de
  6. *
  7. * PURPOSE: Unit benchs for les creation
  8. *
  9. * COPYRIGHT: (C) 2000 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. #define EPSILON 0.0000001
  23. /* prototypes */
  24. static void bench_blas_level_2_double(int rows);
  25. /* *************************************************************** */
  26. /* Perfrome the blas level 2 unit benchs ************************** */
  27. /* *************************************************************** */
  28. int bench_blas_level_2(int rows)
  29. {
  30. G_message(_("\n++ Running blas level 2 benchmark ++"));
  31. bench_blas_level_2_double(rows);
  32. return 1;
  33. }
  34. /* *************************************************************** */
  35. /* ************** D O U B L E ************************************ */
  36. /* *************************************************************** */
  37. void bench_blas_level_2_double(int rows)
  38. {
  39. double **A, *x, *y, *z;
  40. struct timeval tstart;
  41. struct timeval tend;
  42. G_math_les *les;
  43. les = create_normal_unsymmetric_les(rows);
  44. G_math_les *sples;
  45. sples = create_sparse_unsymmetric_les(rows);
  46. x = G_alloc_vector(rows);
  47. y = G_alloc_vector(rows);
  48. z = G_alloc_vector(rows);
  49. A = G_alloc_matrix(rows, rows);
  50. fill_d_vector_range_1(x, 1, rows);
  51. gettimeofday(&tstart, NULL);
  52. #pragma omp parallel default(shared)
  53. {
  54. G_math_Ax_sparse(sples->Asp, x, z, rows);
  55. }
  56. gettimeofday(&tend, NULL);
  57. G_important_message("Computation time G_math_Ax_sparse: %g\n", compute_time_difference(tstart, tend));
  58. gettimeofday(&tstart, NULL);
  59. #pragma omp parallel default(shared)
  60. {
  61. G_math_d_Ax(les->A, x, z, rows, rows);
  62. }
  63. gettimeofday(&tend, NULL);
  64. G_important_message("Computation time G_math_d_Ax: %g\n", compute_time_difference(tstart, tend));
  65. gettimeofday(&tstart, NULL);
  66. #pragma omp parallel default(shared)
  67. {
  68. G_math_d_aAx_by(les->A, x, y, 3.0, 4.0, z, rows, rows);
  69. }
  70. gettimeofday(&tend, NULL);
  71. G_important_message("Computation time G_math_d_Ax_by: %g\n", compute_time_difference(tstart, tend));
  72. gettimeofday(&tstart, NULL);
  73. #pragma omp parallel default(shared)
  74. {
  75. G_math_d_x_dyad_y(x, x, A, rows, rows);
  76. }
  77. gettimeofday(&tend, NULL);
  78. G_important_message("Computation time G_math_d_x_dyad: %g\n", compute_time_difference(tstart, tend));
  79. gettimeofday(&tstart, NULL);
  80. if(x)
  81. G_free_vector(x);
  82. if(y)
  83. G_free_vector(y);
  84. if(z)
  85. G_free_vector(z);
  86. G_math_free_les(les);
  87. G_math_free_les(sples);
  88. if(A)
  89. G_free_matrix(A);
  90. return;
  91. }