static char help[] = "Test repeated LU factorizations. Used for checking memory leak\n\ -m : problem size\n\ -mat_nonsym : use nonsymmetric matrix (default is symmetric)\n\n"; #include "petscmat.h" #undef __FUNCT__ #define __FUNCT__ "main" int main(int argc,char **args) { Mat C,F; /* matrix */ Vec x,u,b; /* approx solution, RHS, exact solution */ PetscReal norm; /* norm of solution error */ PetscScalar v,none = -1.0; PetscInt I,J,ldim,low,high,iglobal,Istart,Iend; PetscErrorCode ierr; PetscInt i,j,m = 3,n = 2,its; PetscMPIInt size,rank; PetscTruth mat_nonsymmetric; PetscInt its_max; MatFactorInfo factinfo; IS perm,iperm; PetscInitialize(&argc,&args,(char *)0,help); ierr = PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);CHKERRQ(ierr); ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); n = 2*size; /* Set flag if we are doing a nonsymmetric problem; the default is symmetric. */ ierr = PetscOptionsHasName(PETSC_NULL,"-mat_nonsym",&mat_nonsymmetric);CHKERRQ(ierr); /* Create parallel matrix, specifying only its global dimensions. When using MatCreate(), the matrix format can be specified at runtime. Also, the parallel partitioning of the matrix is determined by PETSc at runtime. */ ierr = MatCreate(PETSC_COMM_WORLD,&C);CHKERRQ(ierr); ierr = MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n);CHKERRQ(ierr); ierr = MatSetFromOptions(C);CHKERRQ(ierr); ierr = MatGetOwnershipRange(C,&Istart,&Iend);CHKERRQ(ierr); /* Set matrix entries matrix in parallel. - Each processor needs to insert only elements that it owns locally (but any non-local elements will be sent to the appropriate processor during matrix assembly). - Always specify global row and columns of matrix entries. */ for (I=Istart; I0) {J = I - n; ierr = MatSetValues(C,1,&I,1,&J,&v,ADD_VALUES);CHKERRQ(ierr);} if (i0) {J = I - 1; ierr = MatSetValues(C,1,&I,1,&J,&v,ADD_VALUES);CHKERRQ(ierr);} if (j1) {J = I-n-1; ierr = MatSetValues(C,1,&I,1,&J,&v,ADD_VALUES);CHKERRQ(ierr);} } } else { ierr = MatSetOption(C,MAT_SYMMETRIC);CHKERRQ(ierr); ierr = MatSetOption(C,MAT_SYMMETRY_ETERNAL);CHKERRQ(ierr); } /* Assemble matrix, using the 2-step process: MatAssemblyBegin(), MatAssemblyEnd() Computations can be done while messages are in transition by placing code between these two statements. */ ierr = MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); ierr = MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); its_max=1000; /* Create parallel vectors. - When using VecSetSizes(), we specify only the vector's global dimension; the parallel partitioning is determined at runtime. - Note: We form 1 vector from scratch and then duplicate as needed. */ ierr = VecCreate(PETSC_COMM_WORLD,&u);CHKERRQ(ierr); ierr = VecSetSizes(u,PETSC_DECIDE,m*n);CHKERRQ(ierr); ierr = VecSetFromOptions(u);CHKERRQ(ierr); ierr = VecDuplicate(u,&b);CHKERRQ(ierr); ierr = VecDuplicate(b,&x);CHKERRQ(ierr); /* Currently, all parallel PETSc vectors are partitioned by contiguous chunks across the processors. Determine which range of entries are locally owned. */ ierr = VecGetOwnershipRange(x,&low,&high);CHKERRQ(ierr); /* Set elements within the exact solution vector in parallel. - Each processor needs to insert only elements that it owns locally (but any non-local entries will be sent to the appropriate processor during vector assembly). - Always specify global locations of vector entries. */ ierr = VecGetLocalSize(x,&ldim);CHKERRQ(ierr); for (i=0; i