Here's a simple script.
using Atomix: @atomicreplace, @atomic
function foo(v::Vector{Int64})
i = readline()
i = parse(Int64, i)
@inbounds @atomic v[i] += 1
end
function bar(v::Matrix{Int64})
r = readline()
r = parse(Int64, r)
c = readline()
c = parse(Int64, c)
@inbounds @atomic v[r, c] += 1
end
A = ones(Int64, 3)
foo(A)
println("Passed first function call")
B = ones(Int64, 3, 3)
bar(B)
Here's its output if the elements exceed the bounds.
$ julia test.jl
5
Passed first function call
5
5
ERROR: LoadError: BoundsError: attempt to access 3×3 LinearIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}} at index [5, 5]
Stacktrace:
[1] throw_boundserror(A::LinearIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, I::Tuple{Int64, Int64})
@ Base ./essentials.jl:15
[2] checkbounds
@ ./abstractarray.jl:699 [inlined]
[3] _getindex
@ ./abstractarray.jl:1370 [inlined]
[4] getindex
@ ./abstractarray.jl:1342 [inlined]
[5] pointer
@ ~/Projects/project/.julia/packages/Atomix/0UMek/src/references.jl:102 [inlined]
[6] modify!
@ ~/Projects/project/.julia/packages/Atomix/0UMek/src/core.jl:30 [inlined]
[7] bar(v::Matrix{Int64})
@ Main ~/Projects/project/test.jl:14
[8] top-level scope
@ ~/Projects/project/test.jl:23
[9] include(mod::Module, _path::String)
@ Base ./Base.jl:306
[10] exec_options(opts::Base.JLOptions)
@ Base ./client.jl:317
[11] _start()
@ Base ./client.jl:550
in expression starting at /home/matei/Projects/project/test.jl:23
Any thoughts on this?
Here's a simple script.
Here's its output if the elements exceed the bounds.
Any thoughts on this?