Reuse matrix and vector
jarunan at ascomp.ch
jarunan at ascomp.ch
Thu Nov 5 03:32:17 CST 2009
Hello,
I would like to reuse matrix and vector to save computing time. As the
result in last iterations are not similar to the one from my old
solver, so I am not sure if I program with PETSc the right way,
especially, resetting values to matrix with
MatMPIAIJSetPreallocationCSR(). Please take a look, here is how I
program it:
At the beginning of the program I create the vector and matrix.
call VecCreateMPI(PETSC_COMM_WORLD,istorf_no_ovcell,PETSC_DETERMINE,rhs,ierr)
call VecDuplicate(rhs,sol,ierr)
call MatCreate(PETSC_COMM_WORLD,Ap,ierr)
call
MatSetSizes(Ap,istorf_no_ovcell,istorf_no_ovcell,PETSC_DETERMINE,PETSC_DETERMINE,ierr)
call MatSetType(Ap,MATMPIAIJ,ierr)
Then, in each loop I reset values in the vector and the matrix.
do niter = 1,maxiter
call VecSetValues(rhs,w,gindex_issu(1:w),f_issu(1:w),INSERT_VALUES,ierr)
call VecAssemblyBegin(rhs,ierr)
call VecAssemblyEnd(rhs,ierr)
call MatMPIAIJSetPreallocationCSR(Ap,rowind,columnind,A,ierr)
call MatAssemblyBegin(Ap,MAT_FINAL_ASSEMBLY,ierr)
call MatAssemblyEnd(Ap,MAT_FINAL_ASSEMBLY,ierr)
call solve_system
call update_right_hand_side
endo
call MatDestroy(Ap,ierr)
call VecDestroy(sol,ierr)
call VecDestroy(rhs,ierr)
Regards,
Jarunan
--
Jarunan Panyasantisuk
Development Engineer
ASCOMP GmbH, Technoparkstr. 1
CH-8005 Zurich, Switzerland
Phone : +41 44 445 4072
Fax : +41 44 445 4075
E-mail: jarunan at ascomp.ch
www.ascomp.ch
More information about the petsc-users
mailing list