bench_blas2.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 *bles;
  45. bles = create_symmetric_band_les(rows);
  46. G_math_les *sples;
  47. sples = create_sparse_unsymmetric_les(rows);
  48. x = G_alloc_vector(rows);
  49. y = G_alloc_vector(rows);
  50. z = G_alloc_vector(rows);
  51. A = G_alloc_matrix(rows, rows);
  52. fill_d_vector_range_1(x, 1, rows);
  53. gettimeofday(&tstart, NULL);
  54. #pragma omp parallel default(shared)
  55. {
  56. G_math_Ax_sparse(sples->Asp, x, z, rows);
  57. }
  58. gettimeofday(&tend, NULL);
  59. printf("Computation time G_math_Ax_sparse: %g\n", compute_time_difference(tstart, tend));
  60. gettimeofday(&tstart, NULL);
  61. #pragma omp parallel default(shared)
  62. {
  63. G_math_Ax_sband(bles->A, x, z, rows, rows);
  64. }
  65. gettimeofday(&tend, NULL);
  66. printf("Computation time G_math_Ax_sband: %g\n", compute_time_difference(tstart, tend));
  67. gettimeofday(&tstart, NULL);
  68. #pragma omp parallel default(shared)
  69. {
  70. G_math_d_Ax(les->A, x, z, rows, rows);
  71. }
  72. gettimeofday(&tend, NULL);
  73. printf("Computation time G_math_d_Ax: %g\n", compute_time_difference(tstart, tend));
  74. gettimeofday(&tstart, NULL);
  75. #pragma omp parallel default(shared)
  76. {
  77. G_math_d_aAx_by(les->A, x, y, 3.0, 4.0, z, rows, rows);
  78. }
  79. gettimeofday(&tend, NULL);
  80. printf("Computation time G_math_d_Ax_by: %g\n", compute_time_difference(tstart, tend));
  81. gettimeofday(&tstart, NULL);
  82. #pragma omp parallel default(shared)
  83. {
  84. G_math_d_x_dyad_y(x, x, A, rows, rows);
  85. }
  86. gettimeofday(&tend, NULL);
  87. printf("Computation time G_math_d_x_dyad: %g\n", compute_time_difference(tstart, tend));
  88. gettimeofday(&tstart, NULL);
  89. if(x)
  90. G_free_vector(x);
  91. if(y)
  92. G_free_vector(y);
  93. if(z)
  94. G_free_vector(z);
  95. G_math_free_les(les);
  96. G_math_free_les(bles);
  97. G_math_free_les(sples);
  98. if(A)
  99. G_free_matrix(A);
  100. return;
  101. }