Skip to content

Commit

Permalink
Add support for DistributedNext
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWrigley authored and jpsamaroo committed Dec 6, 2024
1 parent d461440 commit 85602cd
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ version = "0.18.13"
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
DistributedNext = "fab6aee4-877b-4bac-a744-3eca44acbb6f"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
MemPool = "f9f48841-c794-520a-933b-121f7ba6ed94"
OnlineStats = "a15396b6-48d5-5d58-9928-6d29437db91e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Expand Down Expand Up @@ -47,15 +49,17 @@ Adapt = "4.0.4"
Colors = "0.12, 0.13"
DataFrames = "1"
DataStructures = "0.18"
DistributedNext = "1.0.0"
Distributions = "0.25"
GraphViz = "0.2"
Graphs = "1"
JSON3 = "1"
MacroTools = "0.5"
MemPool = "0.4.6"
MemPool = "0.4.11"
OnlineStats = "1"
Plots = "1"
PrecompileTools = "1.2"
Preferences = "1.4.3"
PythonCall = "0.9"
Requires = "1"
ScopedValues = "1.1"
Expand Down
4 changes: 4 additions & 0 deletions lib/TimespanLogging/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ version = "0.1.0"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
DistributedNext = "fab6aee4-877b-4bac-a744-3eca44acbb6f"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"

[compat]
DistributedNext = "1.0.0"
Preferences = "1.4.3"
julia = "1"
20 changes: 19 additions & 1 deletion lib/TimespanLogging/src/core.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using Distributed
import Preferences: @load_preference, @set_preferences!
if @load_preference("distributed-package") == "DistributedNext"
using DistributedNext
else
using Distributed
end

import Profile
import Base.gc_num

Expand All @@ -16,6 +22,18 @@ ProfilerResult(samples, lineinfo, tasks::Vector{Task}) =
ProfilerResult(samples, lineinfo, tasks::Nothing) =
ProfilerResult(samples, lineinfo, map(Base.pointer_from_objref, UInt[]))

"""
set_distributed_package!(value[="Distributed|DistributedNext"])
Set a [preference](https://github.com/JuliaPackaging/Preferences.jl) for using
either the Distributed.jl stdlib or DistributedNext.jl. You will need to restart
Julia after setting a new preference.
"""
function set_distributed_package!(value)
@set_preferences!("distributed-package" => value)
@info "TimespanLogging.jl preference has been set, restart your Julia session for this change to take effect!"
end

"""
Timespan
Expand Down
28 changes: 26 additions & 2 deletions src/Dagger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import MemPool
import MemPool: DRef, FileRef, poolget, poolset

import Base: collect, reduce
import Distributed
import Distributed: Future, RemoteChannel, myid, workers, nworkers, procs, remotecall, remotecall_wait, remotecall_fetch

import LinearAlgebra
import LinearAlgebra: Adjoint, BLAS, Diagonal, Bidiagonal, Tridiagonal, LAPACK, LowerTriangular, PosDefException, Transpose, UpperTriangular, UnitLowerTriangular, UnitUpperTriangular, diagind, ishermitian, issymmetric
Expand All @@ -33,6 +31,17 @@ import TimespanLogging: timespan_start, timespan_finish

import Adapt

# Preferences
import Preferences: @load_preference, @set_preferences!

if @load_preference("distributed-package") == "DistributedNext"
import DistributedNext
import DistributedNext: Future, RemoteChannel, myid, workers, nworkers, procs, remotecall, remotecall_wait, remotecall_fetch, check_same_host
else
import Distributed
import Distributed: Future, RemoteChannel, myid, workers, nworkers, procs, remotecall, remotecall_wait, remotecall_fetch, check_same_host
end

include("lib/util.jl")
include("utils/dagdebug.jl")

Expand Down Expand Up @@ -96,6 +105,21 @@ include("utils/logging-events.jl")
include("utils/logging.jl")
include("utils/viz.jl")

"""
set_distributed_package!(value[="Distributed|DistributedNext"])
Set a [preference](https://github.com/JuliaPackaging/Preferences.jl) for using
either the Distributed.jl stdlib or DistributedNext.jl. You will need to restart
Julia after setting a new preference.
"""
function set_distributed_package!(value)
MemPool.set_distributed_package!(value)
TimespanLogging.set_distributed_package!(value)

@set_preferences!("distributed-package" => value)
@info "Dagger.jl preference has been set, restart your Julia session for this change to take effect!"
end

# Precompilation
import PrecompileTools: @compile_workload
include("precompile.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/array/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ end

function Distribute(data::AbstractArray{T,N}) where {T,N}
nprocs = sum(w->length(Dagger.get_processors(OSProc(w))),
Distributed.procs())
procs())
p = Blocks(ntuple(i->max(cld(size(data, i), nprocs), 1), N))
return Distribute(partition(p, domain(data)), p, data)
end
Expand Down
4 changes: 2 additions & 2 deletions src/array/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ const use_shared_array = Ref(true)
function _promote_array(x::AbstractArray{T}, y::AbstractArray{S}) where {T,S}
Q = promote_type(T,S)
ok = (isa(x, Array) || isa(x, SharedArray)) && (isa(y, Array) || isa(y, SharedArray))
if ok && isbitstype(Q) && use_shared_array[] && Distributed.check_same_host([workers()..., 1])
return SharedArray{Q}(length(x)+length(y), pids=Distributed.procs())
if ok && isbitstype(Q) && use_shared_array[] && check_same_host([workers()..., 1])
return SharedArray{Q}(length(x)+length(y), pids=procs())
else
return similar(x, Q, length(x)+length(y))
end
Expand Down
8 changes: 7 additions & 1 deletion src/sch/Sch.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module Sch

import Distributed: Future, ProcessExitedException, RemoteChannel, RemoteException, myid, remote_do, remotecall_fetch, remotecall_wait, workers
import Preferences: @load_preference
if @load_preference("distributed-package") == "DistributedNext"
import DistributedNext: Future, ProcessExitedException, RemoteChannel, RemoteException, myid, remote_do, remotecall_fetch, remotecall_wait, workers
else
import Distributed: Future, ProcessExitedException, RemoteChannel, RemoteException, myid, remote_do, remotecall_fetch, remotecall_wait, workers
end

import MemPool
import MemPool: DRef, StorageResource
import MemPool: poolset, storage_capacity, storage_utilized
Expand Down
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
Dagger = "d58978e5-989f-55fb-8d15-ea34adc7bf54"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
21 changes: 21 additions & 0 deletions test/preferences.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Preferences: load_preference, set_preferences!

@testset "Preferences" begin
cmd = `$(Base.julia_cmd()) --startup-file=no --project -E 'using Dagger; parentmodule(Dagger.myid)'`

try
# Disabling the precompilation workload shaves off over half the time
# this test takes.
set_preferences!(Dagger, "precompile_workload" => false; force=true)

cd(dirname(Base.active_project())) do
Dagger.set_distributed_package!("Distributed")
@test readchomp(cmd) == "Distributed"

Dagger.set_distributed_package!("DistributedNext")
@test readchomp(cmd) == "DistributedNext"
end
finally
set_preferences!(Dagger, "precompile_workload" => true; force=true)
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tests = [
("Disk Caching", "diskcaching.jl"),
("File IO", "file-io.jl"),
("External Languages - Python", "extlang/python.jl"),
("Preferences", "preferences.jl")
#("Fault Tolerance", "fault-tolerance.jl"),
]
all_test_names = map(test -> replace(last(test), ".jl"=>""), tests)
Expand Down

0 comments on commit 85602cd

Please sign in to comment.