|
| 1 | + |
| 2 | +@testset "Base functions" begin |
| 3 | + |
| 4 | + @testset "Distributed data transfers -- local" begin |
| 5 | + data = rand(5) |
| 6 | + save_at(1, :test, data) |
| 7 | + |
| 8 | + @test fetch(get_from(1, :test)) == data |
| 9 | + @test get_val_from(1, :test) == data |
| 10 | + |
| 11 | + remove_from(1, :test) |
| 12 | + |
| 13 | + @test sizeof(get_val_from(1, :test)) == 0 #should be "nothing" but this is more generic |
| 14 | + end |
| 15 | + |
| 16 | + addprocs(3) |
| 17 | + @everywhere using DiDa |
| 18 | + W = workers() |
| 19 | + |
| 20 | + @testset "Distributed data transfers -- with workers" begin |
| 21 | + data = [rand(5) for i in W] |
| 22 | + for (i, w) in enumerate(W) |
| 23 | + save_at(w, :test, data[i]) |
| 24 | + end |
| 25 | + |
| 26 | + @test [fetch(get_from(w, :test)) for w in W] == data |
| 27 | + @test [get_val_from(w, :test) for w in W] == data |
| 28 | + |
| 29 | + undistribute(:test, W) |
| 30 | + |
| 31 | + @test sum([sizeof(get_val_from(w, :test)) for w in W]) == 0 |
| 32 | + end |
| 33 | + |
| 34 | + @testset "Data distribution" begin |
| 35 | + d = rand(100, 5) |
| 36 | + |
| 37 | + di = distribute_array(:test, d, W) |
| 38 | + |
| 39 | + @test di.val == :test |
| 40 | + @test Set(di.workers) == Set(W) |
| 41 | + @test begin |
| 42 | + d1 = get_val_from(di.workers[1], :test) |
| 43 | + d1 == d[1:size(d1, 1), :] |
| 44 | + end |
| 45 | + |
| 46 | + #TODO test actual sizes of the distributed pieces |
| 47 | + |
| 48 | + @test distributed_collect(di, free = false) == d #TODO test with true |
| 49 | + @test sum([sizeof(get_val_from(w, :test)) for w in W]) > 0 |
| 50 | + undistribute(di) |
| 51 | + @test sum([sizeof(get_val_from(w, :test)) for w in W]) == 0 |
| 52 | + end |
| 53 | + |
| 54 | + @testset "Distributed computation" begin |
| 55 | + di = distributed_transform(:(), x -> rand(5), W, :test) |
| 56 | + |
| 57 | + @test get_val_from(W[1], :test) == distributed_collect(di)[1:5] |
| 58 | + |
| 59 | + orig = distributed_collect(di) |
| 60 | + |
| 61 | + @test isapprox( |
| 62 | + distributed_mapreduce(:test, d -> sum(d .^ 2), (a, b) -> a + b, W), |
| 63 | + sum(orig .^ 2), |
| 64 | + ) |
| 65 | + |
| 66 | + distributed_transform(di, d -> d .* 2) |
| 67 | + |
| 68 | + @test orig .* 2 == distributed_collect(:test, W) |
| 69 | + |
| 70 | + @test isapprox( |
| 71 | + distributed_mapreduce(di, d -> sum(d .^ 2), (a, b) -> a + b), |
| 72 | + sum((orig .* 2) .^ 2), |
| 73 | + ) |
| 74 | + |
| 75 | + t = zeros(length(W)) |
| 76 | + exp = zeros(length(W)) |
| 77 | + |
| 78 | + t[1] = 2 |
| 79 | + exp[1] = sum(2 .* get_val_from(W[1], :test)) |
| 80 | + |
| 81 | + @test distributed_foreach(t, (i) -> eval(:(sum($i .* $(di.val)))), W) == exp |
| 82 | + |
| 83 | + undistribute(di) |
| 84 | + |
| 85 | + @test distributed_mapreduce(:noname, x -> x, (a, b) -> a + b, []) == nothing |
| 86 | + end |
| 87 | + |
| 88 | + @testset "Internal utilities" begin |
| 89 | + @test DiDa.tmpSym(:test) != :test |
| 90 | + @test DiDa.tmpSym(:test, prefix = "abc", suffix = "def") == :abctestdef |
| 91 | + @test DiDa.tmpSym(Dinfo(:test, W)) != :test |
| 92 | + end |
| 93 | + |
| 94 | + @testset "Persistent distributed data" begin |
| 95 | + di = distributed_transform(:(), x -> rand(5), W, :test) |
| 96 | + |
| 97 | + files = DiDa.defaultFiles(di.val, di.workers) |
| 98 | + @test allunique(files) |
| 99 | + |
| 100 | + orig = distributed_collect(di) |
| 101 | + distributed_export(di, files) |
| 102 | + distributed_transform(di, x -> "erased") |
| 103 | + distributed_import(di, files) |
| 104 | + |
| 105 | + @test orig == distributed_collect(di) |
| 106 | + |
| 107 | + distributed_export(di.val, di.workers, files) |
| 108 | + di2 = distributed_import(:test2, di.workers, files) |
| 109 | + |
| 110 | + @test orig == distributed_collect(di2) |
| 111 | + |
| 112 | + undistribute(di) |
| 113 | + undistribute(di2) |
| 114 | + |
| 115 | + distributed_unlink(di) |
| 116 | + |
| 117 | + @test all([!isfile(f) for f in files]) |
| 118 | + end |
| 119 | + |
| 120 | + rmprocs(W) |
| 121 | + W = nothing |
| 122 | + |
| 123 | +end |
0 commit comments