[petsc-users] MetSetValues not found
Sanjay Govindjee
s_g at berkeley.edu
Sat Aug 19 15:47:58 CDT 2023
I recently got a copy of E.Bueler's petsc book and was converting the
programs to fortran for my students and have run into a compile error that
I can not figure out. I comment out the MatSetValues line the code
compiles fine.
When I run make on vecmatkspf.F90, I get the error:
42 | PetscCallA(MatSetValues(A,1,i,4,j,aA,INSERT_VALUES,ierr))
| 1
Error: There is no specific subroutine for the generic
'matsetvalues' at (1)
My petsc set works, runs with my FEA code and compiles and runs the fortran
programs in the petsc tutorials directories just fine. And in
particular, compiles
and runs the C versions from Bueler.
I've attached the make file and the source. I must be doing something
obviously wrong but I can not spot it.
-sanjay
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230819/bda9fa85/attachment-0001.html>
-------------- next part --------------
! Fortran version of vecmatksp.c
program vecmatkspf
#include <petsc/finclude/petscksp.h>
use petscksp
use petscmat
Vec :: x, b
Mat :: A
KSP :: ksp
PetscInt :: i, j(4)
PetscReal :: ab(4),aA(4,4)
PetscErrorCode :: ierr
data j /0,1,2,3/
data ab /7.0, 1.0, 1.0, 3.0/
data aA /1.0, 2.0, -1.0, 0.0, &
2.0, 1.0, 1.0, 1.0, &
3.0, -2.0, 1.0, 1.0, &
0.0, -3.0, 0.0, -1.0/
PetscCallA(PetscInitialize(PETSC_NULL_CHARACTER,"Solve a 4x4 linear system using KSP.\n",ierr))
PetscCallA(VecCreate(PETSC_COMM_WORLD,b,ierr))
PetscCallA(VecSetSizes(b,PETSC_DECIDE,4,ierr))
PetscCallA(VecSetFromOptions(b,ierr))
PetscCallA(VecSetValues(b,4,j,ab,INSERT_VALUES,ierr))
PetscCallA(VecAssemblyBegin(b,ierr))
PetscCallA(VecAssemblyEnd(b,ierr))
PetscCallA(MatCreate(PETSC_COMM_WORLD,A,ierr))
PetscCallA(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,4,4,ierr))
PetscCallA(MatSetFromOptions(A,ierr))
PetscCallA(MatSetUp(A,ierr))
do i = 0,3
PetscCallA(MatSetValues(A,1,i,4,j,aA,INSERT_VALUES,ierr))
end do
PetscCallA(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr))
PetscCallA(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr))
PetscCallA(KSPCreate(PETSC_COMM_WORLD,ksp,ierr))
PetscCallA(KSPSetOperators(ksp,A,A,ierr))
PetscCallA(KSPSetFromOptions(ksp,ierr))
PetscCallA(VecDuplicate(b,x,ierr))
PetscCallA(KSPSolve(ksp,b,x,ierr))
PetscCallA(VecView(x,PETSC_VIEWER_STDOUT_WORLD,ierr))
PetscCallA(KSPDestroy(ksp,ierr))
PetscCallA(MatDestroy(A,ierr))
PetscCallA(VecDestroy(x,ierr))
PetscCallA(VecDestroy(b,ierr))
PetscCallA(PetscFinalize(ierr))
end program vecmatkspf
-------------- next part --------------
include ${PETSC_DIR}/lib/petsc/conf/variables
include ${PETSC_DIR}/lib/petsc/conf/rules
CFLAGS += -pedantic -std=c99
sparsemat: sparsemat.o
-${CLINKER} -o sparsemat sparsemat.o ${PETSC_LIB}
${RM} sparsemat.o
vecmatksp: vecmatksp.o
-${CLINKER} -o vecmatksp vecmatksp.o ${PETSC_LIB}
${RM} vecmatksp.o
vecmatkspf: vecmatkspf.o
-${FLINKER} -o vecmatkspf vecmatkspf.o ${PETSC_FORTRAN_LIB} ${PETSC_LIB}
${RM} vecmatkspf.o
tri: tri.o
-${CLINKER} -o tri tri.o ${PETSC_LIB}
${RM} tri.o
loadsolve: loadsolve.o
-${CLINKER} -o loadsolve loadsolve.o ${PETSC_LIB}
${RM} loadsolve.o
# testing
runsparsemat_1:
- at ../testit.sh sparsemat "-mat_view" 1 1
runvecmatksp_1:
- at ../testit.sh vecmatksp "" 1 1
runtri_1:
- at ../testit.sh tri "-a_mat_view ::ascii_dense" 1 1
runtri_2:
- at ../testit.sh tri "-tri_m 1000 -ksp_rtol 1.0e-4 -ksp_type cg -pc_type bjacobi -sub_pc_type jacobi -ksp_converged_reason" 2 2
runloadsolve_1:
- at ./tri -ksp_view_mat binary:A.dat -ksp_view_rhs binary:b.dat > /dev/null
- at ../testit.sh loadsolve "-verbose -fA A.dat -fb b.dat -ksp_view_mat -ksp_view_rhs -ksp_view_solution" 1 1
test_sparsemat: runsparsemat_1
test_vecmatksp: runvecmatksp_1
test_tri: runtri_1 runtri_2
test_loadsolve: runloadsolve_1
test: test_sparsemat test_vecmatksp test_tri test_loadsolve
# etc
.PHONY: clean distclean runvecmatksp_1 runtri_1 runtri_2 runloadsolve_1 test test_vecmatksp test_tri test_loadsolve
distclean: clean
clean::
@rm -f *~ sparsemat vecmatksp tri loadsolve *tmp
@rm -f *.dat *.dat.info
More information about the petsc-users
mailing list