# distributed bitonic sort using elbow merge locally except for the first step
function distbitonic!(p)

    q = Int(log2(p))
  
    pid = 0:p-1
    ascending = mod.(pid,2) .== 0
    println("ascending: $ascending")
    # local full sort here
    for k = 1:q
      kk = 1 << k
      for j = k-1:-1:0
        jj = 1 << j
        partnerid = pid .⊻ jj
        direction = (pid .& kk) .== 0 .& (pid .< partnerid)
        keepsmall = ((pid .< partnerid) .& direction) .| ((pid .> partnerid) .& .!direction)
        println("k: $k | j: $j | partner: $partnerid | keepsmall: $keepsmall")
        # exchange with partner and keep small or large
      end
      ascending = (pid .& kk) .== 0
      println("ascending: $ascending")
      # local elbowmerge here
    end
  
    nothing
  end
 