<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
<BR>
<META content="Microsoft SafeHTML" name=Generator>
<STYLE>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}
</STYLE>
Thanks,<BR> <BR> I changed the '1' to PetscInt ione, However, the error still comes out.<BR> <BR> do II=Istart,Iend-1<BR> mone=II+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR> write(*,'(1a,4i7)')'II=',II,mone,snr(mone),rnr(mone)<BR> call MatSetValues(A_Petsc,ione,snr(mone),ione,rnr(mone),Coef(mone),INSERT_VALUES,ierr) ! PetscInt ione and mone; PetscInt snr(n_nz),rnr(n_nz) PetscReal Coef(n_nz)<BR> ^^ ^^^<BR> enddo <BR><BR> <BR>BTW, I am running the code on the clusters of supurcomputer. Where the option ' --with-64-bit-indices=1' shold I find and remove? <BR> <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>! PETSc Variables<BR>!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR> real*8 norm<BR> PetscInt i,j,II,JJ,its !,m,n<BR> PetscInt Istart,Iend,ione,mone<BR> PetscErrorCode ierr<BR> PetscMPIInt myid,numprocs<BR> PetscTruth flg<BR> PetscScalar v,one,neg_one<BR> Vec x,b,u<BR> Mat A_petsc <BR> KSP ksp<BR> PetscInt,parameter::n_nz=4<BR>!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>! 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., 2., 3. , 4./<BR>data snr /0, 1, 2, 3/<BR>data rnr /0, 1 , 2, 3/<BR>! Body of Debug_PETSc_MatCreate_20101130<BR>! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<BR>! Beginning of program<BR>! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR> call PetscInitialize(PETSC_NULL_CHARACTER,ierr)<BR> call MPI_Comm_rank(PETSC_COMM_WORLD,myid,ierr)<BR> call MPI_Comm_size(PETSC_COMM_WORLD,numprocs,ierr)<BR> write(*,"('snr=',4i4)")snr <BR> write(*,"('rnr=',4i4)")rnr <BR> call MatCreate(PETSC_COMM_WORLD,A_Petsc,ierr)<BR> call MatSetSizes(A_Petsc,PETSC_DECIDE,PETSC_DECIDE,n_nz,n_nz,ierr) !n_nz-1???<BR> call MatSetFromOptions(A_Petsc,ierr)<BR> ! write(*,*)A_petsc<BR> call MatGetOwnershipRange(A_Petsc,Istart,Iend,ierr)<BR> <BR> write(*,'(1a,1i7,1a,1i7)') &<BR> '8.....Check after MatGetOwnershipRange() Istart=',Istart,' Iend=',Iend<BR> do II=Istart,Iend-1<BR><FONT style="BACKGROUND-COLOR: #ff0000"> mone=II+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR> write(*,'(1a,4i7)')'II=',II,mone,snr(mone),rnr(mone)<BR> call MatSetValues(A_Petsc,ione,snr(mone),ione,rnr(mone),Coef(mone),INSERT_VALUES,ierr)<BR></FONT> enddo <BR> <BR> write(*,'(1a)')'9.....Check after MatSetValues()'<BR> call MatAssemblyBegin(A_petsc,MAT_FINAL_ASSEMBLY,ierr)<BR> call MatAssemblyEnd(A_Petsc,MAT_FINAL_ASSEMBLY,ierr)<BR> write(*,'(1a)')'10.....Check after MatCreate()'<BR> call MatView(A_Petsc,PETSC_VIEWER_STDOUT_WORLD,ierr)<BR>! call KSPDestroy(ksp,ierr)<BR>! call VecDestroy(u,ierr)<BR>! call VecDestroy(x,ierr)<BR>! call VecDestroy(b,ierr)<BR> call MatDestroy(A_petsc,ierr)<BR> call PetscFinalize(ierr)<BR>end program Debug_PETSc_MatCreate_20101130<BR><BR> <BR>> From: bsmith@mcs.anl.gov<BR>> Date: Wed, 1 Dec 2010 08:06:19 -0600<BR>> To: petsc-users@mcs.anl.gov<BR>> Subject: Re: [petsc-users] column index in MatSetValues()<BR>> <BR>> <BR>> <BR>> --with-64-bit-indices=1<BR>> <BR>> 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>> <BR>> > MatSetValues(A_Petsc,1,snr(Ione),1,rnr(Ione),Coef(Ione)<BR>> ^^^^ ^^^^^<BR>> <BR>> --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>> <BR>> PetscInt mone<BR>> mone = 1<BR>> > MatSetValues(A_Petsc,mone,snr(Ione),mone,rnr(Ione),Coef(Ione)<BR>> <BR>> but better just build PETSc without the --with-64-bit-indices<BR>> <BR>> Barry<BR>> <BR>> <BR><BR>                                            </body>
</html>