<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi,<br>
<br>
I'm trying to rewrite ex29 (KSP^Laplacian, 2d) from c to fortran
version. The fortran version is based on the template of ex22f,
which is in 3d.<br>
<br>
I have attached the code below. I have 2 problems.<br>
<br>
1. When i3 = -3, in dirichlet BC, I got the same answer as ex29 in c
version.<br>
<br>
However, when I change i3 to -4, I got the following error:<br>
<br>
[0]PETSC ERROR: --------------------- Error Message
----------------------------<br>
--------<br>
[0]PETSC ERROR: Argument out of range!<br>
[0]PETSC ERROR: New nonzero at (9,1) caused a malloc!<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: Petsc Development HG revision:
fc934c1d84bc6ba8e2686702a8a99539d<br>
50af122 HG Date: Mon Apr 23 11:39:32 2012 -0500<br>
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: c:\obj_tmp\ex29f\Debug\ex29f.exe on a petsc-3.2
named USER-PC by<br>
User Tue Apr 24 22:08:46 2012<br>
[0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
/lib<br>
[0]PETSC ERROR: Configure run at Mon Apr 23 21:45:20 2012<br>
[0]PETSC ERROR: Configure options --with-cc="win32fe cl"
--with-fc="win32fe ifor<br>
t" --with-cxx="win32fe cl" --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
--download-f-b<br>
las-lapack=1 --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
--with-debuggin<br>
g=1 --useThreads=0<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: MatSetValues_SeqAIJ() line 331 in
src/mat/impls/aij/seq/C:\temp\<br>
PETSC-~1\src\mat\impls\aij\seq\aij.c<br>
[0]PETSC ERROR: MatSetValues() line 1148 in
src/mat/interface/C:\temp\PETSC-~1\s<br>
rc\mat\INTERF~1\matrix.c<br>
[0]PETSC ERROR: MatSetValuesLocal() line 2003 in
src/mat/interface/C:\temp\PETSC<br>
-~1\src\mat\INTERF~1\matrix.c<br>
[0]PETSC ERROR: MatSetValuesStencil() line 1379 in
src/mat/interface/C:\temp\PET<br>
SC-~1\src\mat\INTERF~1\matrix.c<br>
[0]PETSC ERROR: --------------------- Error Message
----------------------------<br>
--------<br>
[0]PETSC ERROR: Argument out of range!<br>
[0]PETSC ERROR: New nonzero at (10,2) caused a malloc!<br>
<br>
...<br>
<br>
What did I do wrong?<br>
<br>
<br>
2. When I wanted to use the neumann BC, following ex29, I added :<br>
<br>
In subroutine ComputeRHS<br>
<br>
call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,nullspace,ierr)<br>
<br>
call MatNullSpaceRemove(nullspace,b,PETSC_NULL,ierr)<br>
<br>
call MatNullSpaceDestroy(nullspace,ierr)<br>
<br>
and in subroutine ComputeMatrix<br>
<br>
call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,nullspace,ierr)<br>
<br>
call MatSetNullSpace(jac,nullspace,ierr)<br>
<br>
call MatNullSpaceDestroy(nullspace,ierr)<br>
<br>
When I compile, it says unresolved external symbol
MatNullSpaceRemove. Removing MatNullSpaceRemove, I can compile but
running gives the error:<br>
<br>
[0]PETSC ERROR: --------------------- Error Message
----------------------------<br>
--------<br>
[0]PETSC ERROR: Corrupt argument:<br>
see <a class="moz-txt-link-freetext" href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a>!<br>
[0]PETSC ERROR: Invalid Pointer to Object: Parameter # 4!<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: Petsc Development HG revision:
fc934c1d84bc6ba8e2686702a8a99539d<br>
50af122 HG Date: Mon Apr 23 11:39:32 2012 -0500<br>
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: c:\obj_tmp\ex29f\Debug\ex29f.exe on a petsc-3.2
named USER-PC by<br>
User Tue Apr 24 22:30:31 2012<br>
[0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
/lib<br>
[0]PETSC ERROR: Configure run at Mon Apr 23 21:45:20 2012<br>
[0]PETSC ERROR: Configure options --with-cc="win32fe cl"
--with-fc="win32fe ifor<br>
t" --with-cxx="win32fe cl" --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
--download-f-b<br>
las-lapack=1 --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
--with-debuggin<br>
g=1 --useThreads=0<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: MatNullSpaceCreate() line 250 in
src/mat/interface/C:\temp\PETSC<br>
-~1\src\mat\INTERF~1\matnull.c<br>
[0]PETSC ERROR: --------------------- Error Message
----------------------------<br>
--------<br>
[0]PETSC ERROR: Invalid argument!<br>
[0]PETSC ERROR: Wrong type of object: Parameter # 1!<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: Petsc Development HG revision:
fc934c1d84bc6ba8e2686702a8a99539d<br>
50af122 HG Date: Mon Apr 23 11:39:32 2012 -0500<br>
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: c:\obj_tmp\ex29f\Debug\ex29f.exe on a petsc-3.2
named USER-PC by<br>
User Tue Apr 24 22:30:31 2012<br>
[0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
/lib<br>
[0]PETSC ERROR: Configure run at Mon Apr 23 21:45:20 2012<br>
[0]PETSC ERROR: Configure options --with-cc="win32fe cl"
--with-fc="win32fe ifor<br>
t" --with-cxx="win32fe cl" --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
--download-f-b<br>
las-lapack=1 --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
--with-debuggin<br>
g=1 --useThreads=0<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: MatNullSpaceDestroy() line 305 in
src/mat/interface/C:\temp\PETS<br>
C-~1\src\mat\INTERF~1\matnull.c<br>
[0]PETSC ERROR: ourdmfunction() line 30 in
src/dm/interface/ftn-custom/C:\temp\P<br>
ETSC-~1\src\dm\INTERF~1\FTN-CU~1\zdmf.c<br>
[0]PETSC ERROR: DMComputeFunction() line 1783 in
src/dm/interface/C:\temp\PETSC-<br>
~1\src\dm\INTERF~1\dm.c<br>
[0]PETSC ERROR: KSPSetUp() line 218 in
src/ksp/ksp/interface/C:\temp\PETSC-~1\sr<br>
c\ksp\ksp\INTERF~1\itfunc.c<br>
[0]PETSC ERROR: --------------------- Error Message
----------------------------<br>
--------<br>
[0]PETSC ERROR: Corrupt argument:<br>
see <a class="moz-txt-link-freetext" href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a>!<br>
[0]PETSC ERROR: Invalid Pointer to Object: Parameter # 4!<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: Petsc Development HG revision:
fc934c1d84bc6ba8e2686702a8a99539d<br>
50af122 HG Date: Mon Apr 23 11:39:32 2012 -0500<br>
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: c:\obj_tmp\ex29f\Debug\ex29f.exe on a petsc-3.2
named USER-PC by<br>
User Tue Apr 24 22:30:31 2012<br>
[0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
/lib<br>
[0]PETSC ERROR: Configure run at Mon Apr 23 21:45:20 2012<br>
[0]PETSC ERROR: Configure options --with-cc="win32fe cl"
--with-fc="win32fe ifor<br>
t" --with-cxx="win32fe cl" --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
--download-f-b<br>
las-lapack=1 --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
--with-debuggin<br>
g=1 --useThreads=0<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: MatNullSpaceCreate() line 250 in
src/mat/interface/C:\temp\PETSC<br>
-~1\src\mat\INTERF~1\matnull.c<br>
[0]PETSC ERROR: --------------------- Error Message
----------------------------<br>
--------<br>
[0]PETSC ERROR: Invalid argument!<br>
[0]PETSC ERROR: Wrong type of object: Parameter # 1!<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: Petsc Development HG revision:
fc934c1d84bc6ba8e2686702a8a99539d<br>
50af122 HG Date: Mon Apr 23 11:39:32 2012 -0500<br>
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: c:\obj_tmp\ex29f\Debug\ex29f.exe on a petsc-3.2
named USER-PC by<br>
User Tue Apr 24 22:30:31 2012<br>
[0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
/lib<br>
[0]PETSC ERROR: Configure run at Mon Apr 23 21:45:20 2012<br>
[0]PETSC ERROR: Configure options --with-cc="win32fe cl"
--with-fc="win32fe ifor<br>
t" --with-cxx="win32fe cl" --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
--download-f-b<br>
las-lapack=1 --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
--with-debuggin<br>
g=1 --useThreads=0<br>
[0]PETSC ERROR:
----------------------------------------------------------------<br>
--------<br>
[0]PETSC ERROR: MatNullSpaceDestroy() line 305 in
src/mat/interface/C:\temp\PETS<br>
C-~1\src\mat\INTERF~1\matnull.c<br>
[0]PETSC ERROR: ourdmfunction() line 30 in
src/dm/interface/ftn-custom/C:\temp\P<br>
ETSC-~1\src\dm\INTERF~1\FTN-CU~1\zdmf.c<br>
[0]PETSC ERROR: DMComputeFunction() line 1783 in
src/dm/interface/C:\temp\PETSC-<br>
~1\src\dm\INTERF~1\dm.c<br>
[0]PETSC ERROR: KSPSetUp() line 218 in
src/ksp/ksp/interface/C:\temp\PETSC-~1\sr<br>
c\ksp\ksp\INTERF~1\itfunc.c<br>
[0]PETSC ERROR: KSPSolve() line 402 in
src/ksp/ksp/interface/C:\temp\PETSC-~1\sr<br>
c\ksp\ksp\INTERF~1\itfunc.c<br>
Vector Object:Vec_0000000084000000_0 1 MPI processes<br>
type: mpi<br>
Process [0]<br>
<br>
What's wrong?<br>
<br>
<br>
<b>program ex29f</b><br>
<br>
implicit none<br>
<br>
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -<br>
! Include files<br>
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -<br>
!<br>
! petscsys.h - base PETSc routines petscvec.h - vectors<br>
! petscmat.h - matrices<br>
! petscksp.h - Krylov subspace methods petscpc.h -
preconditioners<br>
<br>
#include "finclude/petsc.h90"<br>
<br>
PetscErrorCode ierr<br>
<br>
DM da<br>
<br>
KSP ksp<br>
<br>
Vec x<br>
<br>
external ComputeRHS,ComputeMatrix<br>
<br>
PetscInt i1,i3<br>
<br>
call PetscInitialize(PETSC_NULL_CHARACTER,ierr)<br>
<br>
i3 = -4<br>
<br>
i1 = 1<br>
<br>
call KSPCreate(MPI_COMM_WORLD,ksp,ierr)<br>
<br>
call
DMDACreate2d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR,i3,i3,PETSC_DECIDE,PETSC_DECIDE,i1,i1,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,da,ierr)<br>
call DMSetFunction(da,ComputeRHS,ierr)<br>
call DMSetJacobian(da,ComputeMatrix,ierr) <br>
call KSPSetDM(ksp,da,ierr)<br>
<br>
call KSPSetFromOptions(ksp,ierr)<br>
call KSPSetUp(ksp,ierr)<br>
call KSPSolve(ksp,PETSC_NULL_OBJECT,PETSC_NULL_OBJECT,ierr)<br>
call KSPGetSolution(ksp,x,ierr)<br>
call VecView(x,PETSC_VIEWER_STDOUT_WORLD,ierr)<br>
call KSPDestroy(ksp,ierr)<br>
call DMDestroy(da,ierr)<br>
call PetscFinalize(ierr)<br>
<br>
end program ex29f<br>
<br>
subroutine ComputeRHS(da,x,b,ierr)<br>
<br>
implicit none<br>
<br>
#include "finclude/petsc.h90"<br>
<br>
PetscErrorCode ierr<br>
PetscInt i,j,mx,my,xm,ym,xs,ys<br>
PetscScalar h,nu,rho<br>
PetscScalar Hx,Hy<br>
PetscScalar,pointer :: array(:,:)<br>
Vec x,b<br>
DM da<br>
MatNullSpace nullspace !>neumann BC<br>
<br>
nu = 0.1<br>
<br>
call
DMDAGetInfo(da,PETSC_NULL_INTEGER,mx,my,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,ierr)<br>
<br>
Hx = 1.d0 / (mx-1)<br>
<br>
Hy = 1.d0 / (my-1)<br>
<br>
call
DMDAGetCorners(da,xs,ys,PETSC_NULL_INTEGER,xm,ym,PETSC_NULL_INTEGER,ierr)<br>
<br>
call DMDAVecGetArrayF90(da,b,array,ierr)<br>
<br>
do j = ys,ys+ym-1<br>
<br>
do i = xs,xs+xm-1<br>
<br>
array(i,j) =
exp(-(i*Hx)*(i*Hx)/nu)*exp(-(j*Hy)*(j*Hy)/nu)*Hx*Hy<br>
<br>
end do<br>
<br>
end do<br>
<br>
call DMDAVecRestoreArrayF90(da,b,array,ierr)<br>
<br>
call VecAssemblyBegin(b,ierr)<br>
<br>
call VecAssemblyEnd(b,ierr)<br>
<br>
!call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,nullspace,ierr)<br>
<br>
!call MatNullSpaceRemove(nullspace,b,PETSC_NULL,ierr)<br>
<br>
!call MatNullSpaceDestroy(nullspace,ierr)<br>
<br>
end subroutine ComputeRHS<br>
<br>
<br>
subroutine ComputeMatrix(da,x,JJ,jac,str,ierr)<br>
<br>
implicit none<br>
<br>
#include "finclude/petsc.h90"<br>
<br>
Mat jac,JJ<br>
<br>
PetscErrorCode ierr<br>
<br>
DM da<br>
<br>
PetscInt i,j,k,mx,my,xm<br>
<br>
PetscInt ym,xs,ys,i1,i5<br>
<br>
PetscScalar v(5),Hx,Hy,rho,centerRho<br>
<br>
PetscScalar HydHx<br>
<br>
PetscScalar HxdHy<br>
<br>
MatStencil row(4),col(4,5)<br>
<br>
Vec x<br>
<br>
MatStructure str<br>
<br>
MatNullSpace nullspace !>neumann BC<br>
<br>
rho = 1.0<br>
<br>
i1 = 1<br>
<br>
i5 = 5<br>
<br>
centerRho = rho<br>
<br>
call
DMDAGetInfo(da,PETSC_NULL_INTEGER,mx,my,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,ierr)<br>
<br>
Hx = 1.d0 / (mx-1)<br>
<br>
Hy = 1.d0 / (my-1)<br>
<br>
HxdHy = Hx/Hy<br>
<br>
HydHx = Hy/Hx<br>
<br>
call
DMDAGetCorners(da,xs,ys,PETSC_NULL_INTEGER,xm,ym,PETSC_NULL_INTEGER,ierr)
<br>
<br>
do j=ys,ys+ym-1<br>
<br>
do i=xs,xs+xm-1<br>
<br>
row(MatStencil_i) = i <br>
<br>
row(MatStencil_j) = j<br>
<br>
call ComputeRho(i,j,mx,my,centerRho,rho)<br>
<br>
if (i.eq.0 .or. j.eq.0 .or. i.eq.mx-1 .or. j.eq.my-1) then<br>
<br>
v(1) = 2.0*rho*(HxdHy + HydHx)<br>
<br>
call
MatSetValuesStencil(jac,i1,row,i1,row,v,INSERT_VALUES,ierr)<br>
<br>
else <br>
<br>
v(1) = -rho*HxdHy<br>
<br>
col(MatStencil_i,1) = i<br>
<br>
col(MatStencil_j,2) = j-1<br>
<br>
v(2) = -rho*HydHx<br>
<br>
col(MatStencil_i,2) = i-1 <br>
<br>
col(MatStencil_j,2) = j<br>
<br>
v(3) = 2.0*rho*(HxdHy + HydHx)<br>
<br>
col(MatStencil_i,3) = i <br>
<br>
col(MatStencil_j,3) = j<br>
<br>
v(4) = -rho*HydHx<br>
<br>
col(MatStencil_i,4) = i+1 <br>
<br>
col(MatStencil_j,4) = j <br>
<br>
v(5) = -rho*HxdHy<br>
<br>
col(MatStencil_i,5) = i <br>
<br>
col(MatStencil_j,5) = j+1<br>
<br>
call
MatSetValuesStencil(jac,i1,row,i5,col,v,INSERT_VALUES,ierr)<br>
<br>
end if<br>
<br>
end do<br>
<br>
end do<br>
<br>
call MatAssemblyBegin(jac,MAT_FINAL_ASSEMBLY,ierr)<br>
<br>
call MatAssemblyEnd(jac,MAT_FINAL_ASSEMBLY,ierr)<br>
<br>
!call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,nullspace,ierr)<br>
<br>
!call MatSetNullSpace(jac,nullspace,ierr)<br>
<br>
!call MatNullSpaceDestroy(nullspace,ierr)<br>
<br>
end subroutine ComputeMatrix<br>
<br>
subroutine ComputeRho(i,j,mx,my,centerRho,rho)<br>
<br>
PetscInt i,j,mx,my<br>
<br>
PetscScalar rho,centerRho<br>
<br>
if ((i > mx/3.0) .and. (i < 2.0*mx/3.0) .and. (j > my/3.0)
.and. (j < 2.0*my/3.0)) then<br>
<br>
rho = centerRho<br>
<br>
else<br>
<br>
rho = 1.0<br>
<br>
end if<br>
<br>
<br>
end subroutine ComputeRho<br>
<pre class="moz-signature" cols="72">--
Yours sincerely,
TAY wee-beng</pre>
</body>
</html>