You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also during Julia 0.5, `@inbounds` will not remove the internal
52
-
bounds-checking that happens when using an OffsetArray. Until this
53
-
changes, you can often accomplish the same task with `@unsafe`:
54
-
55
-
```jl
56
-
v =OffsetArray(rand(1000), 0:999)
57
-
@unsafefor i inindices(v, 1)
58
-
v[i] +=1
59
-
end
60
-
```
61
-
62
-
With such annotation, `OffsetArray`s are as performant as `Array`s.
63
-
64
-
`@unsafe` is not as powerful as `@inbounds`, and it is possible to set
65
-
up situations where it fails to remove bounds checks. However, it
66
-
suffices for many uses.
67
-
68
-
# Comparison with Fortran
69
-
70
-
The original purpose of the package was to simplify translation of Fortran codes, say
71
-
* the codes accompanying the book _Numerical Solution of Hyperbolic Partial Differential Equations_ by prof. John A. Trangenstein
72
-
Please refer [here](http://www.math.duke.edu/~johnt/) and [here](http://www.cambridge.org/us/academic/subjects/mathematics/differential-and-integral-equations-dynamical-systems-and-co/numerical-solution-hyperbolic-partial-differential-equations)
73
-
* Clawpack (stands for *Conservation Laws Package*) by prof. Randall J. LeVeque
see also [translation to Julia of Fortran codes from ClawPack](https://github.com/alsam/Claw.jl)
80
-
81
-
The directory _examples_ of [hyperbolic_PDE](https://github.com/alsam/hyperbolic_PDE.jl) contains at the moment a translation of explicit upwind finite difference scheme for scalar law advection equation from
82
-
the book _Numerical Solution of Hyperbolic Partial Differential Equations_ by prof. John A. Trangenstein.
83
-
84
-
+ examples/scalar_law/PROGRAM0/main.jl
85
-
The original Fortran arrays `u(-2:ncells+1), x(0:ncells), flux(0:ncells)` transformed to 1-based Julia arrays by shifting index expressions
+ Timing for `OffsetArray` version with `@unsafe` annotation:
106
-
```sh
107
-
0.103987 seconds (16 allocations: 235.094 KB)
108
-
```
109
-
110
-
+ Timing for `sub` macro version with `@unsafe` annotation (doesn't work without `@unsafe`):
111
-
```sh
112
-
0.105967 seconds (217 allocations: 268.094 KB)
113
-
```
114
-
Only the 2nd timing after warming up is given.
115
-
116
-
+ UPDATE:
117
-
Added
118
-
+ examples/scalar_law/PROGRAM1/...
119
-
```sh
120
-
[~/w/m/O/e/s/PROGRAM1] $ julia linaddmain.jl --cells=10000 --runs=3 ms master|✚ 1…
121
-
0.672295 seconds (42.90 k allocations: 1.990 MB)
122
-
0.509693 seconds (18 allocations: 313.281 KB)
123
-
0.512243 seconds (18 allocations: 313.281 KB)
124
-
[~/w/m/O/e/s/PROGRAM1] $ julia linaddmain.jl --cells=100000 --runs=3 6134ms master|✚ 1…
125
-
7.270463 seconds (42.90 k allocations: 4.736 MB)
126
-
7.177485 seconds (18 allocations: 3.053 MB)
127
-
7.248687 seconds (18 allocations: 3.053 MB)
128
-
```
129
-
130
-
Fortran timing for `100000` number of cells
131
-
```sh
132
-
real 0m4.781s
133
-
user 0m4.760s
134
-
sys 0m0.000s
135
-
136
-
```
137
-
138
-
That is 7.2s for Julia script vs. 4.8s for Fortran.
25
+
Julia supports generic programming with arrays that doesn't require you to assume that indices start with 1, see the [documentation](http://docs.julialang.org/en/latest/devdocs/offset-arrays/).
The original purpose of the package was to simplify translation of Fortran codes, say
4
+
* the codes accompanying the book _Numerical Solution of Hyperbolic Partial Differential Equations_ by prof. John A. Trangenstein
5
+
Please refer [here](http://www.math.duke.edu/~johnt/) and [here](http://www.cambridge.org/us/academic/subjects/mathematics/differential-and-integral-equations-dynamical-systems-and-co/numerical-solution-hyperbolic-partial-differential-equations)
6
+
* Clawpack (stands for *Conservation Laws Package*) by prof. Randall J. LeVeque
see also [translation to Julia of Fortran codes from ClawPack](https://github.com/alsam/Claw.jl)
13
+
14
+
The directory _examples_ of [hyperbolic_PDE](https://github.com/alsam/hyperbolic_PDE.jl) contains at the moment a translation of explicit upwind finite difference scheme for scalar law advection equation from
15
+
the book _Numerical Solution of Hyperbolic Partial Differential Equations_ by prof. John A. Trangenstein.
16
+
17
+
+ examples/scalar_law/PROGRAM0/main.jl
18
+
The original Fortran arrays `u(-2:ncells+1), x(0:ncells), flux(0:ncells)` transformed to 1-based Julia arrays by shifting index expressions
0 commit comments