Hello,

I am trying to solve a system whose matrix is of type MatNest. If I don't use KSPSetUp(), everything is fine. However, if I use that routine, I get the following error:

0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[0]PETSC ERROR: Invalid argument
[0]PETSC ERROR: Nest vector arguments 1 and 2 have different numbers of blocks. [0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.11.0, unknown
[0]PETSC ERROR: /home/manu/Documents/FEM-fluids/C-codes/CLG2-ConvectionDiffusion/Debug/CLG2-ConvectionDiffusion on a mcr_20190405 named mancolric by Unknown Wed Apr 10 17:20:16 2019 [0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran COPTFLAGS="-O3 -march=native -mtune=native" CXXOPTFLAGS="-O3 -march=native -mtune=native" FOPTFLAGS="-O3 -march=native -mtune=native" --with-debugging=0 --download-fblaslapack --download--f2cblaslapack --download-mpich --download--hypre --download-scalapack --download-mumps --download-suitesparse --download-ptscotch --download-pastix --with-matlab --with-openmp [0]PETSC ERROR: #1 VecCopy_Nest() line 68 in /opt/PETSc_library/petsc-3.11.0/src/vec/vec/impls/nest/vecnest.c [0]PETSC ERROR: #2 VecCopy() line 1614 in /opt/PETSc_library/petsc-3.11.0/src/vec/vec/interface/vector.c [0]PETSC ERROR: #3 KSPInitialResidual() line 63 in /opt/PETSc_library/petsc-3.11.0/src/ksp/ksp/interface/itres.c [0]PETSC ERROR: #4 KSPSolve_GMRES() line 236 in /opt/PETSc_library/petsc-3.11.0/src/ksp/ksp/impls/gmres/gmres.c [0]PETSC ERROR: #5 KSPSolve() line 782 in /opt/PETSc_library/petsc-3.11.0/src/ksp/ksp/interface/itfunc.c
[0]PETSC ERROR: #6 mwe() line 55 in ../Tests/tests.c

Please find attached a MWE (it is a slight modification of that of the post opened by Ce Qin, https://lists.mcs.anl.gov/pipermail/petsc-users/2015-February/024230.html, whose answer I have not found).

By the way, with the newest version of PETSc, Eclipse marks as errors the commands PetscFree, CHKERRQ, PETSC_COMM_SELF,... although it compiles and executes well. Perhaps it is a problem related to Eclipse, but this did not happen with the older versions of PETSc.

Thanks and regards,

Manuel

---

#include <petscmat.h>
#include <petscvec.h>
#include <petscksp.h>

int mwe(int argc, char** argv) {

  Mat A00, A11, A;
  Vec b1, b2, x1, x2, b, x;
  PetscErrorCode ierr;

  char petsc_opts[] 	= "-ksp_monitor -pc_type fieldsplit -pc_fieldsplit_type symmetric_multiplicative "
			"-fieldsplit_0_pc_type icc -fieldsplit_0_ksp_type cg -fieldsplit_0_ksp_rtol 1e-10 -fieldsplit_0_ksp_atol 1e-15 -fieldsplit_0_ksp_max_it 10000 "
			"-fieldsplit_1_pc_type cholesky -fieldsplit_1_ksp_type preonly";

  PetscInitialize(&argc, &argv, 0, 0);

  //Create vectors:
  ierr = VecCreateSeq(PETSC_COMM_SELF, 10, &b1); CHKERRQ(ierr);
  ierr = VecDuplicate(b1, &b2); CHKERRQ(ierr);
  ierr = VecDuplicate(b1, &x1); CHKERRQ(ierr);
  ierr = VecDuplicate(b1, &x2); CHKERRQ(ierr);
  ierr = VecSet(b1, 1.0); CHKERRQ(ierr);
  ierr = VecSet(b2, 1.0); CHKERRQ(ierr);
  ierr = VecSet(x1, 0.0); CHKERRQ(ierr);
  ierr = VecSet(x2, 0.0); CHKERRQ(ierr);

  //Create matrices A00, A11:
  ierr = MatCreateSeqAIJ(PETSC_COMM_SELF, 10, 10, 1, PETSC_NULL, &A00); CHKERRQ(ierr);
  ierr = MatDiagonalSet(A00, b1, INSERT_VALUES); CHKERRQ(ierr);
  ierr = MatCreateSeqAIJ(PETSC_COMM_SELF, 10, 10, 1, PETSC_NULL, &A11); CHKERRQ(ierr);
  ierr = MatDiagonalSet(A11, b1, INSERT_VALUES); CHKERRQ(ierr);

  //Create nested matrix and vector:
  Mat mata[] = {A00, NULL, NULL, A11};
  ierr = MatCreateNest(PETSC_COMM_SELF, 2, NULL, 2, NULL, mata, &A); CHKERRQ(ierr);
  Vec vecx[] = {x1, x2};
  ierr = VecCreateNest(PETSC_COMM_SELF, 2, NULL, vecx, &x); CHKERRQ(ierr);
  Vec vecb[] = {b1, b2};
  ierr = VecCreateNest(PETSC_COMM_SELF, 2, NULL, vecb, &b); CHKERRQ(ierr);

  //Solve:
  KSP ksp;
  PC pc;
  ierr = KSPCreate(PETSC_COMM_SELF, &ksp); CHKERRQ(ierr);
  ierr = KSPGetPC(ksp,&pc); 	CHKERRQ(ierr);
  ierr = KSPSetOperators(ksp, A, A); CHKERRQ(ierr);
  ierr = PetscOptionsClear(NULL);
  ierr = PetscOptionsInsertString(NULL,petsc_opts); 	CHKERRQ(ierr);
  ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr);
  IS* ISv 	= calloc(2,sizeof(IS));
  ierr = MatNestGetISs(A,ISv,NULL); CHKERRQ(ierr);
  ierr = PCFieldSplitSetIS(pc,"0",ISv[0]); CHKERRQ(ierr);
  ierr = PCFieldSplitSetIS(pc,"1",ISv[1]); CHKERRQ(ierr);
  ierr = KSPSetUp(ksp); CHKERRQ(ierr); // this line causes an error
  ierr = KSPSolve(ksp, b, x); CHKERRQ(ierr);

  //Free memory:
  ierr = KSPDestroy(&ksp); CHKERRQ(ierr);
  ierr = MatDestroy(&A); 	CHKERRQ(ierr);
  ierr = MatDestroy(&A00); 	CHKERRQ(ierr);
  ierr = MatDestroy(&A11); 	CHKERRQ(ierr);
  ierr = VecDestroy(&b); 	CHKERRQ(ierr);
  ierr = VecDestroy(&b1); 	CHKERRQ(ierr);
  ierr = VecDestroy(&b2); 	CHKERRQ(ierr);
  ierr = VecDestroy(&x); 	CHKERRQ(ierr);
  ierr = VecDestroy(&x1); 	CHKERRQ(ierr);
  ierr = VecDestroy(&x2); 	CHKERRQ(ierr);
  free(ISv);
  PetscFinalize();

  return 0;

}

Reply via email to