forked from richloft/RBF-FD-Prototype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvance.c
135 lines (106 loc) · 3.11 KB
/
advance.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdlib.h>
#include <floating_types.h>
#include <profiling.h>
extern timing_struct local_timer;
void halo_update(fType* S);
void RK3_advance(const fType dt, fType *t, const int NPts, fType *S, void (*f)( const fType t, const fType* S, fType* K)){
const fType sixth = 1.0/6.0;
fType *K1;
fType *K2;
fType *K3;
fType *K = (fType*) malloc(NPts * sizeof(fType));
fType *dS = (fType*) malloc(NPts * sizeof(fType));
fType *Stmp1 = (fType*) malloc(NPts * sizeof(fType));
fType *Stmp2 = (fType*) malloc(NPts * sizeof(fType));
double t_start = getTime();
K1 = K;
f((*t), S, K1);
local_timer.t_rhs += (getTime() - t_start);
t_start = getTime();
for(int i=0; i<NPts; i++){
Stmp1[i] = S[i] + 0.5*dt*K1[i]; //2 flop/site
Stmp2[i] = S[i] - dt*K1[i]; //2 flop/site
dS[i] = K1[i];
}
local_timer.t_update += (getTime() - t_start);
t_start = getTime();
K2 = K;
f((*t)+0.5*dt, Stmp1, K2);
local_timer.t_rhs += (getTime() - t_start);
t_start = getTime();
for(int i=0; i<NPts; i++){
Stmp2[i] += 2.0*dt*K2[i]; //2 flop/site
dS[i] += 4.0*K1[i]; //2 flop/site
}
local_timer.t_update += (getTime() - t_start);
t_start = getTime();
K3 = K;
f((*t)+dt, Stmp2, K3);
local_timer.t_rhs += (getTime() - t_start);
t_start = getTime();
for(int i=0; i<NPts; i++){
S[i] += (sixth*dt)*(dS[i]+K3[i]); //2 flop/site
}
local_timer.t_update += (getTime() - t_start);
(*t) += dt;
free(K);
free(dS);
free(Stmp1);
free(Stmp2);
}
void RK4_advance(const fType dt, fType *t, int NPts, fType *S, void (*f)( const fType t, const fType* S, fType* K)){
const fType sixth = 1.0/6.0;
fType *K1;
fType *K2;
fType *K3;
fType *K4;
fType *dS = (fType*) malloc(NPts * sizeof(fType));
fType *Stmp = (fType*) malloc(NPts * sizeof(fType));
fType *K = (fType*) malloc(NPts * sizeof(fType));
double t_start = getTime();
K1 = K;
f((*t),S,K1);
local_timer.t_rhs += (getTime() - t_start);
t_start = getTime();
for(int i=0; i<NPts; i++){
Stmp[i] = S[i] + 0.5*dt*K1[i]; // 2 flop/site
dS[i] = K1[i];
}
halo_update(Stmp);
local_timer.t_update += (getTime() - t_start);
t_start = getTime();
K2 = K;
f((*t)+0.5*dt, Stmp, K2);
local_timer.t_rhs += (getTime() - t_start);
t_start = getTime();
for(int i=0; i<NPts; i++){
Stmp[i] = S[i] + 0.5*dt*K2[i]; // 2 flop/site
dS[i] += 2.0*K2[i]; // 2 flop/site
}
halo_update(Stmp);
local_timer.t_update += (getTime() - t_start);
t_start = getTime();
K3 = K;
f((*t)+0.5*dt, Stmp, K3);
local_timer.t_rhs += (getTime() - t_start);
t_start = getTime();
for(int i=0; i<NPts; i++){
Stmp[i] = S[i] + dt*K3[i]; // 2 flop/site
dS[i] += 2.0*K3[i]; // 2 flop/site
}
halo_update(Stmp);
local_timer.t_update += (getTime() - t_start);
t_start = getTime();
K4 = K;
f((*t)+dt, Stmp, K4);
local_timer.t_rhs += (getTime() - t_start);
t_start = getTime();
for(int i=0; i<NPts; i++)
S[i] += (sixth*dt)*(dS[i]+K4[i]); //2 flop/site
halo_update(S);
local_timer.t_update += (getTime() - t_start);
free(K);
free(dS);
free(Stmp);
(*t) += dt;
}