view distributedTest.jl @ 151:80f7d7abe47d parallel_test

Removed unnecessary assertion
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Tue, 26 Feb 2019 11:49:56 +0100
parents 4dc19757cada
children
line wrap: on
line source

#TODO: everywhere using here or just everywhere include?
@everywhere using DistributedArrays

# TODO: Currently uses integer division to calculate the local grid size.
# Should we make sure this is handled in some way if mod(sz./nworkers()) != 0
# or keep assertions?
@everywhere function create_partitioned_grid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}, nworkers_per_dim::NTuple{Dim, Int}) where Dim where T
  @assert mod.(size, nworkers_per_dim) == (0,0)
  # Translate the current worker id to a cartesian index, based on nworkers_per_dim
  ci = CartesianIndices(nworkers_per_dim);
  id = Tuple(ci[myid()-1])

  # Compute the size of each partitioned grid
  size_partition = Int.(size./nworkers_per_dim)
  # Compute domain size for each partition
  domain_size = limit_upper.-limit_lower
  domain_partition_size = domain_size./nworkers_per_dim

  # Compute the lower and upper limit for each grid partition, then construct the grid
  ll_partition = limit_lower .+ domain_partition_size.*(id.-1)
  lu_partition = limit_lower .+ domain_partition_size.*id
  grid = sbp.Grid.EquidistantGrid(size_partition, ll_partition, lu_partition)
  return grid
end

@everywhere function timed_apply(op, u, v)
  @time sbp.apply_tiled!(op, u, v)
  return nothing
end

gridsize = (10000, 10000); # Global grid size
nworkers_per_dim = (2,2) # Currently must have mod.(gridsize,n_workers_per_dim) == 0
v = dzeros(gridsize) # Distribured arrays
u = dzeros(gridsize) # Distribured arrays

@sync @distributed for p in workers()
  #Should these be declared globally or locally?
  limit_lower = (0., 0.)
  limit_upper = (2pi, 3pi/2)
  init(x,y) = sin(x) + sin(y)
  grid = create_partitioned_grid(gridsize, limit_lower , limit_upper, nworkers_per_dim)
  @inbounds v[:L] = sbp.Grid.evalOn(grid, init)
  op = sbp.readOperator("d2_4th.txt","h_4th.txt")
  Δ = sbp.Laplace(grid, 1.0, op)
  @inbounds timed_apply(Δ,u[:L], v[:L])
end
@show maximum(abs.(u + v))