[petsc-users] KSPLSQR Incompatible vector local lengths

Pierre-Yves Aquilanti sperif at gmail.com
Wed Jun 22 10:44:03 CDT 2011


Hello,

i'm trying to use the KSPLSQR solver in order to solve the Ax=b where b and
x are of size "n" and matrix A is of size "n+1 x n". A is in fact a superior
hessenberg matrix (i upload a figure at
http://img824.imageshack.us/i/totog.jpg in case of).

I don't use any preconditionning and n=20.

Also, to understand where the program was crashing, i runned Valgrind which
tells me that the error is related to a VecCopy operation withing the
KSPSolve_LSQR. I checked the vectors and matrix size, but it doesn't seem to
come from the sizes. Also, i'm using sequential matrix and vectors.

However, despite my search, i  am not able to make the solver work as
intended, it return a "Incompatible vector local lengths!" error. Do you
have any idea on what would be my mistake ?

Thanks a lot

Regards

PYA


Ps: i attached above the petsc error log, valgrind log and related code.

***************************
             Error :
***************************

[3]PETSC ERROR: --------------------- Error Message
------------------------------------
[3]PETSC ERROR: Arguments are incompatible!
[3]PETSC ERROR: Incompatible vector local lengths!
[3]PETSC ERROR:
------------------------------------------------------------------------
[3]PETSC ERROR: Petsc Release Version 3.1.0, Patch 8, Thu Mar 17 13:37:48
CDT 2011
[3]PETSC ERROR: See docs/changes/index.html for recent updates.
[3]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
[3]PETSC ERROR: See docs/index.html for manual pages.
[3]PETSC ERROR:
------------------------------------------------------------------------
[3]PETSC ERROR: ./hyperh on a linux-c-d named Tripel by perif Wed Jun 22
16:43:26 2011
[3]PETSC ERROR: Libraries linked from
/home/perif/Utils/Libs/petsc-3.1-p8/linux-c-debug-real/lib
[3]PETSC ERROR: Configure run at Tue May 24 14:49:00 2011
[3]PETSC ERROR: Configure options --download-c-blas-lapack=yes
--with-scalar-type=complex --with-fortran=0 --with-debugging=yes
--with-shared=0 --with-petsc-arch=linux-c-debug-real
[3]PETSC ERROR:
------------------------------------------------------------------------
[3]PETSC ERROR: VecCopy() line 1694 in src/vec/vec/interface/vector.c
[3]PETSC ERROR: KSPSolve_LSQR() line 135 in src/ksp/ksp/impls/lsqr/lsqr.c
[3]PETSC ERROR: KSPSolve() line 396 in src/ksp/ksp/interface/itfunc.c
[3]PETSC ERROR: User provided function() line 217 in precond.c



***************************
             Code :
***************************

/*get factor matrix*/

MatCreateSeqDense(PETSC_COMM_WORLD,(*nb_eigen_all)+1,(*nb_eigen_all)+1,PETSC_NULL,&fact);
    MatSetFromOptions(fact);
    MatAssemblyBegin(fact,MAT_FINAL_ASSEMBLY);
    MatAssemblyEnd(fact,MAT_FINAL_ASSEMBLY);




    /*Create the matrix operator that will be used in the QR factorization*/

MatCreateSeqDense(PETSC_COMM_WORLD,(*nb_eigen)+1,(*nb_eigen),PETSC_NULL,&F);
    MatSetFromOptions(F);


   /* Set the matrix values */
   ................................


    /*assemble F for processing*/
    MatAssemblyBegin(F,MAT_FINAL_ASSEMBLY);
    MatAssemblyEnd(F,MAT_FINAL_ASSEMBLY);


    /* set the vectors*/
    ierr=VecCreate(PETSC_COMM_WORLD,&rhs);CHKERRQ(ierr);
    ierr=VecCreate(PETSC_COMM_WORLD,&soln);CHKERRQ(ierr);
    ierr=VecSetSizes(rhs, PETSC_DECIDE, (*nb_eigen));CHKERRQ(ierr);
    ierr=VecSetSizes(soln, PETSC_DECIDE, (*nb_eigen));CHKERRQ(ierr);
    ierr=VecSetType(soln,VECSEQ);CHKERRQ(ierr);
     ierr=VecSetType(rhs,VECSEQ);CHKERRQ(ierr);

    /*set the solution to zero*/
    ierr=VecSet(soln,(PetscScalar)0.0);CHKERRQ(ierr);
     ierr=VecSet(rhs,(PetscScalar)0.0);CHKERRQ(ierr);

    /* rhs[0] must be setted to beta*/

ierr=VecSetValue(rhs,0,(PetscReal)fact_tmp[0],INSERT_VALUES);CHKERRQ(ierr);

    ierr = VecAssemblyBegin(soln);CHKERRQ(ierr);
    ierr = VecAssemblyEnd(soln);CHKERRQ(ierr);
    ierr = VecAssemblyBegin(rhs);CHKERRQ(ierr);
    ierr = VecAssemblyEnd(rhs);CHKERRQ(ierr);



    #ifdef DEBUG

PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_MATLAB );
     MatView(F,PETSC_VIEWER_STDOUT_WORLD);
    #endif

    /*create the lsqr solver context and set it up*/
    ierr=KSPCreate(PETSC_COMM_WORLD,&ksplsqr);CHKERRQ(ierr);

ierr=KSPSetOperators(ksplsqr,F,F,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
    ierr=KSPGetPC(ksplsqr,&pclsqr);CHKERRQ(ierr);
    ierr=PCSetType(pclsqr,PCNONE);CHKERRQ(ierr);
    ierr=KSPSetType(ksplsqr,KSPLSQR);CHKERRQ(ierr);
    ierr=KSPSetInitialGuessNonzero(ksplsqr,PETSC_TRUE);CHKERRQ(ierr);
    ierr=KSPSetUp(ksplsqr);CHKERRQ(ierr);


    /* now we are ready to kick some ass and chew some bubble gum
       unfortunately i'm all out of gum */
    ierr = KSPSolve(ksplsqr, rhs, soln); CHKERRQ(ierr);

***************************
         Valgrind Error :
***************************



==13892== Invalid read of size 8
==13892==    at 0x678B76: VecAYPX_Seq (dvec2.c:667)
==13892==    by 0x65B5DE: VecAYPX (rvector.c:692)
==13892==    by 0x8636D3: KSPSolve_LSQR (lsqr.c:119)
==13892==    by 0x80B7C5: KSPSolve (itfunc.c:396)
==13892==    by 0x4174B8: LSPrecond (precond.c:217)
==13892==    by 0x414B1E: LSQR (lsqr.c:172)
==13892==    by 0x407FCD: main (main.c:105)
==13892==  Address 0x8f5f350 is 816 bytes inside a block of size 820 alloc'd
==13892==    at 0x4C27870: memalign (vg_replace_malloc.c:581)
==13892==    by 0x5948FB: PetscMallocAlign (mal.c:30)
==13892==    by 0x595DDD: PetscTrMallocDefault (mtr.c:192)
==13892==    by 0x66AEEA: VecCreate_Seq (bvec2.c:823)
==13892==    by 0x650478: VecSetType (vecreg.c:54)
==13892==    by 0x416EA4: LSPrecond (precond.c:179)
==13892==    by 0x414B1E: LSQR (lsqr.c:172)
==13892==    by 0x407FCD: main (main.c:105)
==13892==
==13892== Invalid read of size 8
==13892==    at 0x678B7A: VecAYPX_Seq (dvec2.c:667)
==13892==    by 0x65B5DE: VecAYPX (rvector.c:692)
==13892==    by 0x8636D3: KSPSolve_LSQR (lsqr.c:119)
==13892==    by 0x80B7C5: KSPSolve (itfunc.c:396)
==13892==    by 0x4174B8: LSPrecond (precond.c:217)
==13892==    by 0x414B1E: LSQR (lsqr.c:172)
==13892==    by 0x407FCD: main (main.c:105)
==13892==  Address 0x8f5f358 is 4 bytes after a block of size 820 alloc'd
==13892==    at 0x4C27870: memalign (vg_replace_malloc.c:581)
==13892==    by 0x5948FB: PetscMallocAlign (mal.c:30)
==13892==    by 0x595DDD: PetscTrMallocDefault (mtr.c:192)
==13892==    by 0x66AEEA: VecCreate_Seq (bvec2.c:823)
==13892==    by 0x650478: VecSetType (vecreg.c:54)
==13892==    by 0x416EA4: LSPrecond (precond.c:179)
==13892==    by 0x414B1E: LSQR (lsqr.c:172)
==13892==    by 0x407FCD: main (main.c:105)
==13892==
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110622/04b0974d/attachment-0001.htm>


More information about the petsc-users mailing list