Actual source code: ex182.c

  1: static char help[] = "Tests using MatShift() to create a constant diagonal matrix\n\n";

  3: #include <petscmat.h>

  5: int main(int argc, char **argv)
  6: {
  7:   Mat           A, F;
  8:   MatFactorInfo info;
  9:   PetscInt      m = 10;
 10:   IS            perm;
 11:   PetscMPIInt   size;
 12:   PetscBool     issbaij;

 14:   PetscFunctionBeginUser;
 15:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
 16:   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));

 18:   PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
 19:   PetscCall(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, m, m));
 20:   PetscCall(MatSetFromOptions(A));
 21:   PetscCall(MatSetUp(A));
 22:   PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
 23:   PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));

 25:   PetscCall(MatShift(A, 1.0));

 27:   PetscCall(PetscObjectTypeCompare((PetscObject)A, MATSEQSBAIJ, &issbaij));
 28:   if (size == 1 && !issbaij) {
 29:     PetscCall(MatGetFactor(A, MATSOLVERPETSC, MAT_FACTOR_LU, &F));
 30:     PetscCall(MatFactorInfoInitialize(&info));
 31:     PetscCall(ISCreateStride(PETSC_COMM_SELF, m, 0, 1, &perm));
 32:     PetscCall(MatLUFactorSymbolic(F, A, perm, perm, &info));
 33:     PetscCall(MatLUFactorNumeric(F, A, &info));
 34:     PetscCall(MatDestroy(&F));
 35:     PetscCall(ISDestroy(&perm));
 36:   }
 37:   PetscCall(MatDestroy(&A));
 38:   PetscCall(PetscFinalize());
 39:   return 0;
 40: }

 42: /*TEST

 44:    test:
 45:       requires: defined(PETSC_USE_INFO)
 46:       args: -info
 47:       filter: grep malloc | sort -b

 49:    test:
 50:       suffix: 2
 51:       nsize: 2
 52:       requires: defined(PETSC_USE_INFO)
 53:       args: -info ex182info
 54:       filter: grep -h malloc "ex182info.0" | sort -b

 56:    test:
 57:       suffix: 3
 58:       requires: defined(PETSC_USE_INFO)
 59:       args: -info -mat_type baij
 60:       filter: grep malloc | sort -b

 62:    test:
 63:       suffix: 4
 64:       nsize: 2
 65:       requires: defined(PETSC_USE_INFO)
 66:       args: -info ex182info -mat_type baij
 67:       filter: grep -h malloc "ex182info.1" | sort -b

 69:    test:
 70:       suffix: 5
 71:       requires: defined(PETSC_USE_INFO)
 72:       args: -info -mat_type sbaij
 73:       filter: grep malloc | sort  -b

 75:    test:
 76:       suffix: 6
 77:       nsize: 2
 78:       requires: defined(PETSC_USE_INFO)
 79:       args: -info ex182info -mat_type sbaij
 80:       filter: grep -h malloc "ex182info.0" | sort -b

 82:    test:
 83:      suffix: 7
 84:      nsize: 1
 85:      requires: defined(PETSC_USE_INFO)
 86:      args: -info ex182info
 87:      filter: grep -h malloc "ex182info.0" | grep -v Running | sort -b

 89:    test:
 90:      suffix: 8
 91:      nsize: 2
 92:      requires: defined(PETSC_USE_INFO)
 93:      args: -info ex182info:mat
 94:      filter: grep -h malloc "ex182info.1" | sort -b

 96:    test:
 97:      suffix: 9
 98:      nsize: 1
 99:      requires: defined(PETSC_USE_INFO) !defined(PETSC_HAVE_THREADSAFETY)
100:      args: -info ex182info:sys
101:      filter: grep -h -ve Running -ve MPI_Comm -ve Initialize -ve communicator -ve HostName -ve PetscSetFPTrap -ve PetscDetermineInitialFPTrap -ve libpetscbamg "ex182info.0" | sort -b

103:    test:
104:      suffix: 10
105:      nsize: 1
106:      requires: defined(PETSC_USE_INFO)
107:      args: -info :~sys
108:      filter: grep -h malloc | sort -b

110:    test:
111:      suffix: 11
112:      nsize: 2
113:      requires: defined(PETSC_USE_INFO)
114:      args: -info :~sys,mat
115:      filter: sort -b

117:    test:
118:      suffix: 12
119:      nsize: 2
120:      requires: defined(PETSC_USE_INFO) !defined(PETSC_HAVE_THREADSAFETY)
121:      args: -info ex182info:sys,mat
122:      filter: grep -h -ve Running -ve MPI_Comm -ve Initialize -ve communicator -ve HostName -ve PetscSetFPTrap -ve PetscDetermineInitialFPTrap -ve libpetscbamg "ex182info.1" | sort -b

124:    test:
125:      suffix: 13
126:      nsize: 2
127:      requires: defined(PETSC_USE_INFO)
128:      args: -info ex182info:mat:~self
129:      filter: grep -h "ex182info.1" | sort -b

131:    test:
132:      suffix: 14
133:      nsize: 2
134:      requires: defined(PETSC_USE_INFO)
135:      args: -info ex182info::~self
136:      filter: grep -h -ve Running -ve MPI_Comm -ve Initialize -ve communicator -ve HostName -ve PetscSetFPTrap -ve PetscDetermineInitialFPTrap "ex182info.1" | sort -b

138:    test:
139:      suffix: 15
140:      nsize: 2
141:      requires: defined(PETSC_USE_INFO) !defined(PETSC_HAVE_THREADSAFETY)
142:      args: -info ex182info::self
143:      filter: grep -h -ve Running -ve MPI_Comm -ve Initialize -ve communicator -ve HostName -ve PetscSetFPTrap -ve PetscDetermineInitialFPTrap -ve libpetscbamg "ex182info.1" | sort -b

145: TEST*/