1 2 static char help[] = "Tests copying and ordering uniprocessor row-based sparse matrices.\n\n"; 3 4 #include <petscmat.h> 5 6 int main(int argc,char **args) 7 { 8 Mat C,A; 9 PetscInt i,j,m = 5,n = 5,Ii,J; 10 PetscScalar v; 11 IS perm,iperm; 12 13 PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); 14 PetscCall(MatCreateSeqAIJ(PETSC_COMM_SELF,m*n,m*n,5,NULL,&C)); 15 /* create the matrix for the five point stencil, YET AGAIN*/ 16 for (i=0; i<m; i++) { 17 for (j=0; j<n; j++) { 18 v = -1.0; Ii = j + n*i; 19 if (i>0) {J = Ii - n; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 20 if (i<m-1) {J = Ii + n; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 21 if (j>0) {J = Ii - 1; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 22 if (j<n-1) {J = Ii + 1; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 23 v = 4.0; PetscCall(MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES)); 24 } 25 } 26 PetscCall(MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY)); 27 PetscCall(MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY)); 28 29 PetscCall(MatConvert(C,MATSAME,MAT_INITIAL_MATRIX,&A)); 30 31 PetscCall(MatGetOrdering(A,MATORDERINGND,&perm,&iperm)); 32 PetscCall(ISView(perm,PETSC_VIEWER_STDOUT_SELF)); 33 PetscCall(ISView(iperm,PETSC_VIEWER_STDOUT_SELF)); 34 PetscCall(MatView(A,PETSC_VIEWER_STDOUT_SELF)); 35 36 PetscCall(ISDestroy(&perm)); 37 PetscCall(ISDestroy(&iperm)); 38 PetscCall(MatDestroy(&C)); 39 PetscCall(MatDestroy(&A)); 40 PetscCall(PetscFinalize()); 41 return 0; 42 } 43 44 /*TEST 45 46 test: 47 filter: grep -v " MPI process" 48 49 TEST*/ 50