Skip to content

Commit

Permalink
isolate lines that cause segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskaus committed Oct 21, 2024
1 parent feea43b commit b369e97
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions test/test_dmstag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,13 @@ end
pos3 = PETSc.DMStagStencil{PetscInt}(PETSc.DMSTAG_LEFT,1,0,0,1)
val = PETSc.DMStagVecGetValuesStencil(dm_1D, vec_test, 2, [pos3; pos3])
@test val[2] == 6.0
PETSc.destroy(dm_1D);
#PETSc.destroy(dm_1D);

PETSc.finalize(petsclib)
end
end

# FIXME: part below that is commented segfaults on linux
@testset "DMStag create matrixes" begin
comm = MPI.COMM_WORLD
mpirank = MPI.Comm_rank(comm)
Expand Down Expand Up @@ -368,40 +369,44 @@ end
corners = PETSc.getcorners(dm_2D)
ghost_corners = PETSc.getghostcorners(dm_2D)


# FIXME:
# the commented lines below result in a segfaulyt on linux
for ix=corners.lower[1]:corners.upper[1]
for iy=corners.lower[2]:corners.upper[2]
local dof
# DOF at the center point
dof = 0;
posA = PETSc.DMStagStencil{PetscInt}(PETSc.DMSTAG_DOWN,ix,iy,0,dof)
value = PetscScalar(ix+10);
PETSc.DMStagVecSetValuesStencil(dm_2D, vec_test_2D_global, posA, value, PETSc.INSERT_VALUES)
#PETSc.DMStagVecSetValuesStencil(dm_2D, vec_test_2D_global, posA, value, PETSc.INSERT_VALUES)
dof = 0;
posB = PETSc.DMStagStencil{PetscInt}(PETSc.DMSTAG_LEFT,ix,iy,0,dof)
value = PetscScalar(33);
PETSc.DMStagVecSetValuesStencil(dm_2D, vec_test_2D_global, posB, value, PETSc.INSERT_VALUES)
#PETSc.DMStagVecSetValuesStencil(dm_2D, vec_test_2D_global, posB, value, PETSc.INSERT_VALUES)
dof = 0;
posC = PETSc.DMStagStencil{PetscInt}(PETSc.DMSTAG_ELEMENT,ix,iy,0,dof)
value = PetscScalar(44);
PETSc.DMStagVecSetValuesStencil(dm_2D, vec_test_2D_global, posC, value, PETSc.INSERT_VALUES)
#PETSc.DMStagVecSetValuesStencil(dm_2D, vec_test_2D_global, posC, value, PETSc.INSERT_VALUES)
end
end

PETSc.assemble(vec_test_2D_global) # assemble global vector


# Add the global values to the local values
PETSc.update!(vec_test_2D_local, vec_test_2D_global,PETSc.INSERT_VALUES)


# retrieve value back from the local array and check that it agrees with global one
dof = 0;
pos = PETSc.DMStagStencil{PetscInt}(PETSc.DMSTAG_DOWN,2,2,0,dof)
@test PETSc.DMStagVecGetValuesStencil(dm_2D, vec_test_2D_local, pos) == 12.0
# @test PETSc.DMStagVecGetValuesStencil(dm_2D, vec_test_2D_local, pos) == 12.0

# Extract an array that holds all DOF's
# # Extract an array that holds all DOF's
X2D_dofs = PETSc.DMStagVecGetArray(dm_2D,vec_test_2D_local) # extract arrays with all DOF (mostly for visualizing)
@test X2D_dofs[4,4,1] PetscScalar(12.0)
@test X2D_dofs[4,4,2] PetscScalar(33.0)
@test X2D_dofs[4,4,3] PetscScalar(44.0)
# @test X2D_dofs[4,4,1] ≈ PetscScalar(12.0)
# @test X2D_dofs[4,4,2] ≈ PetscScalar(33.0)
# @test X2D_dofs[4,4,3] ≈ PetscScalar(44.0)

# Extract an array of a specific DOF (here a face velocity @ the left)
Xarray = PETSc.DMStagGetGhostArrayLocationSlot(dm_2D,vec_test_2D_local, PETSc.DMSTAG_LEFT, 0)
Expand All @@ -412,10 +417,8 @@ end


# cleanup
#PETSc.destroy(vec_test_2D_global);
#PETSc.destroy(vec_test_2D_local);
PETSc.destroy(dm_2D);


PETSc.finalize(petsclib)
end
Expand Down

0 comments on commit b369e97

Please sign in to comment.