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 PetscFunctionBeginUser; 14 PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); 15 PetscCall(MatCreateSeqAIJ(PETSC_COMM_SELF,m*n,m*n,5,NULL,&C)); 16 /* create the matrix for the five point stencil, YET AGAIN*/ 17 for (i=0; i<m; i++) { 18 for (j=0; j<n; j++) { 19 v = -1.0; Ii = j + n*i; 20 if (i>0) {J = Ii - n; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 21 if (i<m-1) {J = Ii + n; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 22 if (j>0) {J = Ii - 1; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 23 if (j<n-1) {J = Ii + 1; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 24 v = 4.0; PetscCall(MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES)); 25 } 26 } 27 PetscCall(MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY)); 28 PetscCall(MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY)); 29 30 PetscCall(MatConvert(C,MATSAME,MAT_INITIAL_MATRIX,&A)); 31 32 PetscCall(MatGetOrdering(A,MATORDERINGND,&perm,&iperm)); 33 PetscCall(ISView(perm,PETSC_VIEWER_STDOUT_SELF)); 34 PetscCall(ISView(iperm,PETSC_VIEWER_STDOUT_SELF)); 35 PetscCall(MatView(A,PETSC_VIEWER_STDOUT_SELF)); 36 37 PetscCall(ISDestroy(&perm)); 38 PetscCall(ISDestroy(&iperm)); 39 PetscCall(MatDestroy(&C)); 40 PetscCall(MatDestroy(&A)); 41 PetscCall(PetscFinalize()); 42 return 0; 43 } 44 45 /*TEST 46 47 test: 48 filter: grep -v " MPI process" 49 50 TEST*/ 51