Skip to content

Commit e3adcff

Browse files
committed
added @unsafe annotations for speedup.
1 parent e6a0138 commit e3adcff

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

examples/scalar_law/PROGRAM0/main_offset_array.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ function do_computation(nsteps, ncells, tmax, ifirst, ilast, statelft, statergt,
2929
# loop over timesteps
3030
while istep < nsteps && t < tmax
3131
# right boundary condition: outgoing wave
32-
for ic=ncells:lc
32+
@unsafe for ic=ncells:lc
3333
u[ic]=u[ncells-1]
3434
end
3535
# left boundary condition: specified value
36-
for ic=fc:-1
36+
@unsafe for ic=fc:-1
3737
u[ic]=statelft
3838
end
3939

4040
# upwind fluxes times dt (ie, flux time integral over cell side)
4141
# assumes velocity > 0
4242
vdt=velocity*dt
43-
for ie=ifirst:ilast+1
43+
@unsafe for ie=ifirst:ilast+1
4444
flux[ie]=vdt*u[ie-1]
4545
end
4646

4747
# conservative difference
48-
for ic=ifirst:ilast
48+
@unsafe for ic=ifirst:ilast
4949
u[ic] -= (flux[ic+1]-flux[ic]) / (x[ic+1]-x[ic])
5050
end
5151

@@ -98,27 +98,27 @@ function main()
9898

9999
# uniform mesh:
100100
dx=(x_right-x_left)/ncells
101-
for ie in ifirst:ilast+1
101+
@unsafe for ie in ifirst:ilast+1
102102
x[ie]=x_left+ie*dx
103103
end
104104

105105
# initial values for diffential equation:
106106
ijump=max(ifirst-1,min(convert(Int,round(ncells*(jump-x_left)/(x_right-x_left))),ilast+1))
107107
# left state to left of jump
108-
for ic=ifirst:ijump-1
108+
@unsafe for ic=ifirst:ijump-1
109109
u[ic]=statelft
110110
end
111111
# volume-weighted average in cell containing jump
112112
frac=(jump-x_left-ijump*dx)/(x_right-x_left)
113113
u[ijump]=statelft*frac+statergt*(1.0-frac)
114114
# right state to right of jump
115-
for ic=ijump+1:ilast
115+
@unsafe for ic=ijump+1:ilast
116116
u[ic]=statergt
117117
end
118118

119119
# stable timestep (independent of time for linear advection):
120120
mindx=1.0e300
121-
for ic=ifirst:ilast
121+
@unsafe for ic=ifirst:ilast
122122
mindx=min(mindx,x[ic+1]-x[ic])
123123
end
124124

@@ -127,7 +127,7 @@ function main()
127127
u = do_computation(nsteps, ncells, tmax, ifirst, ilast, statelft, statergt, velocity, dt, fc, lc, flux, x, u)
128128

129129
# write final results (plot later)
130-
for ic=0:ncells-1
130+
@unsafe for ic=0:ncells-1
131131
xc = (x[ic]+x[ic+1])*0.5
132132
uc = u[ic]
133133
#@printf("%e %e\n",xc,uc)

0 commit comments

Comments
 (0)