-
-
Notifications
You must be signed in to change notification settings - Fork 291
/
bench_blas2.c
122 lines (101 loc) · 3.33 KB
/
bench_blas2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*****************************************************************************
*
* MODULE: Grass PDE Numerical Library
* AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
* soerengebbert <at> gmx <dot> de
*
* PURPOSE: Unit benchs for les creation
*
* COPYRIGHT: (C) 2000 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*
*****************************************************************************/
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/gmath.h>
#include <math.h>
#include "test_gmath_lib.h"
#include <sys/time.h>
#define EPSILON 0.0000001
/* prototypes */
static void bench_blas_level_2_double(int rows);
/* *************************************************************** */
/* Perfrome the blas level 2 unit benchs ************************** */
/* *************************************************************** */
int bench_blas_level_2(int rows)
{
G_message(_("\n++ Running blas level 2 benchmark ++"));
bench_blas_level_2_double(rows);
return 1;
}
/* *************************************************************** */
/* ************** D O U B L E ************************************ */
/* *************************************************************** */
void bench_blas_level_2_double(int rows)
{
double **A, *x, *y, *z;
struct timeval tstart;
struct timeval tend;
G_math_les *les;
les = create_normal_unsymmetric_les(rows);
G_math_les *bles;
bles = create_symmetric_band_les(rows);
G_math_les *sples;
sples = create_sparse_unsymmetric_les(rows);
x = G_alloc_vector(rows);
y = G_alloc_vector(rows);
z = G_alloc_vector(rows);
A = G_alloc_matrix(rows, rows);
fill_d_vector_range_1(x, 1, rows);
gettimeofday(&tstart, NULL);
#pragma omp parallel default(shared)
{
G_math_Ax_sparse(sples->Asp, x, z, rows);
}
gettimeofday(&tend, NULL);
printf("Computation time G_math_Ax_sparse: %g\n", compute_time_difference(tstart, tend));
gettimeofday(&tstart, NULL);
#pragma omp parallel default(shared)
{
G_math_Ax_sband(bles->A, x, z, rows, rows);
}
gettimeofday(&tend, NULL);
printf("Computation time G_math_Ax_sband: %g\n", compute_time_difference(tstart, tend));
gettimeofday(&tstart, NULL);
#pragma omp parallel default(shared)
{
G_math_d_Ax(les->A, x, z, rows, rows);
}
gettimeofday(&tend, NULL);
printf("Computation time G_math_d_Ax: %g\n", compute_time_difference(tstart, tend));
gettimeofday(&tstart, NULL);
#pragma omp parallel default(shared)
{
G_math_d_aAx_by(les->A, x, y, 3.0, 4.0, z, rows, rows);
}
gettimeofday(&tend, NULL);
printf("Computation time G_math_d_Ax_by: %g\n", compute_time_difference(tstart, tend));
gettimeofday(&tstart, NULL);
#pragma omp parallel default(shared)
{
G_math_d_x_dyad_y(x, x, A, rows, rows);
}
gettimeofday(&tend, NULL);
printf("Computation time G_math_d_x_dyad: %g\n", compute_time_difference(tstart, tend));
gettimeofday(&tstart, NULL);
if(x)
G_free_vector(x);
if(y)
G_free_vector(y);
if(z)
G_free_vector(z);
G_math_free_les(les);
G_math_free_les(bles);
G_math_free_les(sples);
if(A)
G_free_matrix(A);
return;
}