Skip to content

Commit de00b51

Browse files
author
Dae Woo Kim
committed
Deprecations are fixed for julia-0.7
1 parent 81b265a commit de00b51

File tree

6 files changed

+95
-26
lines changed

6 files changed

+95
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.jl.*.cov
33
*.jl.mem
44
deps/deps.jl
5+
Manifest.toml

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Documentation: http://docs.travis-ci.com/user/languages/julia/
2+
language: julia
3+
os:
4+
- linux
5+
julia:
6+
- 0.7
7+
- 1.0
8+
notifications:
9+
email: false
10+
script:
11+
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
12+
- julia -e 'using Pkg, LibGit2;
13+
user_regs = joinpath(DEPOT_PATH[1],"registries");
14+
mkpath(user_regs);
15+
all_registries = Dict("General" => "https://github.com/JuliaRegistries/General.git",
16+
"HolyLabRegistry" => "[email protected]:HolyLab/HolyLabRegistry.git");
17+
Base.shred!(LibGit2.CachedCredentials()) do creds
18+
for (reg, url) in all_registries
19+
path = joinpath(user_regs, reg);
20+
LibGit2.with(Pkg.GitTools.clone(url, path; header = "registry $reg from $(repr(url))", credentials = creds)) do repo end
21+
end
22+
end'
23+
- julia -e 'using Pkg; Pkg.build(); Pkg.test("RegisterDriver"; coverage=false)'
24+
after_success:
25+
# update the documentation
26+
- julia -e 'using Pkg; Pkg.add("Documenter")'
27+
- julia -e 'using RegisterDriver; cd(dirname(dirname(pathof(RegisterDriver)))); ENV["DOCUMENTER_DEBUG"] = "true"; include(joinpath("docs", "make.jl"))'

Project.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name = "RegisterDriver"
2+
uuid = "935ac36e-2656-11e9-1e3b-cbaa636797af"
3+
authors = ["Tim Holy <[email protected]>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
8+
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
9+
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"
10+
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
11+
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
12+
JLD = "4138dd39-2aa7-5051-a626-17a0bb65d9c8"
13+
RegisterCore = "67712758-55e7-5c3c-8e85-dda1d7758434"
14+
RegisterWorkerShell = "978d31ce-2656-11e9-22d6-b5c46a1a3d3e"
15+
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
16+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
17+
18+
[extras]
19+
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
20+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
21+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
22+
23+
[targets]
24+
test = ["Compat", "Test", "Pkg"]

src/RegisterDriver.jl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module RegisterDriver
22

3-
using Images, JLD, HDF5, StaticArrays, Formatting
3+
using Images, JLD, HDF5, StaticArrays, Formatting, SharedArrays, Distributed
44
using RegisterCore
55
using RegisterWorkerShell
66

7-
export driver
7+
export driver, mm_package_loader
88
export PreprocessSNF
99

1010
"""
@@ -43,7 +43,7 @@ function driver(outfile::AbstractString, algorithm::Vector, img, mon::Vector)
4343
nworkers = length(algorithm)
4444
length(mon) == nworkers || error("Number of monitors must equal number of workers")
4545
use_workerprocs = nworkers > 1 || workerpid(algorithm[1]) != myid()
46-
rralgorithm = Array{RemoteChannel}(nworkers)
46+
rralgorithm = Array{RemoteChannel}(undef, nworkers)
4747
if use_workerprocs
4848
# Push the algorithm objects to the worker processes. This elminates
4949
# per-iteration serialization penalties, and ensures that any
@@ -155,15 +155,15 @@ function initialize_jld!(dsets, file, mon, fs, n)
155155
for (k,v) in mon
156156
kstr = string(k)
157157
if isa(v, Number)
158-
write(file, kstr, Vector{typeof(v)}(n))
158+
write(file, kstr, Vector{typeof(v)}(undef, n))
159159
dsets[k] = file[kstr]
160160
elseif isa(v, Array) || isa(v, SharedArray)
161161
v = nicehdf5(v)
162162
if eltype(v) <: HDF5.HDF5BitsKind
163163
fullsz = (size(v)..., n)
164164
dsets[k] = d_create(file.plain, kstr, datatype(eltype(v)), dataspace(fullsz))
165165
else
166-
write(file, kstr, Array{eltype(v)}(size(v)..., n)) # might fail if it's too big, but we tried
166+
write(file, kstr, Array{eltype(v)}(undef, size(v)..., n)) # might fail if it's too big, but we tried
167167
end
168168
dsets[k] = file[kstr]
169169
elseif isa(v, ArrayDecl) # maybe this never happens?
@@ -182,11 +182,11 @@ function initialize_jld!(dsets, file, mon, fs, n)
182182
end
183183

184184
function nicehdf5(v::Union{Array{T},SharedArray{T}}) where T<:StaticArray
185-
nicehdf5(reinterpret(eltype(T), sdata(v), (size(eltype(v))..., size(v)...)))
185+
nicehdf5(reshape(reinterpret(eltype(T), vec(sdata(v))), (size(eltype(v))..., size(v)...)))
186186
end
187187

188188
function nicehdf5(v::Union{Array{T},SharedArray{T}}) where T<:NumDenom
189-
nicehdf5(reinterpret(eltype(T), sdata(v), (2, size(v)...)))
189+
nicehdf5(reshape(reinterpret(eltype(T), vec(sdata(v))), (2, size(v)...)))
190190
end
191191

192192
nicehdf5(v::SharedArray) = sdata(v)
@@ -241,11 +241,31 @@ end
241241
function sqrt_subtract_bias(A, bias)
242242
# T = typeof(sqrt(one(promote_type(eltype(A), typeof(bias)))))
243243
T = Float32
244-
out = Array{T}(size(A))
244+
out = Array{T}(undef, size(A))
245245
for I in eachindex(A)
246246
@inbounds out[I] = sqrt(max(zero(T), convert(T, A[I]) - bias))
247247
end
248248
out
249249
end
250250

251+
mm_package_loader(algorithm::AbstractWorker) = mm_package_loader([algorithm])
252+
function mm_package_loader(algorithms::Vector)
253+
nworkers = length(algorithms)
254+
use_workerprocs = nworkers > 1 || workerpid(algorithms[1]) != myid()
255+
rrdev = Array{RemoteChannel}(undef, nworkers)
256+
if use_workerprocs
257+
for i = 1:nworkers
258+
dev = algorithms[i].dev
259+
rrdev[i] = put!(RemoteChannel(workerpid(algorithms[i])), dev)
260+
end
261+
@sync for i = 1:nworkers
262+
p = workerpid(algorithms[i])
263+
@async remotecall_fetch(load_mm_package, p, rrdev[i])
264+
end
265+
else
266+
load_mm_package(algorithms[1].dev)
267+
end
268+
nothing
269+
end
270+
251271
end # module

test/WorkerDummy.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Dummy algorithms to test features of `driver`
22
module WorkerDummy
33

4-
using RegisterWorkerShell
4+
using RegisterWorkerShell, Distributed
55
import RegisterWorkerShell: worker
66
using Compat
77

@@ -47,10 +47,10 @@ end
4747

4848
function worker(algorithm::Alg2, moving, tindex, mon)
4949
# Do stuff to set tform
50-
tform = range(1, stop=12, length=12)+tindex
50+
tform = range(1, stop=12, length=12).+tindex
5151
monitor!(mon, :tform, tform)
5252
# Do more computations...
53-
monitor!(mon, :u0, zeros(size(algorithm.u0))-tindex)
53+
monitor!(mon, :u0, zeros(size(algorithm.u0)).-tindex)
5454
end
5555

5656
function worker(algorithm::Alg3, moving, tindex, mon)

test/runtests.jl

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
driverprocs = addprocs(2)
2-
3-
# Work around julia #3674
4-
using Images, JLD, Test
5-
using BlockRegistration, BlockRegistrationScheduler
1+
using Test, Distributed, SharedArrays
2+
using Images, JLD
63
using RegisterDriver, RegisterWorkerShell
4+
5+
driverprocs = addprocs(2)
6+
include("WorkerDummy.jl")
77
@sync for p in driverprocs
88
@spawnat p eval(quote
9-
using Images, JLD, Test
10-
using BlockRegistrationScheduler, RegisterDriver, RegisterWorkerShell
9+
using Pkg
10+
Pkg.activate(".")
11+
Pkg.instantiate()
12+
include("WorkerDummy.jl")
1113
end)
1214
end
13-
14-
include("WorkerDummy.jl")
1515
using .WorkerDummy
16-
for p in driverprocs
17-
remotecall_fetch(eval, p, :(include("WorkerDummy.jl"); using .WorkerDummy)) # workaround #3674 if this is re-run
18-
end
1916

2017
workdir = tempname()
2118
mkdir(workdir)
@@ -39,7 +36,7 @@ fn = joinpath(workdir, "file2.jld")
3936
driver(fn, alg, img, mon)
4037
tform = JLD.load(fn, "tform")
4138
u0 = JLD.load(fn, "u0")
42-
@test tform[:,4] == collect(range(1, stop=12, length=12)+4)
39+
@test tform[:,4] == collect(range(1, stop=12, length=12).+4)
4340
@test u0[:,:,2] == fill(-2,(3,3))
4441
rm(fn)
4542

@@ -59,8 +56,8 @@ rm(fn)
5956

6057
# Multi-process
6158
nw = length(driverprocs)
62-
alg = Vector{Any}(nw)
63-
mon = Vector{Any}(nw)
59+
alg = Vector{Any}(undef, nw)
60+
mon = Vector{Any}(undef, nw)
6461
for i = 1:nw
6562
alg[i] = Alg2(rand(100,100), Float32, (3,3), pid=driverprocs[i])
6663
mon[i] = monitor(alg[i], (:tform,:u0,:workerpid))

0 commit comments

Comments
 (0)