xref: /petsc/src/mat/impls/aij/seq/matptap.c (revision 5c66b693f009d4761214d61ad5c9d5d6dfaafa28)
1 /*
2   Defines projective product routines where A is a SeqAIJ matrix
3           C = P^T * A * P
4 */
5 
6 #include "src/mat/impls/aij/seq/aij.h"
7 #include "src/mat/utils/freespace.h"
8 
9 int MatSeqAIJPtAP(Mat,Mat,Mat*);
10 int MatSeqAIJPtAPSymbolic(Mat,Mat,Mat*);
11 int MatSeqAIJPtAPNumeric(Mat,Mat,Mat);
12 
13 static int MATSeqAIJ_PtAP         = 0;
14 static int MATSeqAIJ_PtAPSymbolic = 0;
15 static int MATSeqAIJ_PtAPNumeric  = 0;
16 
17 /*
18      MatSeqAIJPtAP - Creates the SeqAIJ matrix product, C,
19            of SeqAIJ matrix A and matrix P:
20                  C = P^T * A * P;
21 
22      Note: C is assumed to be uncreated.
23            If this is not the case, Destroy C before calling this routine.
24 */
25 #undef __FUNCT__
26 #define __FUNCT__ "MatSeqAIJPtAP"
27 int MatSeqAIJPtAP(Mat A,Mat P,Mat *C) {
28   int ierr;
29   char funct[80];
30 
31   PetscFunctionBegin;
32 
33   ierr = PetscLogEventBegin(MATSeqAIJ_PtAP,A,P,0,0);CHKERRQ(ierr);
34 
35   ierr = MatSeqAIJPtAPSymbolic(A,P,C);CHKERRQ(ierr);
36 
37   /* Avoid additional error checking included in */
38 /*   ierr = MatSeqAIJApplyPtAPNumeric(A,P,*C);CHKERRQ(ierr); */
39 
40   /* Query A for ApplyPtAPNumeric implementation based on types of P */
41   ierr = PetscStrcpy(funct,"MatApplyPtAPNumeric_seqaij_");CHKERRQ(ierr);
42   ierr = PetscStrcat(funct,P->type_name);CHKERRQ(ierr);
43   ierr = PetscTryMethod(A,funct,(Mat,Mat,Mat),(A,P,*C));CHKERRQ(ierr);
44 
45   ierr = PetscLogEventEnd(MATSeqAIJ_PtAP,A,P,0,0);CHKERRQ(ierr);
46 
47   PetscFunctionReturn(0);
48 }
49 
50 /*
51      MatSeqAIJPtAPSymbolic - Creates the (i,j) structure of the SeqAIJ matrix product, C,
52            of SeqAIJ matrix A and matrix P, according to:
53                  C = P^T * A * P;
54 
55      Note: C is assumed to be uncreated.
56            If this is not the case, Destroy C before calling this routine.
57 */
58 #undef __FUNCT__
59 #define __FUNCT__ "MatSeqAIJPtAPSymbolic"
60 int MatSeqAIJPtAPSymbolic(Mat A,Mat P,Mat *C) {
61   int ierr;
62   char funct[80];
63 
64   PetscFunctionBegin;
65 
66   PetscValidPointer(C);
67 
68   PetscValidHeaderSpecific(A,MAT_COOKIE);
69   PetscValidType(A);
70   MatPreallocated(A);
71   if (!A->assembled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");
72   if (A->factor) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for factored matrix");
73 
74   PetscValidHeaderSpecific(P,MAT_COOKIE);
75   PetscValidType(P);
76   MatPreallocated(P);
77   if (!P->assembled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");
78   if (P->factor) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for factored matrix");
79 
80   if (P->M!=A->N) SETERRQ2(PETSC_ERR_ARG_SIZ,"Matrix dimensions are incompatible, %d != %d",P->M,A->N);
81   if (A->M!=A->N) SETERRQ2(PETSC_ERR_ARG_SIZ,"Matrix 'A' must be square, %d != %d",A->M,A->N);
82 
83   /* Query A for ApplyPtAP implementation based on types of P */
84   ierr = PetscStrcpy(funct,"MatApplyPtAPSymbolic_seqaij_");CHKERRQ(ierr);
85   ierr = PetscStrcat(funct,P->type_name);CHKERRQ(ierr);
86   ierr = PetscTryMethod(A,funct,(Mat,Mat,Mat*),(A,P,C));CHKERRQ(ierr);
87 
88   PetscFunctionReturn(0);
89 }
90 
91 EXTERN_C_BEGIN
92 #undef __FUNCT__
93 #define __FUNCT__ "MatApplyPtAPSymbolic_SeqAIJ_SeqAIJ"
94 int MatApplyPtAPSymbolic_SeqAIJ_SeqAIJ(Mat A,Mat P,Mat *C) {
95   int            ierr;
96   FreeSpaceList  free_space=PETSC_NULL,current_space=PETSC_NULL;
97   Mat_SeqAIJ     *a=(Mat_SeqAIJ*)A->data,*p=(Mat_SeqAIJ*)P->data,*c;
98   int            *pti,*ptj,*ptJ,*ai=a->i,*aj=a->j,*ajj,*pi=p->i,*pj=p->j,*pjj;
99   int            *ci,*cj,*denserow,*sparserow,*ptadenserow,*ptasparserow,*ptaj;
100   int            an=A->N,am=A->M,pn=P->N,pm=P->M;
101   int            i,j,k,ptnzi,arow,anzj,ptanzi,prow,pnzj,cnzi;
102   MatScalar      *ca;
103 
104   PetscFunctionBegin;
105 
106   /* Start timer */
107   ierr = PetscLogEventBegin(MATSeqAIJ_PtAPSymbolic,A,P,0,0);CHKERRQ(ierr);
108 
109   /* Get ij structure of P^T */
110   ierr = MatGetSymbolicTranspose_SeqAIJ(P,&pti,&ptj);CHKERRQ(ierr);
111   ptJ=ptj;
112 
113   /* Allocate ci array, arrays for fill computation and */
114   /* free space for accumulating nonzero column info */
115   ierr = PetscMalloc((pn+1)*sizeof(int),&ci);CHKERRQ(ierr);
116   ci[0] = 0;
117 
118   ierr = PetscMalloc((2*pn+2*an+1)*sizeof(int),&ptadenserow);CHKERRQ(ierr);
119   ierr = PetscMemzero(ptadenserow,(2*pn+2*an+1)*sizeof(int));CHKERRQ(ierr);
120   ptasparserow = ptadenserow  + an;
121   denserow     = ptasparserow + an;
122   sparserow    = denserow     + pn;
123 
124   /* Set initial free space to be nnz(A) scaled by aspect ratio of P. */
125   /* This should be reasonable if sparsity of PtAP is similar to that of A. */
126   ierr          = GetMoreSpace((ai[am]/pm)*pn,&free_space);
127   current_space = free_space;
128 
129   /* Determine symbolic info for each row of C: */
130   for (i=0;i<pn;i++) {
131     ptnzi  = pti[i+1] - pti[i];
132     ptanzi = 0;
133     /* Determine symbolic row of PtA: */
134     for (j=0;j<ptnzi;j++) {
135       arow = *ptJ++;
136       anzj = ai[arow+1] - ai[arow];
137       ajj  = aj + ai[arow];
138       for (k=0;k<anzj;k++) {
139         if (!ptadenserow[ajj[k]]) {
140           ptadenserow[ajj[k]]    = -1;
141           ptasparserow[ptanzi++] = ajj[k];
142         }
143       }
144     }
145       /* Using symbolic info for row of PtA, determine symbolic info for row of C: */
146     ptaj = ptasparserow;
147     cnzi   = 0;
148     for (j=0;j<ptanzi;j++) {
149       prow = *ptaj++;
150       pnzj = pi[prow+1] - pi[prow];
151       pjj  = pj + pi[prow];
152       for (k=0;k<pnzj;k++) {
153         if (!denserow[pjj[k]]) {
154             denserow[pjj[k]]  = -1;
155             sparserow[cnzi++] = pjj[k];
156         }
157       }
158     }
159 
160     /* sort sparserow */
161     ierr = PetscSortInt(cnzi,sparserow);CHKERRQ(ierr);
162 
163     /* If free space is not available, make more free space */
164     /* Double the amount of total space in the list */
165     if (current_space->local_remaining<cnzi) {
166       ierr = GetMoreSpace(current_space->total_array_size,&current_space);CHKERRQ(ierr);
167     }
168 
169     /* Copy data into free space, and zero out denserows */
170     ierr = PetscMemcpy(current_space->array,sparserow,cnzi*sizeof(int));CHKERRQ(ierr);
171     current_space->array           += cnzi;
172     current_space->local_used      += cnzi;
173     current_space->local_remaining -= cnzi;
174 
175     for (j=0;j<ptanzi;j++) {
176       ptadenserow[ptasparserow[j]] = 0;
177     }
178     for (j=0;j<cnzi;j++) {
179       denserow[sparserow[j]] = 0;
180     }
181       /* Aside: Perhaps we should save the pta info for the numerical factorization. */
182       /*        For now, we will recompute what is needed. */
183     ci[i+1] = ci[i] + cnzi;
184   }
185   /* nnz is now stored in ci[ptm], column indices are in the list of free space */
186   /* Allocate space for cj, initialize cj, and */
187   /* destroy list of free space and other temporary array(s) */
188   ierr = PetscMalloc((ci[pn]+1)*sizeof(int),&cj);CHKERRQ(ierr);
189   ierr = MakeSpaceContiguous(&free_space,cj);CHKERRQ(ierr);
190   ierr = PetscFree(ptadenserow);CHKERRQ(ierr);
191 
192   /* Allocate space for ca */
193   ierr = PetscMalloc((ci[pn]+1)*sizeof(MatScalar),&ca);CHKERRQ(ierr);
194   ierr = PetscMemzero(ca,(ci[pn]+1)*sizeof(MatScalar));CHKERRQ(ierr);
195 
196   /* put together the new matrix */
197   ierr = MatCreateSeqAIJWithArrays(A->comm,pn,pn,ci,cj,ca,C);CHKERRQ(ierr);
198 
199   /* MatCreateSeqAIJWithArrays flags matrix so PETSc doesn't free the user's arrays. */
200   /* Since these are PETSc arrays, change flags to free them as necessary. */
201   c = (Mat_SeqAIJ *)((*C)->data);
202   c->freedata = PETSC_TRUE;
203   c->nonew    = 0;
204 
205   /* Clean up. */
206   ierr = MatRestoreSymbolicTranspose_SeqAIJ(P,&pti,&ptj);CHKERRQ(ierr);
207 
208   ierr = PetscLogEventEnd(MATSeqAIJ_PtAPSymbolic,A,P,0,0);CHKERRQ(ierr);
209   PetscFunctionReturn(0);
210 }
211 EXTERN_C_END
212 
213 #include "src/mat/impls/maij/maij.h"
214 EXTERN_C_BEGIN
215 #undef __FUNCT__
216 #define __FUNCT__ "MatApplyPtAPSymbolic_SeqAIJ_SeqMAIJ"
217 int MatApplyPtAPSymbolic_SeqAIJ_SeqMAIJ(Mat A,Mat PP,Mat *C) {
218   /* This routine requires testing -- I don't think it works. */
219   int            ierr;
220   FreeSpaceList  free_space=PETSC_NULL,current_space=PETSC_NULL;
221   Mat_SeqMAIJ    *pp=(Mat_SeqMAIJ*)PP->data;
222   Mat            P=pp->AIJ;
223   Mat_SeqAIJ     *a=(Mat_SeqAIJ*)A->data,*p=(Mat_SeqAIJ*)P->data,*c;
224   int            *pti,*ptj,*ptJ,*ai=a->i,*aj=a->j,*ajj,*pi=p->i,*pj=p->j,*pjj;
225   int            *ci,*cj,*denserow,*sparserow,*ptadenserow,*ptasparserow,*ptaj;
226   int            an=A->N,am=A->M,pn=P->N,pm=P->M,ppdof=pp->dof;
227   int            i,j,k,dof,pdof,ptnzi,arow,anzj,ptanzi,prow,pnzj,cnzi;
228   MatScalar      *ca;
229 
230   PetscFunctionBegin;
231   /* Start timer */
232   ierr = PetscLogEventBegin(MATSeqAIJ_PtAPSymbolic,A,PP,0,0);CHKERRQ(ierr);
233 
234   /* Get ij structure of P^T */
235   ierr = MatGetSymbolicTranspose_SeqAIJ(P,&pti,&ptj);CHKERRQ(ierr);
236 
237   /* Allocate ci array, arrays for fill computation and */
238   /* free space for accumulating nonzero column info */
239   ierr = PetscMalloc((pn+1)*sizeof(int),&ci);CHKERRQ(ierr);
240   ci[0] = 0;
241 
242   ierr = PetscMalloc((2*pn+2*an+1)*sizeof(int),&ptadenserow);CHKERRQ(ierr);
243   ierr = PetscMemzero(ptadenserow,(2*pn+2*an+1)*sizeof(int));CHKERRQ(ierr);
244   ptasparserow = ptadenserow  + an;
245   denserow     = ptasparserow + an;
246   sparserow    = denserow     + pn;
247 
248   /* Set initial free space to be nnz(A) scaled by aspect ratio of P. */
249   /* This should be reasonable if sparsity of PtAP is similar to that of A. */
250   ierr          = GetMoreSpace((ai[am]/pm)*pn,&free_space);
251   current_space = free_space;
252 
253   /* Determine symbolic info for each row of C: */
254   for (i=0;i<pn/ppdof;i++) {
255     ptnzi  = pti[i+1] - pti[i];
256     ptanzi = 0;
257     ptJ    = ptj + pti[i];
258     for (dof=0;dof<ppdof;dof++) {
259     /* Determine symbolic row of PtA: */
260       for (j=0;j<ptnzi;j++) {
261         arow = ptJ[j] + dof;
262         anzj = ai[arow+1] - ai[arow];
263         ajj  = aj + ai[arow];
264         for (k=0;k<anzj;k++) {
265           if (!ptadenserow[ajj[k]]) {
266             ptadenserow[ajj[k]]    = -1;
267             ptasparserow[ptanzi++] = ajj[k];
268           }
269         }
270       }
271       /* Using symbolic info for row of PtA, determine symbolic info for row of C: */
272       ptaj = ptasparserow;
273       cnzi   = 0;
274       for (j=0;j<ptanzi;j++) {
275         pdof = *ptaj%dof;
276         prow = (*ptaj++)/dof;
277         pnzj = pi[prow+1] - pi[prow];
278         pjj  = pj + pi[prow];
279         for (k=0;k<pnzj;k++) {
280           if (!denserow[pjj[k]+pdof]) {
281             denserow[pjj[k]+pdof] = -1;
282             sparserow[cnzi++]     = pjj[k]+pdof;
283           }
284         }
285       }
286 
287       /* sort sparserow */
288       ierr = PetscSortInt(cnzi,sparserow);CHKERRQ(ierr);
289 
290       /* If free space is not available, make more free space */
291       /* Double the amount of total space in the list */
292       if (current_space->local_remaining<cnzi) {
293         ierr = GetMoreSpace(current_space->total_array_size,&current_space);CHKERRQ(ierr);
294       }
295 
296       /* Copy data into free space, and zero out denserows */
297       ierr = PetscMemcpy(current_space->array,sparserow,cnzi*sizeof(int));CHKERRQ(ierr);
298       current_space->array           += cnzi;
299       current_space->local_used      += cnzi;
300       current_space->local_remaining -= cnzi;
301 
302       for (j=0;j<ptanzi;j++) {
303         ptadenserow[ptasparserow[j]] = 0;
304       }
305       for (j=0;j<cnzi;j++) {
306         denserow[sparserow[j]] = 0;
307       }
308       /* Aside: Perhaps we should save the pta info for the numerical factorization. */
309       /*        For now, we will recompute what is needed. */
310       ci[i+1+dof] = ci[i+dof] + cnzi;
311     }
312   }
313   /* nnz is now stored in ci[ptm], column indices are in the list of free space */
314   /* Allocate space for cj, initialize cj, and */
315   /* destroy list of free space and other temporary array(s) */
316   ierr = PetscMalloc((ci[pn]+1)*sizeof(int),&cj);CHKERRQ(ierr);
317   ierr = MakeSpaceContiguous(&free_space,cj);CHKERRQ(ierr);
318   ierr = PetscFree(ptadenserow);CHKERRQ(ierr);
319 
320   /* Allocate space for ca */
321   ierr = PetscMalloc((ci[pn]+1)*sizeof(MatScalar),&ca);CHKERRQ(ierr);
322   ierr = PetscMemzero(ca,(ci[pn]+1)*sizeof(MatScalar));CHKERRQ(ierr);
323 
324   /* put together the new matrix */
325   ierr = MatCreateSeqAIJWithArrays(A->comm,pn,pn,ci,cj,ca,C);CHKERRQ(ierr);
326 
327   /* MatCreateSeqAIJWithArrays flags matrix so PETSc doesn't free the user's arrays. */
328   /* Since these are PETSc arrays, change flags to free them as necessary. */
329   c = (Mat_SeqAIJ *)((*C)->data);
330   c->freedata = PETSC_TRUE;
331   c->nonew    = 0;
332 
333   /* Clean up. */
334   ierr = MatRestoreSymbolicTranspose_SeqAIJ(P,&pti,&ptj);CHKERRQ(ierr);
335 
336   ierr = PetscLogEventEnd(MATSeqAIJ_PtAPSymbolic,A,PP,0,0);CHKERRQ(ierr);
337   PetscFunctionReturn(0);
338 }
339 EXTERN_C_END
340 
341 /*
342      MatSeqAIJPtAPNumeric - Computes the SeqAIJ matrix product, C,
343            of SeqAIJ matrix A and matrix P, according to:
344                  C = P^T * A * P
345      Note: C must have been created by calling MatSeqAIJApplyPtAPSymbolic.
346 */
347 #undef __FUNCT__
348 #define __FUNCT__ "MatSeqAIJPtAPNumeric"
349 int MatSeqAIJPtAPNumeric(Mat A,Mat P,Mat C) {
350   int ierr;
351   char funct[80];
352 
353   PetscFunctionBegin;
354 
355   PetscValidHeaderSpecific(A,MAT_COOKIE);
356   PetscValidType(A);
357   MatPreallocated(A);
358   if (!A->assembled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");
359   if (A->factor) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for factored matrix");
360 
361   PetscValidHeaderSpecific(P,MAT_COOKIE);
362   PetscValidType(P);
363   MatPreallocated(P);
364   if (!P->assembled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");
365   if (P->factor) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for factored matrix");
366 
367   PetscValidHeaderSpecific(C,MAT_COOKIE);
368   PetscValidType(C);
369   MatPreallocated(C);
370   if (!C->assembled) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");
371   if (C->factor) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for factored matrix");
372 
373   if (P->N!=C->M) SETERRQ2(PETSC_ERR_ARG_SIZ,"Matrix dimensions are incompatible, %d != %d",P->N,C->M);
374   if (P->M!=A->N) SETERRQ2(PETSC_ERR_ARG_SIZ,"Matrix dimensions are incompatible, %d != %d",P->M,A->N);
375   if (A->M!=A->N) SETERRQ2(PETSC_ERR_ARG_SIZ,"Matrix 'A' must be square, %d != %d",A->M,A->N);
376   if (P->N!=C->N) SETERRQ2(PETSC_ERR_ARG_SIZ,"Matrix dimensions are incompatible, %d != %d",P->N,C->N);
377 
378   /* Query A for ApplyPtAP implementation based on types of P */
379   ierr = PetscStrcpy(funct,"MatApplyPtAPNumeric_seqaij_");CHKERRQ(ierr);
380   ierr = PetscStrcat(funct,P->type_name);CHKERRQ(ierr);
381   ierr = PetscTryMethod(A,funct,(Mat,Mat,Mat),(A,P,C));CHKERRQ(ierr);
382 
383   PetscFunctionReturn(0);
384 }
385 
386 EXTERN_C_BEGIN
387 #undef __FUNCT__
388 #define __FUNCT__ "MatApplyPtAPNumeric_SeqAIJ_SeqAIJ"
389 int MatApplyPtAPNumeric_SeqAIJ_SeqAIJ(Mat A,Mat P,Mat C) {
390   int        ierr,flops=0;
391   Mat_SeqAIJ *a  = (Mat_SeqAIJ *) A->data;
392   Mat_SeqAIJ *p  = (Mat_SeqAIJ *) P->data;
393   Mat_SeqAIJ *c  = (Mat_SeqAIJ *) C->data;
394   int        *ai=a->i,*aj=a->j,*apj,*apjdense,*pi=p->i,*pj=p->j,*pJ=p->j,*pjj;
395   int        *ci=c->i,*cj=c->j,*cjj;
396   int        am=A->M,cn=C->N,cm=C->M;
397   int        i,j,k,anzi,pnzi,apnzj,nextap,pnzj,prow,crow;
398   MatScalar  *aa=a->a,*apa,*pa=p->a,*pA=p->a,*paj,*ca=c->a,*caj;
399 
400   PetscFunctionBegin;
401   ierr = PetscLogEventBegin(MATSeqAIJ_PtAPNumeric,A,P,C,0);CHKERRQ(ierr);
402 
403   /* Allocate temporary array for storage of one row of A*P */
404   ierr = PetscMalloc(cn*(sizeof(MatScalar)+2*sizeof(int)),&apa);CHKERRQ(ierr);
405   ierr = PetscMemzero(apa,cn*(sizeof(MatScalar)+2*sizeof(int)));CHKERRQ(ierr);
406 
407   apj      = (int *)(apa + cn);
408   apjdense = apj + cn;
409 
410   /* Clear old values in C */
411   ierr = PetscMemzero(ca,ci[cm]*sizeof(MatScalar));CHKERRQ(ierr);
412 
413   for (i=0;i<am;i++) {
414     /* Form sparse row of A*P */
415     anzi  = ai[i+1] - ai[i];
416     apnzj = 0;
417     for (j=0;j<anzi;j++) {
418       prow = *aj++;
419       pnzj = pi[prow+1] - pi[prow];
420       pjj  = pj + pi[prow];
421       paj  = pa + pi[prow];
422       for (k=0;k<pnzj;k++) {
423         if (!apjdense[pjj[k]]) {
424           apjdense[pjj[k]] = -1;
425           apj[apnzj++]     = pjj[k];
426         }
427         apa[pjj[k]] += (*aa)*paj[k];
428       }
429       flops += 2*pnzj;
430       aa++;
431     }
432 
433     /* Sort the j index array for quick sparse axpy. */
434     ierr = PetscSortInt(apnzj,apj);CHKERRQ(ierr);
435 
436     /* Compute P^T*A*P using outer product (P^T)[:,j]*(A*P)[j,:]. */
437     pnzi = pi[i+1] - pi[i];
438     for (j=0;j<pnzi;j++) {
439       nextap = 0;
440       crow   = *pJ++;
441       cjj    = cj + ci[crow];
442       caj    = ca + ci[crow];
443       /* Perform sparse axpy operation.  Note cjj includes apj. */
444       for (k=0;nextap<apnzj;k++) {
445         if (cjj[k]==apj[nextap]) {
446           caj[k] += (*pA)*apa[apj[nextap++]];
447         }
448       }
449       flops += 2*apnzj;
450       pA++;
451     }
452 
453     /* Zero the current row info for A*P */
454     for (j=0;j<apnzj;j++) {
455       apa[apj[j]]      = 0.;
456       apjdense[apj[j]] = 0;
457     }
458   }
459 
460   /* Assemble the final matrix and clean up */
461   ierr = MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
462   ierr = MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
463   ierr = PetscFree(apa);CHKERRQ(ierr);
464   ierr = PetscLogFlops(flops);CHKERRQ(ierr);
465   ierr = PetscLogEventEnd(MATSeqAIJ_PtAPNumeric,A,P,C,0);CHKERRQ(ierr);
466 
467   PetscFunctionReturn(0);
468 }
469 EXTERN_C_END
470 
471 #undef __FUNCT__
472 #define __FUNCT__ "RegisterApplyPtAPRoutines_Private"
473 int RegisterApplyPtAPRoutines_Private(Mat A) {
474   int ierr;
475 
476   PetscFunctionBegin;
477 
478   if (!MATSeqAIJ_PtAP) {
479     ierr = PetscLogEventRegister(&MATSeqAIJ_PtAP,"MatSeqAIJApplyPtAP",MAT_COOKIE);CHKERRQ(ierr);
480   }
481 
482   if (!MATSeqAIJ_PtAPSymbolic) {
483     ierr = PetscLogEventRegister(&MATSeqAIJ_PtAPSymbolic,"MatSeqAIJApplyPtAPSymbolic",MAT_COOKIE);CHKERRQ(ierr);
484   }
485   ierr = PetscObjectComposeFunctionDynamic((PetscObject)A,"MatApplyPtAPSymbolic_seqaij_seqaij",
486                                            "MatApplyPtAPSymbolic_SeqAIJ_SeqAIJ",
487                                            MatApplyPtAPSymbolic_SeqAIJ_SeqAIJ);CHKERRQ(ierr);
488 
489   if (!MATSeqAIJ_PtAPNumeric) {
490     ierr = PetscLogEventRegister(&MATSeqAIJ_PtAPNumeric,"MatSeqAIJApplyPtAPNumeric",MAT_COOKIE);CHKERRQ(ierr);
491   }
492   ierr = PetscObjectComposeFunctionDynamic((PetscObject)A,"MatApplyPtAPNumeric_seqaij_seqaij",
493                                            "MatApplyPtAPNumeric_SeqAIJ_SeqAIJ",
494                                            MatApplyPtAPNumeric_SeqAIJ_SeqAIJ);CHKERRQ(ierr);
495   ierr = RegisterMatMatMultRoutines_Private(A);CHKERRQ(ierr);
496   PetscFunctionReturn(0);
497 }
498