@@ -548,12 +548,14 @@ interface.
548
548
- `ranks`: Array containing the distribution of ranks.
549
549
- `np::NTuple{N}`: Number of parts per direction.
550
550
- `n::NTuple{N}`: Number of global indices per direction.
551
- - `ghost::NTuple{N}=ntuple(i->false,N)`: Use or not ghost indices per direction.
551
+ - `ghost::NTuple{N}=ntuple(i->false,N)`: Number of ghost indices per direction.
552
552
- `periodic::NTuple{N}=ntuple(i->false,N)`: Use or not periodic boundaries per direction.
553
553
554
554
For convenience, one can also provide scalar inputs instead tuples
555
555
to create 1D block partitions. In this case, the argument `np` can be omitted
556
- and it will be computed as `np=length(ranks)`.
556
+ and it will be computed as `np=length(ranks)`. At the moment, it's only possible
557
+ to use this syntax for zero (with `ghost=false`) or one (with `ghost=true`) layer(s)
558
+ of ghost indices. If you wish to have more ghost indices, use tuples instead.
557
559
558
560
# Examples
559
561
@@ -622,42 +624,35 @@ function block_with_constant_size(rank,np,n,ghost,periodic=map(i->false,ghost))
622
624
p = CartesianIndices (np)[rank]
623
625
own_ranges = map (local_range,Tuple (p),np,n)
624
626
local_ranges = map (local_range,Tuple (p),np,n,ghost,periodic)
625
- owners = map (Tuple (p),own_ranges, local_ranges) do p,or, lr
627
+ owners = map (Tuple (p), np, n, local_ranges) do p, np, n, lr
626
628
myowners = zeros (Int32,length (lr))
627
- for i in 1 : length (lr)
628
- if lr[i] in or
629
+ i = 1
630
+ for p in Iterators. cycle (1 : np)
631
+ plr = local_range (p, np, n)
632
+ while mod (lr[i]- 1 , n)+ 1 in plr
629
633
myowners[i] = p
634
+ (i += 1 ) > length (myowners) && return myowners
630
635
end
631
636
end
632
- if myowners[1 ] == 0
633
- myowners[1 ] = p- 1
634
- end
635
- if myowners[end ] == 0
636
- myowners[end ] = p+ 1
637
- end
638
- myowners
639
- end
640
- n_ghost = 0
641
- cis = CartesianIndices (map (length,local_ranges))
642
- predicate (p,i,owners) = owners[i] == p
643
- for ci in cis
644
- flags = map (predicate,Tuple (p),Tuple (ci),owners)
645
- if ! all (flags)
646
- n_ghost += 1
647
- end
648
637
end
638
+ n_local = prod (map (length, local_ranges))
639
+ n_own = prod (map (length, own_ranges))
640
+ n_ghost = n_local - n_own
641
+
649
642
ghost_to_global = zeros (Int,n_ghost)
650
643
ghost_to_owner = zeros (Int32,n_ghost)
651
- n_local = prod (map (length,local_ranges))
652
644
perm = zeros (Int32,n_local)
653
645
i_ghost = 0
654
646
i_own = 0
655
- n_own = prod (map (length,own_ranges))
647
+
648
+ cis = CartesianIndices (map (length,local_ranges))
656
649
lis = CircularArray (LinearIndices (n))
657
650
local_cis = CartesianIndices (local_ranges)
658
- owner_lis = CircularArray ( LinearIndices (np) )
651
+ owner_lis = LinearIndices (np)
659
652
for (i,ci) in enumerate (cis)
660
- flags = map (predicate,Tuple (p),Tuple (ci),owners)
653
+ flags = map (Tuple (ci), own_ranges, local_ranges) do i, or, lr
654
+ i in (or .- first (lr) .+ 1 )
655
+ end
661
656
if ! all (flags)
662
657
i_ghost += 1
663
658
ghost_to_global[i_ghost] = lis[local_cis[i]]
@@ -809,39 +804,32 @@ function renumber_partition(partition_in;renumber_local_indices=true)
809
804
end
810
805
811
806
function local_range (p,np,n,ghost= false ,periodic= false )
812
- l = n ÷ np
807
+ l, rem = divrem (n, np)
813
808
offset = l * (p- 1 )
814
- rem = n % np
815
809
if rem >= (np- p+ 1 )
816
- l = l + 1
817
- offset = offset + p - (np- rem) - 1
818
- end
819
- start = 1 + offset
820
- stop = l+ offset
821
- if ghost && np != 1
822
- if periodic || p!= 1
823
- start -= 1
824
- end
825
- if periodic || p!= np
826
- stop += 1
827
- end
828
- end
829
- start: stop
830
- end
831
-
832
- function boundary_owner (p,np,n,ghost= false ,periodic= false )
833
- start = p
834
- stop = p
835
- if ghost && np != 1
836
- if periodic || p!= 1
837
- start -= 1
838
- end
839
- if periodic || p!= np
840
- stop += 1
841
- end
810
+ l += 1
811
+ offset += p - (np- rem) - 1
842
812
end
843
- (start,p,stop)
844
- end
813
+ start = 1 + offset- ghost
814
+ stop = l+ offset+ ghost
815
+
816
+ periodic && return start: stop
817
+ return max (1 , start): min (n,stop)
818
+ end
819
+
820
+ # # unused
821
+ # function boundary_owner(p,np,n,ghost=false,periodic=false)
822
+ # start = p
823
+ # stop = p
824
+
825
+ # if periodic || p!=1
826
+ # start -= ghost
827
+ # end
828
+ # if periodic || p!=np
829
+ # stop += ghost
830
+ # end
831
+ # (start,p,stop)
832
+ # end
845
833
846
834
struct VectorFromDict{Tk,Tv} <: AbstractVector{Tv}
847
835
dict:: Dict{Tk,Tv}
0 commit comments