Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update stencil2coo kernels for shifts > 1 #442

Merged
merged 5 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions psydac/linalg/kernels/stencil2coo_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def stencil2coo_1d_C(A:'T[:,:]', data:'T[:]', rows:'int64[:]', cols:'int64[:]',
for j1 in range(ncl1):
value = A[i1+pp1,j1]
if abs(value) == 0.0:continue
J = ((I//cm1)*dm1+j1-dp1)%nc1
J = ((I*dm1//cm1)+j1-dp1)%nc1
rows[nnz] = I
cols[nnz] = J
data[nnz] = value
Expand All @@ -38,7 +38,7 @@ def stencil2coo_1d_F(A:'T[:,:]', data:'T[:]', rows:'int64[:]', cols:'int64[:]',
for j1 in range(ncl1):
value = A[i1+pp1,j1]
if abs(value) == 0.0:continue
J = ((I//cm1)*dm1+j1-dp1)%nc1
J = ((I*dm1//cm1)+j1-dp1)%nc1
rows[nnz] = I
cols[nnz] = J
data[nnz] = value
Expand Down Expand Up @@ -66,8 +66,8 @@ def stencil2coo_2d_C(A:'T[:,:,:,:]', data:'T[:]', rows:'int64[:]', cols:'int64[:
for j2 in range(ncl2):
value = A[i1+pp1,i2+pp2,j1,j2]
if abs(value) == 0.0:continue
jj1 = ((ii1//cm1)*dm1+j1-dp1)%nc1
jj2 = ((ii2//cm2)*dm2+j2-dp2)%nc2
jj1 = ((ii1*dm1//cm1)+j1-dp1)%nc1
jj2 = ((ii2*dm2//cm2)+j2-dp2)%nc2

J = jj1*nc2 + jj2

Expand Down Expand Up @@ -97,8 +97,8 @@ def stencil2coo_2d_F(A:'T[:,:,:,:]', data:'T[:]', rows:'int64[:]', cols:'int64[:
for j2 in range(ncl2):
value = A[i1+pp1,i2+pp2,j1,j2]
if abs(value) == 0.0:continue
jj1 = ((ii1//cm1)*dm1+j1-dp1)%nc1
jj2 = ((ii2//cm2)*dm2+j2-dp2)%nc2
jj1 = ((ii1*dm1//cm1)+j1-dp1)%nc1
jj2 = ((ii2*dm2//cm2)+j2-dp2)%nc2

J = jj2*nc1 + jj1

Expand Down Expand Up @@ -132,9 +132,9 @@ def stencil2coo_3d_C(A:'T[:,:,:,:,:,:]', data:'T[:]', rows:'int64[:]', cols:'int
for j3 in range(ncl3):
value = A[i1+pp1,i2+pp2,i3+pp3,j1,j2,j3]
if abs(value) == 0.0:continue
jj1 = ((ii1//cm1)*dm1+j1-dp1)%nc1
jj2 = ((ii2//cm2)*dm2+j2-dp2)%nc2
jj3 = ((ii3//cm3)*dm3+j3-dp3)%nc3
jj1 = ((ii1*dm1//cm1)+j1-dp1)%nc1
jj2 = ((ii2*dm2//cm2)+j2-dp2)%nc2
jj3 = ((ii3*dm3//cm3)+j3-dp3)%nc3

J = jj1*nc2*nc3 + jj2*nc3 + jj3

Expand Down Expand Up @@ -170,9 +170,9 @@ def stencil2coo_3d_F(A:'T[:,:,:,:,:,:]', data:'T[:]', rows:'int64[:]', cols:'int
for j3 in range(ncl3):
value = A[i1+pp1,i2+pp2,i3+pp3,j1,j2,j3]
if abs(value) == 0.0:continue
jj1 = ((ii1//cm1)*dm1+j1-dp1)%nc1
jj2 = ((ii2//cm2)*dm2+j2-dp2)%nc2
jj3 = ((ii3//cm3)*dm3+j3-dp3)%nc3
jj1 = ((ii1*dm1//cm1)+j1-dp1)%nc1
jj2 = ((ii2*dm2//cm2)+j2-dp2)%nc2
jj3 = ((ii3*dm3//cm3)+j3-dp3)%nc3

J = jj3*nc1*nc2 + jj2*nc1 + jj1

Expand Down
6 changes: 3 additions & 3 deletions psydac/linalg/tests/test_stencil_matrix.py
max-models marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def test_stencil_matrix_2d_serial_spurious_entries( dtype, p1, p2, s1, s2, P1, P
@pytest.mark.parametrize('dtype', [float])
@pytest.mark.parametrize('n1', [7])
@pytest.mark.parametrize('p1', [1,2])
@pytest.mark.parametrize('s1', [1])
@pytest.mark.parametrize('s1', [1, 2])
@pytest.mark.parametrize('P1', [True, False])
def test_stencil_matrix_1d_serial_toarray( dtype, n1, p1, s1, P1):
# Select non-zero values based on diagonal index
Expand Down Expand Up @@ -489,8 +489,8 @@ def test_stencil_matrix_1d_serial_toarray( dtype, n1, p1, s1, P1):
@pytest.mark.parametrize('n2', [8, 7])
@pytest.mark.parametrize('p1', [1, 2])
@pytest.mark.parametrize('p2', [1, 3])
@pytest.mark.parametrize('s1', [1])
@pytest.mark.parametrize('s2', [1])
@pytest.mark.parametrize('s1', [1, 2])
@pytest.mark.parametrize('s2', [1, 2])
@pytest.mark.parametrize('P1', [True, False])
@pytest.mark.parametrize('P2', [True, False])
def test_stencil_matrix_2d_serial_toarray( dtype, n1, n2, p1, p2, s1, s2, P1, P2):
Expand Down