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;

 15:   PetscInitialize(&argc, &args, (char *)0, help);
 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 0;
 56: }

 58: /*TEST

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

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

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

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

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

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

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

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

104: TEST*/