Skip to content

Commit 3c9c641

Browse files
committed
profiling of basis function evals vs coefficient multiplications. replaces eval_timing branch
1 parent f161b9d commit 3c9c641

File tree

2 files changed

+119
-4
lines changed

2 files changed

+119
-4
lines changed

profiling/eval_profiling.c

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
get accurate timing comparisons for basis evaluation vs coefficient multiplications
3+
*/
4+
5+
#include "../vergini/basis.h"
6+
#include "../vergini/billiard.h"
7+
#include "../vergini/colloc.h"
8+
#include "../vergini/nrutil.h"
9+
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
#include <time.h>
13+
#include <string.h>
14+
#include <unistd.h>
15+
16+
#define STADIUM 0
17+
#define SINAI 1
18+
19+
int verb = 1;
20+
21+
int main(int argc, char **argv) {
22+
Basis_Set bas;
23+
Billiard bil;
24+
Bdry_Pt_Set bps;
25+
int i,j,n,N;
26+
double **coeffs, *x, *y, **psi, *values;
27+
double k = 500.0, temp;
28+
time_t start;
29+
double basis_time, coeff_time;
30+
char arg;
31+
double b = 10;
32+
double k_base = 20;
33+
34+
if (argc < 7) {
35+
printf("usage: ./eval -l billiard_args -s basis_args -n number_of_evals\n");
36+
exit(-1);
37+
}
38+
39+
// parse command line args
40+
while ((arg = getopt(argc, argv, "l:s:n:")) != -1) {
41+
switch (arg) {
42+
case 'l':
43+
if (parse_billiard(optarg, &bil)==-1) {
44+
printf("failed to parse billiard: %s\n", optarg);
45+
exit(-1);
46+
}
47+
break;
48+
case 's':
49+
if (parse_basis(optarg, &bas)==-1) {
50+
printf("failed to parse basis: %s\n", optarg);
51+
exit(-1);
52+
}
53+
case 'n':
54+
n = atoi(optarg);
55+
break;
56+
}
57+
}
58+
build_billiard(&bil, k_base);
59+
build_bdry(b, k_base, &bil, &bps);
60+
build_basis(k_base, &bil, &bas);
61+
62+
show_billiard_properties(&bil, k_base);
63+
show_colloc_properties(&bil, &bps, k_base);
64+
show_basis_properties(&bil, &bas);
65+
66+
N = bas.N;
67+
68+
// initialize
69+
coeffs = dmatrix(0,n,0,N);
70+
values = dvector(0,n);
71+
for (i = 0; i < N ; i++) {
72+
for (j = 0 ; j < N ; j++) {
73+
coeffs[i][j] = (double)rand() / RAND_MAX;
74+
}
75+
}
76+
77+
x = dvector(0,n);
78+
y = dvector(0,n);
79+
psi = dmatrix(0,n,0,N);
80+
for (i = 0 ; i < n ; i++) {
81+
x[i] = (double)rand() / RAND_MAX;
82+
y[i] = (double)rand() / RAND_MAX;
83+
}
84+
85+
// run & time
86+
start = clock();
87+
for (i = 0 ; i < n ; i++) {
88+
for (j = 0 ; j < bas.N ; j++) {
89+
psi[i][j] = eval_basis(k*x[i], k*y[i], j, &bas);
90+
}
91+
}
92+
basis_time = (double)(clock() - start) / CLOCKS_PER_SEC;
93+
94+
start = clock();
95+
for (i = 0 ; i < n ; i++) {
96+
for (j = 0 ; j < bas.N ; j++) {
97+
values[i] += psi[i][j] * coeffs[i][j];
98+
}
99+
}
100+
coeff_time = (double)(clock() - start) / CLOCKS_PER_SEC;
101+
102+
// print results
103+
printf("basis evals took %g seconds\n", basis_time);
104+
printf("coeff mults took %g seconds\n", coeff_time);
105+
printf("ratio: %f\n", basis_time / coeff_time);
106+
107+
free_dvector(x, 0, n);
108+
free_dvector(y, 0, n);
109+
free_dmatrix(psi, 0, n, 0, N);
110+
free_dmatrix(coeffs, 0, n, 0, N);
111+
free_dvector(values, 0, n);
112+
113+
}

profiling/makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
hank: hankel_profiling.c
2+
gcc -lm -lblas -lgsl hankel_profiling.c -o hank
13

2-
CC=gcc
3-
FLAGS=-lm -lgcc -lblas -lgsl
4+
eval: eval_profiling.o
5+
g++ eval_profiling.o ../vergini/basis.o ../vergini/billiard.o ../vergini/colloc.o ../vergini/grid.o ../vergini/matrix.o ../vergini/nrutil.o ../vergini/useful.o -o eval -I/usr/include/atlas -L/usr/lib64/atlas -L/usr/lib64/lapack -L/usr/lib64/libblas -lgsl -llapack -lblas -lf77blas -latlas -lm
46

5-
profile: hankel_profiling.c
6-
$(CC) $(FLAGS) hankel_profiling.c -o profile
7+
eval_profiling.o: eval_profiling.c
8+
g++ -c eval_profiling.c -I/usr/include/atlas -L/usr/lib64/atlas -lgsl -lgslcblas -llapack -lblas -lf77blas -latlas -lm
79

810
hank103.c: hank103.f
911
f2c hank103.f

0 commit comments

Comments
 (0)