<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
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> . I am wondering if the email system has something wrong? Sorry if the resent email bohters anyone.<BR>
<BR>
In the new version of the code I defined PetscInt II,JJ,ione, mone,snr[] and rnr[], PetscReal coef[], and modified the following portion. However, the error is still there. Is there any ohter reason I didn't figure out?<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 loop=======<BR> <BR>
do I=Istart,Iend-1<BR> mone=I+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR> II=snr(mone)<BR> JJ=rnr(mone)<BR> v=coef(mone)<BR> write(*,'(1a,4i7)')'II=',II,mone,snr(mone),rnr(mone)<BR> call MatSetValues(A_Petsc,ione,II,ione,JJ,v,INSERT_VALUES,ierr)<BR> enddo <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>! 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 I=Istart,Iend-1<BR> mone=I+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR> II=snr(mone)<BR> JJ=rnr(mone)<BR> v=coef(mone)<BR> write(*,'(1a,4i7)')'II=',II,mone,snr(mone),rnr(mone)<BR> call MatSetValues(A_Petsc,ione,II,ione,JJ,v,INSERT_VALUES,ierr)<BR> 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>
!===================End of the code============================<BR><BR> <BR><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>> On Nov 30, 2010, at 10:33 PM, Peter Wang wrote:<BR>> <BR>> > I am trying to create a matrix and insert values to it. The martix is supposed to be as following:<BR>> > <BR>> > 1 0 0 0<BR>> > 0 2 0 0<BR>> > 0 0 3 0<BR>> > 0 0 0 4<BR>> > <BR>> > array coef[] is the diagonal value of the matrix, <BR>> > snr[] is the index of the row, rnr[] is the index of column.<BR>> > <BR>> > 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>> > snr= 0 1 2 3<BR>> > rnr= 0 1 2 3<BR>> > <BR>> > 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>> > <BR>> > The output (if any) follows:<BR>> > snr= 0 1 2 3<BR>> > rnr= 0 1 2 3<BR>> > 8.....Check after MatGetOwnershipRange() Istart= 0 Iend= 4<BR>> > II= 0 1 0 0<BR>> > [0]PETSC ERROR: --------------------- Error Message ------------------------------------<BR>> > [0]PETSC ERROR: Argument out of range!<BR>> > [0]PETSC ERROR: Column too large: col 4607182418800017408 max 3!<BR>> > [0]PETSC ERROR: ------------------------------------------------------------------------<BR>> > [0]PETSC ERROR: Petsc Release Version 3.1.0, Patch 5, Mon Sep 27 11:51:54 CDT 2010<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>> > [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>> > [0]PETSC ERROR: Libraries linked from /sharedapps/uwm/ceas/gcc-4.4.3/petsc/3.1-p5-v1/lib<BR>> > [0]PETSC ERROR: Configure run at Fri Oct 8 12:59:16 2010<BR>> > [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>> > [0]PETSC ERROR: ------------------------------------------------------------------------<BR>> > [0]PETSC ERROR: MatSetValues_SeqAIJ() line 193 in src/mat/impls/aij/seq/aij.c<BR>> > [0]PETSC ERROR: MatSetValues() line 992 in src/mat/interface/matrix.c<BR>> > <BR>> > <BR>> > <BR>> > !The code is as following:<BR>> > !=============================<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<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>> > !parameter::n_nz=4<BR>> > Real*8::Coef(n_nz)<BR>> > PetscInt::snr(n_nz),rnr(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>> > ione=II+1 !(Coef,snr,rnr are 1-based row and column numbers, shifting them to 0-based)<BR>> > write(*,'(1a,4i7)')'II=',II,ione,snr(ione),rnr(ione) !output snr and rnr for error check<BR>> > call MatSetValues(A_Petsc,1,snr(Ione),1,rnr(Ione),Coef(Ione),INSERT_VALUES,ierr)<BR>> > 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>                                            </body>
</html>