comparison distributedTest.jl @ 149:11b6646918d4 parallel_test

Rewrote the test using the @distributed macro instead of spawns. Seems to improve results.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Tue, 26 Feb 2019 11:09:30 +0100
parents 95a3ba70bccb
children 4dc19757cada
comparison
equal deleted inserted replaced
148:95a3ba70bccb 149:11b6646918d4
1 #NOTE: The followig code "works" in that the resulting error is small. Much more
2 # work needs to be done in order to figure out how julias distributed parallelism works
3 # especially w.r.t data movement.
4
5 #TODO: everywhere using here or just everywhere include? 1 #TODO: everywhere using here or just everywhere include?
6 @everywhere using DistributedArrays 2 @everywhere using DistributedArrays
7 3
8 # TODO: Currently uses integer division to calculate the local grid size. 4 # TODO: Currently uses integer division to calculate the local grid size.
9 # Should we make sure this is handled in some way if mod(sz./nworkers()) != 0 5 # Should we make sure this is handled in some way if mod(sz./nworkers()) != 0
27 lu_partition = limit_lower .+ domain_partition_size.*id 23 lu_partition = limit_lower .+ domain_partition_size.*id
28 grid = sbp.Grid.EquidistantGrid(size_partition, ll_partition, lu_partition) 24 grid = sbp.Grid.EquidistantGrid(size_partition, ll_partition, lu_partition)
29 return grid 25 return grid
30 end 26 end
31 27
32 # Create grid 28 @everywhere function timed_apply(op, u, v)
33 #TODO: Should these be declared globally? 29 @time sbp.apply_tiled!(op, u, v)
34 gridsize = (10000, 10000); 30 return nothing
35 limit_lower = (0., 0.) 31 end
36 limit_upper = (2pi, 3pi/2)
37 nworkers_per_dim = (Int(nworkers()/2),Int(nworkers()/2))
38 32
39 # TODO: Currently only works with same number of processes in each direction and for 33 gridsize = (10000, 10000); # Global grid size
40 # an even number of processes
41 grids_partitioned = [@spawnat p create_partitioned_grid(gridsize, limit_lower , limit_upper, nworkers_per_dim) for p in workers()]
42
43 # Create Laplace operator
44 # TODO: If we dont have fetch here, then the error is large. Does this indicate that we need to move data, or simply that
45 # the future is not yet computed once this statement is reached?
46 Laplace_partitioned = [@spawnat p sbp.Laplace(fetch(grids_partitioned[p-1]), 1.0, sbp.readOperator("d2_4th.txt","h_4th.txt")) for p in workers()]
47
48 # Create initial value grid function v and solution grid function u
49 #TODO: Should init be declared globally?
50 init(x,y) = sin(x) + sin(y)
51 v = dzeros(gridsize) # Distribured arrays 34 v = dzeros(gridsize) # Distribured arrays
52 u = dzeros(gridsize) # Distribured arrays 35 u = dzeros(gridsize) # Distribured arrays
53 fetch([@spawnat p v[:L] = sbp.Grid.evalOn(fetch(grids_partitioned[p-1]), init) for p in workers()]) #TODO: Don't want to fetch here
54 36
55 # Apply Laplace 37 @sync @distributed for p in workers()
56 fetch([@spawnat p sbp.apply_tiled!(fetch(Laplace_partitioned[p-1]),u[:L], v[:L]) for p in workers()]) #TODO: Don't want to fetch here 38 #Should these be declared globally or locally?
57 39 limit_lower = (0., 0.)
58 #TODO: Here we need to make sure that the data is ready. 40 limit_upper = (2pi, 3pi/2)
41 nworkers_per_dim = (Int(nworkers()/2),Int(nworkers()/2))
42 init(x,y) = sin(x) + sin(y)
43 grid = create_partitioned_grid(gridsize, limit_lower , limit_upper, nworkers_per_dim)
44 @inbounds v[:L] = sbp.Grid.evalOn(grid, init)
45 op = sbp.readOperator("d2_4th.txt","h_4th.txt")
46 Δ = sbp.Laplace(grid, 1.0, op)
47 @inbounds timed_apply(Δ,u[:L], v[:L])
48 end
59 @show maximum(abs.(u + v)) 49 @show maximum(abs.(u + v))