Hello,<br><br>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 <a href="http://img824.imageshack.us/i/totog.jpg">http://img824.imageshack.us/i/totog.jpg</a> in case of). <br>
<br>I don't use any preconditionning and n=20.<br><br>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.<br>
<br>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 ? <br><br>Thanks a lot<br>
<br>Regards<br><br>PYA<br><br><br>Ps: i attached above the petsc error log, valgrind log and related code.<br><br>***************************<br> Error :<br>***************************<br><br>[3]PETSC ERROR: --------------------- Error Message ------------------------------------<br>
[3]PETSC ERROR: Arguments are incompatible!<br>[3]PETSC ERROR: Incompatible vector local lengths!<br>[3]PETSC ERROR: ------------------------------------------------------------------------<br>[3]PETSC ERROR: Petsc Release Version 3.1.0, Patch 8, Thu Mar 17 13:37:48 CDT 2011<br>
[3]PETSC ERROR: See docs/changes/index.html for recent updates.<br>[3]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>[3]PETSC ERROR: See docs/index.html for manual pages.<br>[3]PETSC ERROR: ------------------------------------------------------------------------<br>
[3]PETSC ERROR: ./hyperh on a linux-c-d named Tripel by perif Wed Jun 22 16:43:26 2011<br>[3]PETSC ERROR: Libraries linked from /home/perif/Utils/Libs/petsc-3.1-p8/linux-c-debug-real/lib<br>[3]PETSC ERROR: Configure run at Tue May 24 14:49:00 2011<br>
[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<br>[3]PETSC ERROR: ------------------------------------------------------------------------<br>
[3]PETSC ERROR: VecCopy() line 1694 in src/vec/vec/interface/vector.c<br>[3]PETSC ERROR: KSPSolve_LSQR() line 135 in src/ksp/ksp/impls/lsqr/lsqr.c<br>[3]PETSC ERROR: KSPSolve() line 396 in src/ksp/ksp/interface/itfunc.c<br>
[3]PETSC ERROR: User provided function() line 217 in precond.c<br><br><br><br>***************************<br> Code :<br>***************************<br><br>/*get factor matrix*/<br> MatCreateSeqDense(PETSC_COMM_WORLD,(*nb_eigen_all)+1,(*nb_eigen_all)+1,PETSC_NULL,&fact);<br>
MatSetFromOptions(fact); <br> MatAssemblyBegin(fact,MAT_FINAL_ASSEMBLY);<br> MatAssemblyEnd(fact,MAT_FINAL_ASSEMBLY);<br><br><br> <br> <br> /*Create the matrix operator that will be used in the QR factorization*/<br>
MatCreateSeqDense(PETSC_COMM_WORLD,(*nb_eigen)+1,(*nb_eigen),PETSC_NULL,&F);<br> MatSetFromOptions(F);<br> <br> <br> /* Set the matrix values */<br> ................................<br> <br> <br>
/*assemble F for processing*/<br> MatAssemblyBegin(F,MAT_FINAL_ASSEMBLY);<br> MatAssemblyEnd(F,MAT_FINAL_ASSEMBLY);<br><br> <br> /* set the vectors*/<br> ierr=VecCreate(PETSC_COMM_WORLD,&rhs);CHKERRQ(ierr);<br>
ierr=VecCreate(PETSC_COMM_WORLD,&soln);CHKERRQ(ierr);<br> ierr=VecSetSizes(rhs, PETSC_DECIDE, (*nb_eigen));CHKERRQ(ierr);<br> ierr=VecSetSizes(soln, PETSC_DECIDE, (*nb_eigen));CHKERRQ(ierr);<br> ierr=VecSetType(soln,VECSEQ);CHKERRQ(ierr);<br>
ierr=VecSetType(rhs,VECSEQ);CHKERRQ(ierr);<br> <br> /*set the solution to zero*/<br> ierr=VecSet(soln,(PetscScalar)0.0);CHKERRQ(ierr);<br> ierr=VecSet(rhs,(PetscScalar)0.0);CHKERRQ(ierr);<br> <br> /* rhs[0] must be setted to beta*/<br>
ierr=VecSetValue(rhs,0,(PetscReal)fact_tmp[0],INSERT_VALUES);CHKERRQ(ierr);<br><br> ierr = VecAssemblyBegin(soln);CHKERRQ(ierr);<br> ierr = VecAssemblyEnd(soln);CHKERRQ(ierr);<br> ierr = VecAssemblyBegin(rhs);CHKERRQ(ierr);<br>
ierr = VecAssemblyEnd(rhs);CHKERRQ(ierr);<br> <br><br><br> #ifdef DEBUG<br> PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_MATLAB );<br> MatView(F,PETSC_VIEWER_STDOUT_WORLD);<br> #endif<br>
<br> /*create the lsqr solver context and set it up*/<br> ierr=KSPCreate(PETSC_COMM_WORLD,&ksplsqr);CHKERRQ(ierr);<br> ierr=KSPSetOperators(ksplsqr,F,F,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);<br> ierr=KSPGetPC(ksplsqr,&pclsqr);CHKERRQ(ierr);<br>
ierr=PCSetType(pclsqr,PCNONE);CHKERRQ(ierr);<br> ierr=KSPSetType(ksplsqr,KSPLSQR);CHKERRQ(ierr);<br> ierr=KSPSetInitialGuessNonzero(ksplsqr,PETSC_TRUE);CHKERRQ(ierr);<br> ierr=KSPSetUp(ksplsqr);CHKERRQ(ierr);<br>
<br> <br> /* now we are ready to kick some ass and chew some bubble gum<br> unfortunately i'm all out of gum */<br> ierr = KSPSolve(ksplsqr, rhs, soln); CHKERRQ(ierr);<br><br>***************************<br>
Valgrind Error :<br>
***************************<br><br><br><br>==13892== Invalid read of size 8<br>==13892== at 0x678B76: VecAYPX_Seq (dvec2.c:667)<br>==13892== by 0x65B5DE: VecAYPX (rvector.c:692)<br>==13892== by 0x8636D3: KSPSolve_LSQR (lsqr.c:119)<br>
==13892== by 0x80B7C5: KSPSolve (itfunc.c:396)<br>==13892== by 0x4174B8: LSPrecond (precond.c:217)<br>==13892== by 0x414B1E: LSQR (lsqr.c:172)<br>==13892== by 0x407FCD: main (main.c:105)<br>==13892== Address 0x8f5f350 is 816 bytes inside a block of size 820 alloc'd<br>
==13892== at 0x4C27870: memalign (vg_replace_malloc.c:581)<br>==13892== by 0x5948FB: PetscMallocAlign (mal.c:30)<br>==13892== by 0x595DDD: PetscTrMallocDefault (mtr.c:192)<br>==13892== by 0x66AEEA: VecCreate_Seq (bvec2.c:823)<br>
==13892== by 0x650478: VecSetType (vecreg.c:54)<br>==13892== by 0x416EA4: LSPrecond (precond.c:179)<br>==13892== by 0x414B1E: LSQR (lsqr.c:172)<br>==13892== by 0x407FCD: main (main.c:105)<br>==13892== <br>==13892== Invalid read of size 8<br>
==13892== at 0x678B7A: VecAYPX_Seq (dvec2.c:667)<br>==13892== by 0x65B5DE: VecAYPX (rvector.c:692)<br>==13892== by 0x8636D3: KSPSolve_LSQR (lsqr.c:119)<br>==13892== by 0x80B7C5: KSPSolve (itfunc.c:396)<br>==13892== by 0x4174B8: LSPrecond (precond.c:217)<br>
==13892== by 0x414B1E: LSQR (lsqr.c:172)<br>==13892== by 0x407FCD: main (main.c:105)<br>==13892== Address 0x8f5f358 is 4 bytes after a block of size 820 alloc'd<br>==13892== at 0x4C27870: memalign (vg_replace_malloc.c:581)<br>
==13892== by 0x5948FB: PetscMallocAlign (mal.c:30)<br>==13892== by 0x595DDD: PetscTrMallocDefault (mtr.c:192)<br>==13892== by 0x66AEEA: VecCreate_Seq (bvec2.c:823)<br>==13892== by 0x650478: VecSetType (vecreg.c:54)<br>
==13892== by 0x416EA4: LSPrecond (precond.c:179)<br>==13892== by 0x414B1E: LSQR (lsqr.c:172)<br>==13892== by 0x407FCD: main (main.c:105)<br>==13892== <br><br>