Skip to content

Commit ea59edd

Browse files
committed
added DocOpt.jl to examples/scalar_law/PROGRAM1/linaddmain.jl.
1 parent 8630173 commit ea59edd

File tree

2 files changed

+65
-21
lines changed

2 files changed

+65
-21
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,7 @@ the book _Numerical Solution of Hyperbolic Partial Differential Equations_ by pr
9595
flux = OffsetArray(Float64, 0:ncells)
9696
```
9797

98-
+ UPDATE:
99-
Added
100-
+ examples/scalar_law/PROGRAM0/main_sub.jl
101-
102-
see more details here
103-
+ [room for performance improvement for SubArray #5117](https://github.com/JuliaLang/julia/issues/5117)
104-
105-
+ Timing for baseline with `@unsafe` annotation:
98+
+ Timings for baseline with `@unsafe` annotation:
10699
```sh
107100
0.103402 seconds (21 allocations: 235.531 KB)
108101
```
@@ -117,3 +110,17 @@ the book _Numerical Solution of Hyperbolic Partial Differential Equations_ by pr
117110
0.105967 seconds (217 allocations: 268.094 KB)
118111
```
119112
Only the 2nd timing after warming up is given.
113+
114+
+ UPDATE:
115+
Added
116+
+ examples/scalar_law/PROGRAM1/...
117+
```sh
118+
[~/w/m/O/e/s/PROGRAM1] $ julia linaddmain.jl --cells=10000 --runs=3 ms master|✚ 1…
119+
0.672295 seconds (42.90 k allocations: 1.990 MB)
120+
0.509693 seconds (18 allocations: 313.281 KB)
121+
0.512243 seconds (18 allocations: 313.281 KB)
122+
[~/w/m/O/e/s/PROGRAM1] $ julia linaddmain.jl --cells=100000 --runs=3 6134ms master|✚ 1…
123+
7.270463 seconds (42.90 k allocations: 4.736 MB)
124+
7.177485 seconds (18 allocations: 3.053 MB)
125+
7.248687 seconds (18 allocations: 3.053 MB)
126+
```

examples/scalar_law/PROGRAM1/linaddmain.jl

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
# is completely correct, or that it will work for your purposes.
2121
# Use the software at your own risk.
2222
#***********************************************************************
23-
23+
__precompile__()
2424
using OffsetArrays
25+
using DocOpt
2526

2627
include("consts.jl")
2728

@@ -32,16 +33,13 @@ include("linearad.jl")
3233
include("consdiff.jl")
3334
include("upwind.jl")
3435

35-
function main()
36-
#const ncells = 100
37-
const ncells = 10000
36+
function do_computation(ncells, nsteps, verbose, print_solution)
3837

3938
u = OffsetArray(Float64, -2:ncells+1)
4039
x = OffsetArray(Float64, 0:ncells)
4140
flux = OffsetArray(Float64, 0:ncells)
4241
dfdu = OffsetArray(Float64, -2:ncells+1)
4342

44-
const nsteps = 10000
4543
const tmax = 0.8
4644
const cfl = 0.9
4745

@@ -57,7 +55,10 @@ function main()
5755

5856
initsl(ncells,fc,lc,fm,lm,ifirst,ilast, u,x)
5957

60-
#println("x : $x u : $u")
58+
if verbose
59+
println("x : $x u : $u")
60+
end
61+
6162
bcmesh(fm,lm,ncells, x)
6263
bccells(fc,lc,ncells, u)
6364
fluxderv(fc,lc,fc,lc, u, dfdu)
@@ -76,17 +77,53 @@ function main()
7677
end
7778

7879
# write final results (plot later)
79-
@unsafe for ic=0:ncells-1
80-
#for ic=0:ncells-1
81-
xc = (x[ic]+x[ic+1])*0.5
82-
uc = u[ic]
83-
#@printf("%e %e\n",xc,uc)
80+
if print_solution
81+
@unsafe for ic=0:ncells-1
82+
xc = (x[ic]+x[ic+1])*0.5
83+
uc = u[ic]
84+
@printf("%e %e\n",xc,uc)
85+
end
86+
end
87+
88+
end
89+
90+
function main()
91+
const script_name = basename(Base.source_path())
92+
const doc = """$script_name
93+
94+
Usage:
95+
$script_name -h | --help
96+
$script_name [-v | --verbose] [-p | --print] [--cells=<cells>] [--steps=<steps>] [--runs=<runs>]
97+
98+
Options:
99+
-h --help Show this screen.
100+
-v --verbose Adds verbosity.
101+
-p --print Print solution.
102+
--cells=<cells> Specify a number of cells [default: 100].
103+
--steps=<steps> Specify a number of steps [default: 10000].
104+
--runs=<runs> Specify a number of runs [default: 2].
105+
"""
106+
107+
arguments = docopt(doc)
108+
109+
verbose = arguments["--verbose"]
110+
print_sol = arguments["--print"]
111+
ncells = parse(Int, arguments["--cells"])
112+
nsteps = parse(Int, arguments["--steps"])
113+
nruns = parse(Int, arguments["--runs"])
114+
115+
if verbose
116+
println("ncells: $ncells")
117+
println("nsteps: $nsteps")
84118
end
85119

120+
for r = 1:nruns
121+
@time do_computation(ncells, nsteps, verbose, print_sol)
122+
end
86123

87124
end # main
88125

89-
@time main()
90-
@time main()
126+
main()
127+
91128

92129

0 commit comments

Comments
 (0)