bench_solver_direct.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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: benchmarking the direct solvers
  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 <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <grass/glocale.h>
  20. #include <grass/gmath.h>
  21. #include "test_gmath_lib.h"
  22. #include <sys/time.h>
  23. /* prototypes */
  24. static int bench_solvers(int rows);
  25. /* ************************************************************************* */
  26. /* Performe the solver unit tests ****************************************** */
  27. /* ************************************************************************* */
  28. int bench_solvers_direct(int rows) {
  29. G_message(_("\n++ Running direct solver benchmark ++"));
  30. bench_solvers(rows);
  31. return 1;
  32. }
  33. /* *************************************************************** */
  34. /* Test all implemented solvers for sparse and normal matrix *** */
  35. /* *************************************************************** */
  36. int bench_solvers(int rows) {
  37. G_math_les *les;
  38. struct timeval tstart;
  39. struct timeval tend;
  40. G_message("\t * benchmarking gmath lu decomposition solver with unsymmetric matrix\n");
  41. les = create_normal_unsymmetric_les(rows);
  42. gettimeofday(&tstart, NULL);
  43. G_math_solver_lu(les->A, les->x, les->b, les->rows);
  44. gettimeofday(&tend, NULL);
  45. printf("Computation time gmath lu decomposition: %g\n", compute_time_difference(tstart, tend));
  46. G_math_free_les(les);
  47. G_message("\t * benchmarking lu ccmath decomposition solver with unsymmetric matrix\n");
  48. les = create_normal_unsymmetric_les(rows);
  49. gettimeofday(&tstart, NULL);
  50. G_math_solv(les->A, les->b, les->rows);
  51. gettimeofday(&tend, NULL);
  52. printf("Computation time ccmath lu decomposition: %g\n", compute_time_difference(tstart, tend));
  53. G_math_free_les(les);
  54. G_message("\t * benchmarking gauss elimination solver with unsymmetric matrix\n");
  55. les = create_normal_unsymmetric_les(rows);
  56. gettimeofday(&tstart, NULL);
  57. G_math_solver_gauss(les->A, les->x, les->b, les->rows);
  58. gettimeofday(&tend, NULL);
  59. printf("Computation time gauss elimination: %g\n", compute_time_difference(tstart, tend));
  60. G_math_free_les(les);
  61. G_message("\t * benchmarking gmath cholesky decomposition solver with symmetric matrix\n");
  62. les = create_normal_symmetric_les(rows);
  63. gettimeofday(&tstart, NULL);
  64. G_math_solver_cholesky(les->A, les->x, les->b, les->rows, les->rows);
  65. gettimeofday(&tend, NULL);
  66. printf("Computation time gmath cholesky decomposition: %g\n", compute_time_difference(tstart, tend));
  67. G_math_free_les(les);
  68. G_message("\t * benchmarking ccmath cholesky decomposition solver with symmetric matrix\n");
  69. les = create_normal_symmetric_les(rows);
  70. gettimeofday(&tstart, NULL);
  71. G_math_solvps(les->A, les->b, les->rows);
  72. gettimeofday(&tend, NULL);
  73. printf("Computation time ccmath cholesky decomposition: %g\n", compute_time_difference(tstart, tend));
  74. G_math_free_les(les);
  75. G_message("\t * benchmarking gmath cholesky band matrix decomposition solver with symmetric band matrix\n");
  76. les = create_symmetric_band_les(rows);
  77. gettimeofday(&tstart, NULL);
  78. G_math_solver_cholesky_sband(les->A, les->x, les->b, les->rows, les->rows);
  79. gettimeofday(&tend, NULL);
  80. printf("Computation time cholesky band matrix decomposition: %g\n", compute_time_difference(tstart, tend));
  81. G_math_free_les(les);
  82. return 1;
  83. }