<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Thanks,<BR>
&nbsp;<BR>
&nbsp;I&nbsp;changed the '1' to PetscInt ione, However, the error still comes out.<BR>
&nbsp;<BR>
&nbsp;do II=Istart,Iend-1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mone=II+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(*,'(1a,4i7)')'II=',II,mone,snr(mone),rnr(mone)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call MatSetValues(A_Petsc,ione,snr(mone),ione,rnr(mone),Coef(mone),INSERT_VALUES,ierr)&nbsp; ! PetscInt&nbsp; ione and mone; PetscInt snr(n_nz),rnr(n_nz) PetscReal Coef(n_nz)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^^&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^^^<BR>&nbsp;&nbsp;&nbsp; enddo <BR><BR>
&nbsp;<BR>
BTW, I am running the code on&nbsp;the&nbsp;clusters&nbsp;of&nbsp;supurcomputer.&nbsp;Where the option &nbsp;'&nbsp;--with-64-bit-indices=1' shold I find and remove?&nbsp;<BR>
&nbsp;<BR>
!===The modified code is ==<BR>
program Debug_PETSc_MatCreate_20101130<BR>
implicit none<BR>!<BR>#include "finclude/petscsys.h"<BR>#include "finclude/petscvec.h"<BR>#include "finclude/petscmat.h"<BR>#include "finclude/petscpc.h"<BR>#include "finclude/petscksp.h"<BR>! Variables<BR>!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>!&nbsp; PETSc Variables<BR>!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; real*8&nbsp; norm<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscInt&nbsp; i,j,II,JJ,its&nbsp;&nbsp; !,m,n<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscInt&nbsp; Istart,Iend,ione,mone<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscErrorCode ierr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscMPIInt&nbsp;&nbsp;&nbsp;&nbsp; myid,numprocs<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscTruth&nbsp; flg<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscScalar v,one,neg_one<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Vec&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x,b,u<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mat&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A_petsc <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KSP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ksp<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PetscInt,parameter::n_nz=4<BR>!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>!&nbsp; Other Variables<BR>!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>PetscInt::snr(n_nz),rnr(n_nz)<BR>!parameter::n_nz=4<BR>PetscReal::Coef(n_nz)<BR>data Coef /1.,&nbsp;&nbsp; 2.,&nbsp;&nbsp;&nbsp; 3. ,&nbsp; 4./<BR>data snr&nbsp; /0,&nbsp;&nbsp;&nbsp; 1,&nbsp;&nbsp;&nbsp;&nbsp; 2,&nbsp;&nbsp;&nbsp; 3/<BR>data rnr&nbsp; /0,&nbsp;&nbsp;&nbsp; 1 ,&nbsp;&nbsp;&nbsp; 2,&nbsp;&nbsp;&nbsp; 3/<BR>
! Body of Debug_PETSc_MatCreate_20101130<BR>
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<BR>!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Beginning of program<BR>! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>&nbsp;&nbsp;&nbsp; call PetscInitialize(PETSC_NULL_CHARACTER,ierr)<BR>&nbsp;&nbsp;&nbsp; call MPI_Comm_rank(PETSC_COMM_WORLD,myid,ierr)<BR>&nbsp;&nbsp;&nbsp; call MPI_Comm_size(PETSC_COMM_WORLD,numprocs,ierr)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(*,"('snr=',4i4)")snr&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(*,"('rnr=',4i4)")rnr&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; call MatCreate(PETSC_COMM_WORLD,A_Petsc,ierr)<BR>&nbsp;&nbsp;&nbsp; call MatSetSizes(A_Petsc,PETSC_DECIDE,PETSC_DECIDE,n_nz,n_nz,ierr)&nbsp;&nbsp;&nbsp; !n_nz-1???<BR>&nbsp;&nbsp;&nbsp; call MatSetFromOptions(A_Petsc,ierr)<BR>
&nbsp;&nbsp;&nbsp; !&nbsp;&nbsp;&nbsp; write(*,*)A_petsc<BR>&nbsp;&nbsp;&nbsp; call MatGetOwnershipRange(A_Petsc,Istart,Iend,ierr)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; write(*,'(1a,1i7,1a,1i7)')&nbsp; &amp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '8.....Check after MatGetOwnershipRange() Istart=',Istart,'&nbsp; Iend=',Iend<BR>
&nbsp;&nbsp;&nbsp; do II=Istart,Iend-1<BR><FONT style="BACKGROUND-COLOR: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mone=II+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(*,'(1a,4i7)')'II=',II,mone,snr(mone),rnr(mone)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call MatSetValues(A_Petsc,ione,snr(mone),ione,rnr(mone),Coef(mone),INSERT_VALUES,ierr)<BR></FONT>&nbsp;&nbsp;&nbsp; enddo <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(*,'(1a)')'9.....Check after MatSetValues()'<BR>&nbsp;&nbsp;&nbsp; call MatAssemblyBegin(A_petsc,MAT_FINAL_ASSEMBLY,ierr)<BR>&nbsp;&nbsp;&nbsp; call MatAssemblyEnd(A_Petsc,MAT_FINAL_ASSEMBLY,ierr)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(*,'(1a)')'10.....Check after MatCreate()'<BR>&nbsp;&nbsp;&nbsp; call MatView(A_Petsc,PETSC_VIEWER_STDOUT_WORLD,ierr)<BR>
!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call KSPDestroy(ksp,ierr)<BR>!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecDestroy(u,ierr)<BR>!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecDestroy(x,ierr)<BR>!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call VecDestroy(b,ierr)<BR>&nbsp;&nbsp;&nbsp; call MatDestroy(A_petsc,ierr)<BR>
&nbsp;&nbsp;&nbsp; call PetscFinalize(ierr)<BR>end program Debug_PETSc_MatCreate_20101130<BR><BR>&nbsp;<BR>
&gt; From: bsmith@mcs.anl.gov<BR>&gt; Date: Wed, 1 Dec 2010 08:06:19 -0600<BR>&gt; To: petsc-users@mcs.anl.gov<BR>&gt; Subject: Re: [petsc-users] column index in MatSetValues()<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; --with-64-bit-indices=1<BR>&gt; <BR>&gt; You only need this option if you are solving problems with over 2 billion unknowns! I recommend removing it otherwise, it wastes memory and slows performance slightly.<BR>&gt; <BR>&gt; &gt; MatSetValues(A_Petsc,1,snr(Ione),1,rnr(Ione),Coef(Ione)<BR>&gt; ^^^^ ^^^^^<BR>&gt; <BR>&gt; --with-64-bit-indices means ALL integers passed to PETSc MUST be 64 bit, but here you are passing the integer 1 as a "regular" 32 bit integer. You need to declare it as a PetscInt, for example<BR>&gt; <BR>&gt; PetscInt mone<BR>&gt; mone = 1<BR>&gt; &gt; MatSetValues(A_Petsc,mone,snr(Ione),mone,rnr(Ione),Coef(Ione)<BR>&gt; <BR>&gt; but better just build PETSc without the --with-64-bit-indices<BR>&gt; <BR>&gt; Barry<BR>&gt; <BR>&gt; <BR>                                               </body>
</html>