<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
&nbsp; I sent two emails for replying thie topic. However, I didn't get the email of myself from <STRONG>petsc-users-bounces@mcs.anl.gov</STRONG>&nbsp;.&nbsp; I am wondering if the email system has something&nbsp;wrong?&nbsp;Sorry if the resent email bohters&nbsp;anyone.<BR>
&nbsp;<BR>
&nbsp;&nbsp;In the new version of the code I&nbsp;defined PetscInt II,JJ,ione, mone,snr[] and rnr[], PetscReal&nbsp;coef[],&nbsp;and modified the following portion. However, the error is still there. Is there any ohter reason I didn't figure out?<BR>
&nbsp;<BR>
&nbsp;<BR>&nbsp;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 loop=======<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;do I=Istart,Iend-1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mone=I+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II=snr(mone)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JJ=rnr(mone)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v=coef(mone)<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,II,ione,JJ,v,INSERT_VALUES,ierr)<BR>&nbsp;&nbsp;&nbsp; enddo&nbsp;<BR><BR>! ============the whole program code modified====================<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 I=Istart,Iend-1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mone=I+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II=snr(mone)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JJ=rnr(mone)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v=coef(mone)<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,II,ione,JJ,v,INSERT_VALUES,ierr)<BR>&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>
&nbsp;<BR>
!===================End of the code============================<BR><BR>&nbsp;<BR><BR>&nbsp;<BR><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>&gt; On Nov 30, 2010, at 10:33 PM, Peter Wang wrote:<BR>&gt; <BR>&gt; &gt; I am trying to create a matrix and insert values to it. The martix is supposed to be as following:<BR>&gt; &gt; <BR>&gt; &gt; 1 0 0 0<BR>&gt; &gt; 0 2 0 0<BR>&gt; &gt; 0 0 3 0<BR>&gt; &gt; 0 0 0 4<BR>&gt; &gt; <BR>&gt; &gt; array coef[] is the diagonal value of the matrix, <BR>&gt; &gt; snr[] is the index of the row, rnr[] is the index of column.<BR>&gt; &gt; <BR>&gt; &gt; However, I always get the wrong results. It shows the Column too large: col 4607182418800017408 max 3! I cheked the value of rnr[]. The output snr and rnr is correct:<BR>&gt; &gt; snr= 0 1 2 3<BR>&gt; &gt; rnr= 0 1 2 3<BR>&gt; &gt; <BR>&gt; &gt; It seems there is something wrong when MatSetValues() is called. Following is a part of the error information. The information is shown at each loop of do II=Istart,Iend-1<BR>&gt; &gt; <BR>&gt; &gt; The output (if any) follows:<BR>&gt; &gt; snr= 0 1 2 3<BR>&gt; &gt; rnr= 0 1 2 3<BR>&gt; &gt; 8.....Check after MatGetOwnershipRange() Istart= 0 Iend= 4<BR>&gt; &gt; II= 0 1 0 0<BR>&gt; &gt; [0]PETSC ERROR: --------------------- Error Message ------------------------------------<BR>&gt; &gt; [0]PETSC ERROR: Argument out of range!<BR>&gt; &gt; [0]PETSC ERROR: Column too large: col 4607182418800017408 max 3!<BR>&gt; &gt; [0]PETSC ERROR: ------------------------------------------------------------------------<BR>&gt; &gt; [0]PETSC ERROR: Petsc Release Version 3.1.0, Patch 5, Mon Sep 27 11:51:54 CDT 2010<BR>&gt; &gt; [0]PETSC ERROR: See docs/changes/index.html for recent updates.<BR>&gt; &gt; [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<BR>&gt; &gt; [0]PETSC ERROR: See docs/index.html for manual pages.<BR>&gt; &gt; [0]PETSC ERROR: ------------------------------------------------------------------------<BR>&gt; &gt; [0]PETSC ERROR: Debug_PETSc_MatCreate_20101130 on a linux-gnu named compute-1-35.hpc.local.uwm by pwang_a Tue Nov 30 22:27:03 2010<BR>&gt; &gt; [0]PETSC ERROR: Libraries linked from /sharedapps/uwm/ceas/gcc-4.4.3/petsc/3.1-p5-v1/lib<BR>&gt; &gt; [0]PETSC ERROR: Configure run at Fri Oct 8 12:59:16 2010<BR>&gt; &gt; [0]PETSC ERROR: Configure options --prefix=/sharedapps/uwm/ceas/gcc-4.4.3/petsc/3.1-p5-v1 --with-mpi-dir=/sharedapps/uwm/common/gcc-4.4.3/openmpi/1.3.2-v1 --with-blas-lapack-dir=/sharedapps/uwm/ceas/gcc-4.4.3/lapack/3.2.2-v1/lib --with-64-bit-indices=1 --with-64-bit-pointers=1 --with-large-file-io=1 --with-x=0<BR>&gt; &gt; [0]PETSC ERROR: ------------------------------------------------------------------------<BR>&gt; &gt; [0]PETSC ERROR: MatSetValues_SeqAIJ() line 193 in src/mat/impls/aij/seq/aij.c<BR>&gt; &gt; [0]PETSC ERROR: MatSetValues() line 992 in src/mat/interface/matrix.c<BR>&gt; &gt; <BR>&gt; &gt; <BR>&gt; &gt; <BR>&gt; &gt; !The code is as following:<BR>&gt; &gt; !=============================<BR>&gt; &gt; program Debug_PETSc_MatCreate_20101130<BR>&gt; &gt; implicit none<BR>&gt; &gt; !<BR>&gt; &gt; #include "finclude/petscsys.h"<BR>&gt; &gt; #include "finclude/petscvec.h"<BR>&gt; &gt; #include "finclude/petscmat.h"<BR>&gt; &gt; #include "finclude/petscpc.h"<BR>&gt; &gt; #include "finclude/petscksp.h"<BR>&gt; &gt; ! Variables<BR>&gt; &gt; !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>&gt; &gt; ! PETSc Variables<BR>&gt; &gt; !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>&gt; &gt; real*8 norm<BR>&gt; &gt; PetscInt i,j,II,JJ,its !,m,n<BR>&gt; &gt; PetscInt Istart,Iend,ione<BR>&gt; &gt; PetscErrorCode ierr<BR>&gt; &gt; PetscMPIInt myid,numprocs<BR>&gt; &gt; PetscTruth flg<BR>&gt; &gt; PetscScalar v,one,neg_one<BR>&gt; &gt; Vec x,b,u<BR>&gt; &gt; Mat A_petsc <BR>&gt; &gt; KSP ksp<BR>&gt; &gt; PetscInt,parameter:: n_nz=4<BR>&gt; &gt; !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>&gt; &gt; ! Other Variables<BR>&gt; &gt; !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>&gt; &gt; !parameter::n_nz=4<BR>&gt; &gt; Real*8::Coef(n_nz)<BR>&gt; &gt; PetscInt::snr(n_nz),rnr(n_nz)<BR>&gt; &gt; data Coef /1., 2., 3. , 4./<BR>&gt; &gt; data snr /0, 1, 2, 3/<BR>&gt; &gt; data rnr /0, 1 , 2, 3/<BR>&gt; &gt; ! Body of Debug_PETSc_MatCreate_20101130<BR>&gt; &gt; ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<BR>&gt; &gt; ! Beginning of program<BR>&gt; &gt; ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <BR>&gt; &gt; call PetscInitialize(PETSC_NULL_CHARACTER,ierr)<BR>&gt; &gt; call MPI_Comm_rank(PETSC_COMM_WORLD,myid,ierr)<BR>&gt; &gt; call MPI_Comm_size(PETSC_COMM_WORLD,numprocs,ierr)<BR>&gt; &gt; write(*,"('snr=',4i4)")snr <BR>&gt; &gt; write(*,"('rnr=',4i4)")rnr <BR>&gt; &gt; call MatCreate(PETSC_COMM_WORLD,A_Petsc,ierr)<BR>&gt; &gt; call MatSetSizes(A_Petsc,PETSC_DECIDE,PETSC_DECIDE,n_nz,n_nz,ierr) !n_nz-1???<BR>&gt; &gt; call MatSetFromOptions(A_Petsc,ierr)<BR>&gt; &gt; ! write(*,*)A_petsc<BR>&gt; &gt; call MatGetOwnershipRange(A_Petsc,Istart,Iend,ierr)<BR>&gt; &gt; <BR>&gt; &gt; write(*,'(1a,1i7,1a,1i7)') &amp;<BR>&gt; &gt; '8.....Check after MatGetOwnershipRange() Istart=',Istart,' Iend=',Iend<BR>&gt; &gt; do II=Istart,Iend-1<BR>&gt; &gt; ione=II+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR>&gt; &gt; write(*,'(1a,4i7)')'II=',II,ione,snr(ione),rnr(ione) !output snr and rnr for error check<BR>&gt; &gt; call MatSetValues(A_Petsc,1,snr(Ione),1,rnr(Ione),Coef(Ione),INSERT_VALUES,ierr)<BR>&gt; &gt; enddo <BR>&gt; &gt; <BR>&gt; &gt; write(*,'(1a)')'9.....Check after MatSetValues()'<BR>&gt; &gt; call MatAssemblyBegin(A_petsc,MAT_FINAL_ASSEMBLY,ierr)<BR>&gt; &gt; call MatAssemblyEnd(A_Petsc,MAT_FINAL_ASSEMBLY,ierr)<BR>&gt; &gt; write(*,'(1a)')'10.....Check after MatCreate()'<BR>&gt; &gt; call MatView(A_Petsc,PETSC_VIEWER_STDOUT_WORLD,ierr)<BR>&gt; &gt; ! call KSPDestroy(ksp,ierr)<BR>&gt; &gt; ! call VecDestroy(u,ierr)<BR>&gt; &gt; ! call VecDestroy(x,ierr)<BR>&gt; &gt; ! call VecDestroy(b,ierr)<BR>&gt; &gt; call MatDestroy(A_petsc,ierr)<BR>&gt; &gt; call PetscFinalize(ierr)<BR>&gt; &gt; end program Debug_PETSc_MatCreate_20101130<BR>&gt; &gt; !=====================================<BR>&gt; <BR>                                               </body>
</html>