Actual source code: normm.c

  1: #include <../src/mat/impls/shell/shell.h>

  3: typedef struct {
  4:   Mat A;
  5:   Mat D; /* local submatrix for diagonal part */
  6:   Vec w;
  7: } Mat_Normal;

  9: static PetscErrorCode MatIncreaseOverlap_Normal(Mat A, PetscInt is_max, IS is[], PetscInt ov)
 10: {
 11:   Mat_Normal *a;
 12:   Mat         pattern;

 14:   PetscFunctionBegin;
 15:   PetscCheck(ov >= 0, PetscObjectComm((PetscObject)A), PETSC_ERR_ARG_OUTOFRANGE, "Negative overlap specified");
 16:   PetscCall(MatShellGetContext(A, &a));
 17:   PetscCall(MatProductCreate(a->A, a->A, NULL, &pattern));
 18:   PetscCall(MatSetOption(pattern, MAT_STRUCTURE_ONLY, PETSC_TRUE));
 19:   PetscCall(MatProductSetType(pattern, MATPRODUCT_AtB));
 20:   PetscCall(MatProductSetFromOptions(pattern));
 21:   PetscCall(MatProductSymbolic(pattern));
 22:   /* release symbolic product workspace before increasing overlap */
 23:   PetscCall(MatProductClear(pattern));
 24:   PetscCall(MatIncreaseOverlap(pattern, is_max, is, ov));
 25:   PetscCall(MatDestroy(&pattern));
 26:   PetscFunctionReturn(PETSC_SUCCESS);
 27: }

 29: static PetscErrorCode MatCreateSubMatrices_Normal(Mat mat, PetscInt n, const IS irow[], const IS icol[], MatReuse scall, Mat *submat[])
 30: {
 31:   Mat_Normal *a;
 32:   Mat         B, *suba;
 33:   IS         *row;
 34:   PetscScalar shift, scale;
 35:   PetscInt    M;

 37:   PetscFunctionBegin;
 38:   PetscCheck(irow == icol, PetscObjectComm((PetscObject)mat), PETSC_ERR_SUP, "Not implemented");
 39:   PetscCall(MatShellGetScalingShifts(mat, &shift, &scale, (Vec *)MAT_SHELL_NOT_ALLOWED, (Vec *)MAT_SHELL_NOT_ALLOWED, (Vec *)MAT_SHELL_NOT_ALLOWED, (Mat *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED));
 40:   PetscCall(MatShellGetContext(mat, &a));
 41:   B = a->A;
 42:   if (scall != MAT_REUSE_MATRIX) PetscCall(PetscCalloc1(n, submat));
 43:   PetscCall(MatGetSize(B, &M, NULL));
 44:   PetscCall(PetscMalloc1(n, &row));
 45:   PetscCall(ISCreateStride(PETSC_COMM_SELF, M, 0, 1, &row[0]));
 46:   PetscCall(ISSetIdentity(row[0]));
 47:   for (M = 1; M < n; ++M) row[M] = row[0];
 48:   PetscCall(MatCreateSubMatrices(B, n, row, icol, MAT_INITIAL_MATRIX, &suba));
 49:   for (M = 0; M < n; ++M) {
 50:     PetscCall(MatCreateNormal(suba[M], *submat + M));
 51:     PetscCall(MatShift((*submat)[M], shift));
 52:     PetscCall(MatScale((*submat)[M], scale));
 53:   }
 54:   PetscCall(ISDestroy(&row[0]));
 55:   PetscCall(PetscFree(row));
 56:   PetscCall(MatDestroySubMatrices(n, &suba));
 57:   PetscFunctionReturn(PETSC_SUCCESS);
 58: }

 60: static PetscErrorCode MatPermute_Normal(Mat A, IS rowp, IS colp, Mat *B)
 61: {
 62:   Mat_Normal *a;
 63:   Mat         C, Aa;
 64:   IS          row;
 65:   PetscScalar shift, scale;

 67:   PetscFunctionBegin;
 68:   PetscCheck(rowp == colp, PetscObjectComm((PetscObject)A), PETSC_ERR_ARG_INCOMP, "Row permutation and column permutation must be the same");
 69:   PetscCall(MatShellGetScalingShifts(A, &shift, &scale, (Vec *)MAT_SHELL_NOT_ALLOWED, (Vec *)MAT_SHELL_NOT_ALLOWED, (Vec *)MAT_SHELL_NOT_ALLOWED, (Mat *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED));
 70:   PetscCall(MatShellGetContext(A, &a));
 71:   Aa = a->A;
 72:   PetscCall(ISCreateStride(PetscObjectComm((PetscObject)Aa), Aa->rmap->n, Aa->rmap->rstart, 1, &row));
 73:   PetscCall(ISSetIdentity(row));
 74:   PetscCall(MatPermute(Aa, row, colp, &C));
 75:   PetscCall(ISDestroy(&row));
 76:   PetscCall(MatCreateNormal(C, B));
 77:   PetscCall(MatDestroy(&C));
 78:   PetscCall(MatShift(*B, shift));
 79:   PetscCall(MatScale(*B, scale));
 80:   PetscFunctionReturn(PETSC_SUCCESS);
 81: }

 83: static PetscErrorCode MatDuplicate_Normal(Mat A, MatDuplicateOption op, Mat *B)
 84: {
 85:   Mat_Normal *a;
 86:   Mat         C;

 88:   PetscFunctionBegin;
 89:   PetscCall(MatShellGetContext(A, &a));
 90:   PetscCall(MatDuplicate(a->A, op, &C));
 91:   PetscCall(MatCreateNormal(C, B));
 92:   PetscCall(MatDestroy(&C));
 93:   if (op == MAT_COPY_VALUES) PetscCall(MatCopy(A, *B, SAME_NONZERO_PATTERN));
 94:   PetscFunctionReturn(PETSC_SUCCESS);
 95: }

 97: static PetscErrorCode MatCopy_Normal(Mat A, Mat B, MatStructure str)
 98: {
 99:   Mat_Normal *a, *b;

101:   PetscFunctionBegin;
102:   PetscCall(MatShellGetContext(A, &a));
103:   PetscCall(MatShellGetContext(B, &b));
104:   PetscCall(MatCopy(a->A, b->A, str));
105:   PetscFunctionReturn(PETSC_SUCCESS);
106: }

108: static PetscErrorCode MatMult_Normal(Mat N, Vec x, Vec y)
109: {
110:   Mat_Normal *Na;

112:   PetscFunctionBegin;
113:   PetscCall(MatShellGetContext(N, &Na));
114:   PetscCall(MatMult(Na->A, x, Na->w));
115:   PetscCall(MatMultTranspose(Na->A, Na->w, y));
116:   PetscFunctionReturn(PETSC_SUCCESS);
117: }

119: static PetscErrorCode MatDestroy_Normal(Mat N)
120: {
121:   Mat_Normal *Na;

123:   PetscFunctionBegin;
124:   PetscCall(MatShellGetContext(N, &Na));
125:   PetscCall(MatDestroy(&Na->A));
126:   PetscCall(MatDestroy(&Na->D));
127:   PetscCall(VecDestroy(&Na->w));
128:   PetscCall(PetscFree(Na));
129:   PetscCall(PetscObjectComposeFunction((PetscObject)N, "MatNormalGetMat_C", NULL));
130:   PetscCall(PetscObjectComposeFunction((PetscObject)N, "MatConvert_normal_seqaij_C", NULL));
131:   PetscCall(PetscObjectComposeFunction((PetscObject)N, "MatConvert_normal_mpiaij_C", NULL));
132: #if PetscDefined(HAVE_HYPRE)
133:   PetscCall(PetscObjectComposeFunction((PetscObject)N, "MatConvert_normal_hypre_C", NULL));
134: #endif
135:   PetscCall(PetscObjectComposeFunction((PetscObject)N, "MatProductSetFromOptions_normal_seqdense_C", NULL));
136:   PetscCall(PetscObjectComposeFunction((PetscObject)N, "MatProductSetFromOptions_normal_mpidense_C", NULL));
137:   PetscCall(PetscObjectComposeFunction((PetscObject)N, "MatShellSetContext_C", NULL));
138:   PetscFunctionReturn(PETSC_SUCCESS);
139: }

141: /*
142:       Slow, nonscalable version
143: */
144: static PetscErrorCode MatGetDiagonal_Normal(Mat N, Vec v)
145: {
146:   Mat_Normal        *Na;
147:   Mat                A;
148:   PetscInt           i, j, rstart, rend, nnz;
149:   const PetscInt    *cols;
150:   PetscScalar       *work, *values;
151:   const PetscScalar *mvalues;

153:   PetscFunctionBegin;
154:   PetscCall(MatShellGetContext(N, &Na));
155:   A = Na->A;
156:   PetscCall(PetscMalloc1(A->cmap->N, &work));
157:   PetscCall(PetscArrayzero(work, A->cmap->N));
158:   PetscCall(MatGetOwnershipRange(A, &rstart, &rend));
159:   for (i = rstart; i < rend; i++) {
160:     PetscCall(MatGetRow(A, i, &nnz, &cols, &mvalues));
161:     for (j = 0; j < nnz; j++) work[cols[j]] += mvalues[j] * mvalues[j];
162:     PetscCall(MatRestoreRow(A, i, &nnz, &cols, &mvalues));
163:   }
164:   PetscCallMPI(MPIU_Allreduce(MPI_IN_PLACE, work, A->cmap->N, MPIU_SCALAR, MPIU_SUM, PetscObjectComm((PetscObject)N)));
165:   rstart = N->cmap->rstart;
166:   rend   = N->cmap->rend;
167:   PetscCall(VecGetArray(v, &values));
168:   PetscCall(PetscArraycpy(values, work + rstart, rend - rstart));
169:   PetscCall(VecRestoreArray(v, &values));
170:   PetscCall(PetscFree(work));
171:   PetscFunctionReturn(PETSC_SUCCESS);
172: }

174: static PetscErrorCode MatGetDiagonalBlock_Normal(Mat N, Mat *D)
175: {
176:   Mat_Normal *Na;
177:   Mat         M, A;

179:   PetscFunctionBegin;
180:   PetscCall(MatShellGetContext(N, &Na));
181:   A = Na->A;
182:   PetscCall(MatGetDiagonalBlock(A, &M));
183:   PetscCall(MatCreateNormal(M, &Na->D));
184:   *D = Na->D;
185:   PetscFunctionReturn(PETSC_SUCCESS);
186: }

188: static PetscErrorCode MatNormalGetMat_Normal(Mat A, Mat *M)
189: {
190:   Mat_Normal *Aa;

192:   PetscFunctionBegin;
193:   PetscCall(MatShellGetContext(A, &Aa));
194:   *M = Aa->A;
195:   PetscFunctionReturn(PETSC_SUCCESS);
196: }

198: /*@
199:   MatNormalGetMat - Gets the `Mat` object stored inside a `MATNORMAL`

201:   Logically Collective

203:   Input Parameter:
204: . A - the `MATNORMAL` matrix

206:   Output Parameter:
207: . M - the matrix object stored inside `A`

209:   Level: intermediate

211: .seealso: [](ch_matrices), `Mat`, `MATNORMAL`, `MATNORMALHERMITIAN`, `MatCreateNormal()`
212: @*/
213: PetscErrorCode MatNormalGetMat(Mat A, Mat *M)
214: {
215:   PetscFunctionBegin;
218:   PetscAssertPointer(M, 2);
219:   PetscUseMethod(A, "MatNormalGetMat_C", (Mat, Mat *), (A, M));
220:   PetscFunctionReturn(PETSC_SUCCESS);
221: }

223: static PetscErrorCode MatConvert_Normal_AIJ(Mat A, MatType newtype, MatReuse reuse, Mat *newmat)
224: {
225:   Mat_Normal *Aa;
226:   Mat         B;
227:   Vec         left, right, dshift;
228:   PetscScalar scale, shift;
229:   PetscInt    m, n, M, N;

231:   PetscFunctionBegin;
232:   PetscCall(MatShellGetContext(A, &Aa));
233:   PetscCall(MatShellGetScalingShifts(A, &shift, &scale, &dshift, &left, &right, (Mat *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED));
234:   PetscCall(MatGetSize(A, &M, &N));
235:   PetscCall(MatGetLocalSize(A, &m, &n));
236:   if (reuse == MAT_REUSE_MATRIX) {
237:     B = *newmat;
238:     PetscCall(MatProductReplaceMats(Aa->A, Aa->A, NULL, B));
239:   } else {
240:     PetscCall(MatProductCreate(Aa->A, Aa->A, NULL, &B));
241:     PetscCall(MatProductSetType(B, MATPRODUCT_AtB));
242:     PetscCall(MatProductSetFromOptions(B));
243:     PetscCall(MatProductSymbolic(B));
244:     PetscCall(MatSetOption(B, MAT_SYMMETRIC, PETSC_TRUE));
245:   }
246:   PetscCall(MatProductNumeric(B));
247:   if (reuse == MAT_INPLACE_MATRIX) PetscCall(MatHeaderReplace(A, &B));
248:   else if (reuse == MAT_INITIAL_MATRIX) *newmat = B;
249:   PetscCall(MatConvert(*newmat, MATAIJ, MAT_INPLACE_MATRIX, newmat));
250:   PetscCall(MatDiagonalScale(*newmat, left, right));
251:   PetscCall(MatScale(*newmat, scale));
252:   PetscCall(MatShift(*newmat, shift));
253:   if (dshift) PetscCall(MatDiagonalSet(*newmat, dshift, ADD_VALUES));
254:   PetscFunctionReturn(PETSC_SUCCESS);
255: }

257: #if PetscDefined(HAVE_HYPRE)
258: static PetscErrorCode MatConvert_Normal_HYPRE(Mat A, MatType type, MatReuse reuse, Mat *B)
259: {
260:   PetscFunctionBegin;
261:   if (reuse == MAT_INITIAL_MATRIX) {
262:     PetscCall(MatConvert(A, MATAIJ, reuse, B));
263:     PetscCall(MatConvert(*B, type, MAT_INPLACE_MATRIX, B));
264:   } else PetscCall(MatConvert_Basic(A, type, reuse, B)); /* fall back to basic convert */
265:   PetscFunctionReturn(PETSC_SUCCESS);
266: }
267: #endif

269: typedef struct {
270:   Mat work[2];
271: } Normal_Dense;

273: static PetscErrorCode MatProductNumeric_Normal_Dense(Mat C)
274: {
275:   Mat           A, B;
276:   Normal_Dense *contents;
277:   Mat_Normal   *a;
278:   Vec           right;
279:   PetscScalar  *array, scale;

281:   PetscFunctionBegin;
282:   MatCheckProduct(C, 1);
283:   A = C->product->A;
284:   B = C->product->B;
285:   PetscCall(MatShellGetContext(A, &a));
286:   contents = (Normal_Dense *)C->product->data;
287:   PetscCheck(contents, PetscObjectComm((PetscObject)C), PETSC_ERR_PLIB, "Product data empty");
288:   PetscCall(MatShellGetScalingShifts(A, (PetscScalar *)MAT_SHELL_NOT_ALLOWED, &scale, (Vec *)MAT_SHELL_NOT_ALLOWED, (Vec *)MAT_SHELL_NOT_ALLOWED, &right, (Mat *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED));
289:   if (right) {
290:     PetscCall(MatCopy(B, C, SAME_NONZERO_PATTERN));
291:     PetscCall(MatDiagonalScale(C, right, NULL));
292:   }
293:   PetscCall(MatProductNumeric(contents->work[0]));
294:   PetscCall(MatDenseGetArrayWrite(C, &array));
295:   PetscCall(MatDensePlaceArray(contents->work[1], array));
296:   PetscCall(MatProductNumeric(contents->work[1]));
297:   PetscCall(MatDenseRestoreArrayWrite(C, &array));
298:   PetscCall(MatDenseResetArray(contents->work[1]));
299:   PetscCall(MatSetOption(C, MAT_NO_OFF_PROC_ENTRIES, PETSC_TRUE));
300:   PetscCall(MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY));
301:   PetscCall(MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY));
302:   PetscCall(MatScale(C, scale));
303:   PetscFunctionReturn(PETSC_SUCCESS);
304: }

306: static PetscErrorCode MatNormal_DenseDestroy(PetscCtxRt ctx)
307: {
308:   Normal_Dense *contents = *(Normal_Dense **)ctx;

310:   PetscFunctionBegin;
311:   PetscCall(MatDestroy(contents->work));
312:   PetscCall(MatDestroy(contents->work + 1));
313:   PetscCall(PetscFree(contents));
314:   PetscFunctionReturn(PETSC_SUCCESS);
315: }

317: static PetscErrorCode MatProductSymbolic_Normal_Dense(Mat C)
318: {
319:   Mat           A, B;
320:   Normal_Dense *contents = NULL;
321:   Mat_Normal   *a;
322:   Vec           right;
323:   PetscScalar  *array, scale;
324:   PetscInt      n, N, m, M;

326:   PetscFunctionBegin;
327:   MatCheckProduct(C, 1);
328:   PetscCheck(!C->product->data, PetscObjectComm((PetscObject)C), PETSC_ERR_PLIB, "Product data not empty");
329:   A = C->product->A;
330:   B = C->product->B;
331:   PetscCall(MatShellGetScalingShifts(A, (PetscScalar *)MAT_SHELL_NOT_ALLOWED, &scale, (Vec *)MAT_SHELL_NOT_ALLOWED, (Vec *)MAT_SHELL_NOT_ALLOWED, &right, (Mat *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED, (IS *)MAT_SHELL_NOT_ALLOWED));
332:   PetscCall(MatShellGetContext(A, &a));
333:   PetscCall(MatGetLocalSize(B, NULL, &n));
334:   PetscCall(MatGetSize(B, NULL, &N));
335:   PetscCall(MatGetLocalSize(A, &m, NULL));
336:   PetscCall(MatGetSize(A, &M, NULL));
337:   PetscCall(MatSetSizes(C, m, n, M, N));
338:   PetscCall(MatSetType(C, ((PetscObject)B)->type_name));
339:   PetscCall(MatSetVecType(C, B->defaultvectype));
340:   PetscCall(MatSetUp(C));
341:   PetscCall(PetscNew(&contents));
342:   C->product->data    = contents;
343:   C->product->destroy = MatNormal_DenseDestroy;
344:   if (right) PetscCall(MatProductCreate(a->A, C, NULL, contents->work));
345:   else PetscCall(MatProductCreate(a->A, B, NULL, contents->work));
346:   PetscCall(MatProductSetType(contents->work[0], MATPRODUCT_AB));
347:   PetscCall(MatProductSetFromOptions(contents->work[0]));
348:   PetscCall(MatProductSymbolic(contents->work[0]));
349:   PetscCall(MatProductCreate(a->A, contents->work[0], NULL, contents->work + 1));
350:   PetscCall(MatProductSetType(contents->work[1], MATPRODUCT_AtB));
351:   PetscCall(MatProductSetFromOptions(contents->work[1]));
352:   PetscCall(MatProductSymbolic(contents->work[1]));
353:   PetscCall(MatDenseGetArrayWrite(C, &array));
354:   PetscCall(MatSeqDenseSetPreallocation(contents->work[1], array));
355:   PetscCall(MatMPIDenseSetPreallocation(contents->work[1], array));
356:   PetscCall(MatDenseRestoreArrayWrite(C, &array));
357:   C->ops->productnumeric = MatProductNumeric_Normal_Dense;
358:   PetscFunctionReturn(PETSC_SUCCESS);
359: }

361: static PetscErrorCode MatProductSetFromOptions_Normal_Dense(Mat C)
362: {
363:   Mat_Product *product = C->product;

365:   PetscFunctionBegin;
366:   if (product->type == MATPRODUCT_AB) C->ops->productsymbolic = MatProductSymbolic_Normal_Dense;
367:   PetscFunctionReturn(PETSC_SUCCESS);
368: }

370: /*MC
371:   MATNORMAL - a matrix that behaves like A'*A for `MatMult()` while only containing A

373:   Level: intermediate

375:   Developer Notes:
376:   This is implemented on top of `MATSHELL` to get support for scaling and shifting without requiring duplicate code

378:   Users can not call `MatShellSetOperation()` operations on this class, there is some error checking for that incorrect usage

380: .seealso: [](ch_matrices), `Mat`, `MatCreateNormal()`, `MatMult()`, `MatNormalGetMat()`, `MATNORMALHERMITIAN`, `MatCreateNormalHermitian()`
381: M*/

383: /*@
384:   MatCreateNormal - Creates a new `MATNORMAL` matrix object that behaves like $A^T A$.

386:   Collective

388:   Input Parameter:
389: . A - the (possibly rectangular) matrix

391:   Output Parameter:
392: . N - the matrix that represents $A^T A $

394:   Level: intermediate

396:   Notes:
397:   The product $A^T A$ is NOT actually formed! Rather the new matrix
398:   object performs the matrix-vector product, `MatMult()`, by first multiplying by
399:   $A$ and then $A^T$

401:   If `MatGetFactor()` is called on this matrix with `MAT_FACTOR_QR` then the inner matrix `A` is used for the factorization

403: .seealso: [](ch_matrices), `Mat`, `MATNORMAL`, `MatMult()`, `MatNormalGetMat()`, `MATNORMALHERMITIAN`, `MatCreateNormalHermitian()`
404: @*/
405: PetscErrorCode MatCreateNormal(Mat A, Mat *N)
406: {
407:   Mat_Normal *Na;
408:   VecType     vtype;

410:   PetscFunctionBegin;
411:   PetscCall(MatCreate(PetscObjectComm((PetscObject)A), N));
412:   PetscCall(PetscLayoutReference(A->cmap, &(*N)->rmap));
413:   PetscCall(PetscLayoutReference(A->cmap, &(*N)->cmap));
414:   PetscCall(MatSetType(*N, MATSHELL));
415:   PetscCall(PetscNew(&Na));
416:   PetscCall(MatShellSetContext(*N, Na));
417:   PetscCall(PetscObjectReference((PetscObject)A));
418:   Na->A = A;
419:   PetscCall(MatCreateVecs(A, NULL, &Na->w));

421:   PetscCall(MatSetBlockSize(*N, A->cmap->bs));
422:   PetscCall(MatShellSetOperation(*N, MATOP_DESTROY, (PetscErrorCodeFn *)MatDestroy_Normal));
423:   PetscCall(MatShellSetOperation(*N, MATOP_MULT, (PetscErrorCodeFn *)MatMult_Normal));
424:   PetscCall(MatShellSetOperation(*N, MATOP_MULT_TRANSPOSE, (PetscErrorCodeFn *)MatMult_Normal));
425:   PetscCall(MatShellSetOperation(*N, MATOP_DUPLICATE, (PetscErrorCodeFn *)MatDuplicate_Normal));
426:   PetscCall(MatShellSetOperation(*N, MATOP_GET_DIAGONAL, (PetscErrorCodeFn *)MatGetDiagonal_Normal));
427:   PetscCall(MatShellSetOperation(*N, MATOP_GET_DIAGONAL_BLOCK, (PetscErrorCodeFn *)MatGetDiagonalBlock_Normal));
428:   PetscCall(MatShellSetOperation(*N, MATOP_COPY, (PetscErrorCodeFn *)MatCopy_Normal));
429:   (*N)->ops->increaseoverlap   = MatIncreaseOverlap_Normal;
430:   (*N)->ops->createsubmatrices = MatCreateSubMatrices_Normal;
431:   (*N)->ops->permute           = MatPermute_Normal;

433:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatNormalGetMat_C", MatNormalGetMat_Normal));
434:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatConvert_normal_seqaij_C", MatConvert_Normal_AIJ));
435:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatConvert_normal_mpiaij_C", MatConvert_Normal_AIJ));
436: #if PetscDefined(HAVE_HYPRE)
437:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatConvert_normal_hypre_C", MatConvert_Normal_HYPRE));
438: #endif
439:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatProductSetFromOptions_normal_seqdense_C", MatProductSetFromOptions_Normal_Dense));
440:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatProductSetFromOptions_normal_mpidense_C", MatProductSetFromOptions_Normal_Dense));
441:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatShellSetContext_C", MatShellSetContext_Immutable));
442:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatShellSetContextDestroy_C", MatShellSetContextDestroy_Immutable));
443:   PetscCall(PetscObjectComposeFunction((PetscObject)*N, "MatShellSetManageScalingShifts_C", MatShellSetManageScalingShifts_Immutable));
444:   PetscCall(MatSetOption(*N, MAT_SYMMETRIC, PETSC_TRUE));
445:   PetscCall(MatGetVecType(A, &vtype));
446:   PetscCall(MatSetVecType(*N, vtype));
447: #if PetscDefined(HAVE_DEVICE)
448:   PetscCall(MatBindToCPU(*N, A->boundtocpu));
449: #endif
450:   PetscCall(MatSetUp(*N));
451:   PetscCall(PetscObjectChangeTypeName((PetscObject)*N, MATNORMAL));
452:   PetscFunctionReturn(PETSC_SUCCESS);
453: }