Skip to content

Commit ea04326

Browse files
authored
Merge pull request #132 from fverdugo/allow_negative_indices
Allow non positive indices (cont.)
2 parents ac69c40 + b0cb22b commit ea04326

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

src/p_range.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ function filter_ghost(indices,gids,owners)
208208
n_new_ghost = 0
209209
global_to_ghost_indices = global_to_ghost(indices)
210210
for (global_i,owner) in zip(gids,owners)
211+
if global_i < 1
212+
continue
213+
end
211214
if owner != part_owner
212215
ghost_i = global_to_ghost_indices[global_i]
213216
if ghost_i == 0 && !(global_i in set)
@@ -221,6 +224,9 @@ function filter_ghost(indices,gids,owners)
221224
new_ghost_i = 0
222225
set = Set{Int}()
223226
for (global_i,owner) in zip(gids,owners)
227+
if global_i < 1
228+
continue
229+
end
224230
if owner != part_owner
225231
ghost_i = global_to_ghost_indices[global_i]
226232
if ghost_i == 0 && !(global_i in set)
@@ -293,6 +299,9 @@ function map_x_to_y!(x_to_y,I,indices)
293299
local_to_global_indices = x_to_y(indices)
294300
for k in 1:length(I)
295301
Ik = I[k]
302+
if Ik < 1
303+
continue
304+
end
296305
I[k] = local_to_global_indices[Ik]
297306
end
298307
I
@@ -1251,9 +1260,23 @@ function find_owner(indices,global_ids,::Type{<:OwnAndGhostIndices{T}}) where T
12511260
if T == Nothing
12521261
error("Not enough data to perform this operation without communciation")
12531262
end
1254-
map(indices,global_ids) do indices,global_ids
1255-
indices.global_to_owner[global_ids]
1263+
map(global_ids,indices) do global_ids, indices
1264+
map_global_to_owner(global_ids,indices.global_to_owner)
1265+
end
1266+
end
1267+
1268+
function map_global_to_owner(I,global_to_owner)
1269+
Ti = eltype(global_to_owner)
1270+
owners = Vector{Ti}(undef,length(I))
1271+
for k in 1:length(I)
1272+
i = I[k]
1273+
if i<1
1274+
owners[k] = zero(Ti)
1275+
continue
1276+
end
1277+
owners[k] = global_to_owner[i]
12561278
end
1279+
owners
12571280
end
12581281

12591282
part_id(a::OwnAndGhostIndices) = a.own.owner
@@ -1567,7 +1590,7 @@ function find_owner(indices,global_ids,::Type{<:LocalIndicesWithConstantBlockSiz
15671590
start
15681591
end
15691592
global_to_owner = BlockPartitionGlobalToOwner(start)
1570-
global_to_owner[global_ids]
1593+
map_global_to_owner(global_ids,global_to_owner)
15711594
end
15721595
end
15731596

@@ -1600,7 +1623,7 @@ function find_owner(indices,global_ids,::Type{<:LocalIndicesWithVariableBlockSiz
16001623
start = vcat(initial,[n+1])
16011624
end
16021625
global_to_owner = BlockPartitionGlobalToOwner(start)
1603-
global_to_owner[global_ids]
1626+
map_global_to_owner(global_ids,global_to_owner)
16041627
end
16051628
end
16061629

src/p_sparse_matrix.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,18 +1301,6 @@ function psparse_assemble_impl(
13011301
k_rcv = JaggedArray(k_rcv_data,I_rcv.ptrs)
13021302
(;I_rcv,J_rcv,V_rcv,k_rcv,parts_rcv)
13031303
end
1304-
function setup_touched_col_ids(A,cache_rcv,cols_sa)
1305-
J_rcv_data = cache_rcv.J_rcv.data
1306-
l1 = nnz(A.own_ghost)
1307-
l2 = length(J_rcv_data)
1308-
J_aux = zeros(Int,l1+l2)
1309-
ghost_to_global_col = ghost_to_global(cols_sa)
1310-
for (p,(_,j,_)) in enumerate(nziterator(A.own_ghost))
1311-
J_own_ghost[p] = ghost_to_global_col[j]
1312-
end
1313-
J_aux[l1.+(1:l2)] = J_rcv_data
1314-
J_aux
1315-
end
13161304
function setup_own_triplets(A,cache_rcv,rows_sa,cols_sa)
13171305
nz_own_own = findnz(A.blocks.own_own)
13181306
nz_own_ghost = findnz(A.blocks.own_ghost)

src/p_vector.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,24 @@ function dense_vector(I,V,n)
555555
T = eltype(V)
556556
a = zeros(T,n)
557557
for (i,v) in zip(I,V)
558+
if i < 1
559+
continue
560+
end
558561
a[i] += v
559562
end
560563
a
561564
end
562565

566+
function dense_vector!(A,K,V)
567+
fill!(A,0)
568+
for (k,v) in zip(K,V)
569+
if k < 1
570+
continue
571+
end
572+
A[k] += v
573+
end
574+
end
575+
563576
function pvector(I,V,rows;kwargs...)
564577
pvector(dense_vector,I,V,rows;kwargs...)
565578
end
@@ -665,16 +678,10 @@ end
665678
pvector!(B::PVector,V,cache)
666679
"""
667680
function pvector!(B,V,cache)
668-
function update!(A,K,V)
669-
fill!(A,0)
670-
for (k,v) in zip(K,V)
671-
A[k] += v
672-
end
673-
end
674681
(A,cacheB,assemble,assembled,K) = cache
675682
rows_sa = partition(axes(A,1))
676683
values_sa = partition(A)
677-
map(update!,values_sa,K,V)
684+
map(dense_vector!,values_sa,K,V)
678685
if !assembled && assemble
679686
t = PartitionedArrays.assemble!(B,A,cacheB)
680687
else

test/p_sparse_matrix_tests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ function p_sparse_matrix_tests(distribute)
206206
if part == 1
207207
[1,2,1,2,2], [2,6,1,2,1], [1.0,2.0,30.0,10.0,1.0]
208208
elseif part == 2
209-
[3,3,4,6], [3,9,4,2], [10.0,2.0,30.0,2.0]
209+
[3,3,4,6,0], [3,9,4,2,0], [10.0,2.0,30.0,2.0,2.0]
210210
elseif part == 3
211211
[5,5,6,7], [5,6,6,7], [10.0,2.0,30.0,1.0]
212212
else
213-
[9,9,8,10,6], [9,3,8,10,5], [10.0,2.0,30.0,50.0,2.0]
213+
[9,9,8,10,6,-1], [9,3,8,10,5,1], [10.0,2.0,30.0,50.0,2.0,1.0]
214214
end
215215
end |> tuple_of_arrays
216216

0 commit comments

Comments
 (0)