Actual source code: ex172.c


  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: {
 10:   Mat            A,B,C;
 11:   PetscBool      different=PETSC_FALSE,skip=PETSC_FALSE;
 12:   PetscInt       m0,m1,n=128,i;

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

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

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

 57: /*TEST

 59:    test:
 60:       nsize: 4
 61:       output_file: output/ex172.out

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

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

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

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

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

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

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

103: TEST*/