forked from oscar-system/Oscar.jl
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOscarWorkerPool.jl
40 lines (33 loc) · 1.19 KB
/
OscarWorkerPool.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@testset "Parallel" begin
using Distributed
# Start a worker pool with Oscar running on the workers.
# Define an auxiliary context object for the distributed computation
mutable struct CtxIO
a::Vector
b::Dict{Int, Any}
function CtxIO(a::Vector)
return new(a, Dict{Int, Any}())
end
end
Oscar.pop_task!(ctx::CtxIO) = is_empty(ctx.a) ? nothing : (length(ctx.a), x->x^2, pop!(ctx.a))
Oscar.process_result!(ctx::CtxIO, id::Int, result) = ctx.b[id] = result
#initiate worker pool
oscar_worker_pool(1) do wp
@testset "compute distributed" begin
# Implement methods for `pop_task!` and `process_result!` for this
# type as explained in their docstrings.
# Create a context for the computation.
R, (x, y, z) = QQ[:x, :y, :z]
ctx = CtxIO(gens(R))
# Trigger distributed execution.
Oscar.compute_distributed!(ctx, wp)
# Verify that the result is correct.
@test all(x in keys(ctx.b) for x in [1, 2, 3])
@test all(a^2 in values(ctx.b) for a in gens(R))
end
@testset "pmap" begin
R, (x, y, z) = GF(101)[:x, :y, :z]
@test pmap(f->f^2, wp, gens(R)) == [x^2, y^2, z^2]
end
end
end