Actual source code: ex172.c

petsc-3.14.6 2021-03-30
Report Typos and Errors

  2: static char help[] = "Test MatAXPY and SUBSET_NONZERO_PATTERN [-different] [-skip]\n by default subset pattern is used \n\n";

  4: /* A test contributed by Jose E. Roman, Oct. 2014 */

  6: #include <petscmat.h>

  8: int main(int argc,char **args)
  9: {
 11:   Mat            A,B,C;
 12:   PetscBool      different=PETSC_FALSE,skip=PETSC_FALSE;
 13:   PetscInt       m0,m1,n=128,i;

 15:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 16:   PetscOptionsGetBool(NULL,NULL,"-different",&different,NULL);
 17:   PetscOptionsGetBool(NULL,NULL,"-skip",&skip,NULL);
 18:   /*
 19:      Create matrices
 20:      A = tridiag(1,-2,1) and B = diag(7);
 21:   */
 22:   MatCreate(PETSC_COMM_WORLD,&A);
 23:   MatCreate(PETSC_COMM_WORLD,&B);
 24:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
 25:   MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,n,n);
 26:   MatSetFromOptions(A);
 27:   MatSetFromOptions(B);
 28:   MatSetUp(A);
 29:   MatSetUp(B);
 30:   MatGetOwnershipRange(A,&m0,&m1);
 31:   for (i=m0;i<m1;i++) {
 32:     if (i>0) { MatSetValue(A,i,i-1,-1.0,INSERT_VALUES); }
 33:     if (i<n-1) { MatSetValue(A,i,i+1,-1.0,INSERT_VALUES); }
 34:     MatSetValue(A,i,i,2.0,INSERT_VALUES);
 35:     MatSetValue(B,i,i,7.0,INSERT_VALUES);
 36:   }
 37:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 38:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
 39:   MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);
 40:   MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);

 42:   MatDuplicate(A,MAT_COPY_VALUES,&C);
 43:   /* Add B */
 44:   MatAXPY(C,1.0,B,(different)?DIFFERENT_NONZERO_PATTERN:SUBSET_NONZERO_PATTERN);
 45:   /* Add A */
 46:   if (!skip) { MatAXPY(C,1.0,A,SUBSET_NONZERO_PATTERN); }

 48:   /*
 49:      Free memory
 50:   */
 51:   MatDestroy(&A);
 52:   MatDestroy(&B);
 53:   MatDestroy(&C);
 54:   PetscFinalize();
 55:   return ierr;
 56: }


 59: /*TEST

 61:    test:
 62:       nsize: 4
 63:       output_file: output/ex172.out

 65:    test:
 66:       suffix: 2
 67:       nsize: 4
 68:       args: -different
 69:       output_file: output/ex172.out

 71:    test:
 72:       suffix: 3
 73:       nsize: 4
 74:       args: -skip
 75:       output_file: output/ex172.out

 77:    test:
 78:       suffix: 4
 79:       nsize: 4
 80:       args: -different -skip
 81:       output_file: output/ex172.out

 83:    test:
 84:       suffix: baij
 85:       args: -mat_type baij> ex172.tmp 2>&1
 86:       output_file: output/ex172.out

 88:    test:
 89:       suffix: mpibaij
 90:       nsize: 4
 91:       args: -mat_type baij> ex172.tmp 2>&1
 92:       output_file: output/ex172.out

 94:    test:
 95:       suffix: mpisbaij
 96:       nsize: 4
 97:       args: -mat_type sbaij> ex172.tmp 2>&1
 98:       output_file: output/ex172.out

100:    test:
101:       suffix: sbaij
102:       args: -mat_type sbaij> ex172.tmp 2>&1
103:       output_file: output/ex172.out

105: TEST*/