xref: /petsc/src/mat/interface/ftn-custom/zmatrixf.c (revision 1b37a2a7cc4a4fb30c3e967db1c694c0a1013f51)
1 #include <petsc/private/fortranimpl.h>
2 #include <petsc/private/f90impl.h>
3 #include <petscmat.h>
4 #include <petscviewer.h>
5 
6 #if defined(PETSC_HAVE_FORTRAN_CAPS)
7   #define matgetvalues_                MATGETVALUES
8   #define matgetvalues0_               MATGETVALUES0
9   #define matgetvaluesnn1_             MATGETVALUESnn1
10   #define matgetvaluesnnnn_            MATGETVALUESnnnn
11   #define matgetvalues11_              MATGETVALUES11
12   #define matgetvalues11a_             MATGETVALUES11A
13   #define matgetvalues1n_              MATGETVALUES1N
14   #define matgetvaluesn1_              MATGETVALUESN1
15   #define matgetvalueslocal_           MATGETVALUESLOCAL
16   #define matgetvalueslocal0_          MATGETVALUESLOCAL0
17   #define matgetvalueslocalnn1_        MATGETVALUESLOCALNN1
18   #define matgetvalueslocalnnnn_       MATGETVALUESLOCALNNNN
19   #define matgetvalueslocal11_         MATGETVALUESLOCAL11
20   #define matgetvalueslocal11a_        MATGETVALUESLOCAL11A
21   #define matgetvalueslocal1n_         MATGETVALUESLOCAL1N
22   #define matgetvalueslocaln1_         MATGETVALUESLOCALN1
23   #define matsetvalues_                MATSETVALUES
24   #define matsetvaluesnnnn_            MATSETVALUESNNNN
25   #define matsetvalues0_               MATSETVALUES0
26   #define matsetvaluesnn1_             MATSETVALUESNN1
27   #define matsetvalues11_              MATSETVALUES11
28   #define matsetvalues1n_              MATSETVALUES1N
29   #define matsetvaluesn1_              MATSETVALUESN1
30   #define matsetvaluesblocked0_        MATSETVALUESBLOCKED0
31   #define matsetvaluesblocked2_        MATSETVALUESBLOCKED2
32   #define matsetvaluesblocked11_       MATSETVALUESBLOCKED11
33   #define matsetvaluesblocked111_      MATSETVALUESBLOCKED111
34   #define matsetvaluesblocked1n_       MATSETVALUESBLOCKED1N
35   #define matsetvaluesblockedn1_       MATSETVALUESBLOCKEDN1
36   #define matsetvaluesblockedlocal_    MATSETVALUESBLOCKEDLOCAL
37   #define matsetvaluesblockedlocal0_   MATSETVALUESBLOCKEDLOCAL0
38   #define matsetvaluesblockedlocal11_  MATSETVALUESBLOCKEDLOCAL11
39   #define matsetvaluesblockedlocal111_ MATSETVALUESBLOCKEDLOCAL111
40   #define matsetvaluesblockedlocal1n_  MATSETVALUESBLOCKEDLOCAL1N
41   #define matsetvaluesblockedlocaln1_  MATSETVALUESBLOCKEDLOCALN1
42   #define matsetvalueslocal_           MATSETVALUESLOCAL
43   #define matsetvalueslocal0_          MATSETVALUESLOCAL0
44   #define matsetvalueslocal11_         MATSETVALUESLOCAL11
45   #define matsetvalueslocal11nn_       MATSETVALUESLOCAL11NN
46   #define matsetvalueslocal111_        MATSETVALUESLOCAL111
47   #define matsetvalueslocal1n_         MATSETVALUESLOCAL1N
48   #define matsetvalueslocaln1_         MATSETVALUESLOCALN1
49   #define matgetrowmin_                MATGETROWMIN
50   #define matgetrowminabs_             MATGETROWMINABS
51   #define matgetrowmax_                MATGETROWMAX
52   #define matgetrowmaxabs_             MATGETROWMAXABS
53   #define matdestroymatrices_          MATDESTROYMATRICES
54   #define matdestroysubmatrices_       MATDESTROYSUBMATRICES
55   #define matgetfactor_                MATGETFACTOR
56   #define matfactorgetsolverpackage_   MATFACTORGETSOLVERPACKAGE
57   #define matgetrowij_                 MATGETROWIJ
58   #define matrestorerowij_             MATRESTOREROWIJ
59   #define matgetrow_                   MATGETROW
60   #define matrestorerow_               MATRESTOREROW
61   #define matload_                     MATLOAD
62   #define matview_                     MATVIEW
63   #define matseqaijgetarray_           MATSEQAIJGETARRAY
64   #define matseqaijrestorearray_       MATSEQAIJRESTOREARRAY
65   #define matdensegetarray_            MATDENSEGETARRAY
66   #define matdensegetarrayread_        MATDENSEGETARRAYREAD
67   #define matdenserestorearray_        MATDENSERESTOREARRAY
68   #define matdenserestorearrayread_    MATDENSERESTOREARRAYREAD
69   #define matconvert_                  MATCONVERT
70   #define matcreatesubmatrices_        MATCREATESUBMATRICES
71   #define matcreatesubmatricesmpi_     MATCREATESUBMATRICESMPI
72   #define matzerorowscolumns_          MATZEROROWSCOLUMNS
73   #define matzerorowscolumnsis_        MATZEROROWSCOLUMNSIS
74   #define matzerorowsstencil_          MATZEROROWSSTENCIL
75   #define matzerorowscolumnsstencil_   MATZEROROWSCOLUMNSSTENCIL
76   #define matzerorows_                 MATZEROROWS
77   #define matzerorowsis_               MATZEROROWSIS
78   #define matzerorowslocal_            MATZEROROWSLOCAL
79   #define matzerorowslocal0_           MATZEROROWSLOCAL0
80   #define matzerorowslocal1_           MATZEROROWSLOCAL1
81   #define matzerorowslocalis_          MATZEROROWSLOCALIS
82   #define matzerorowscolumnslocal_     MATZEROROWSCOLUMNSLOCAL
83   #define matzerorowscolumnslocalis_   MATZEROROWSCOLUMNSLOCALIS
84   #define matsetoptionsprefix_         MATSETOPTIONSPREFIX
85   #define matcreatevecs_               MATCREATEVECS
86   #define matnullspaceremove_          MATNULLSPACEREMOVE
87   #define matgetinfo_                  MATGETINFO
88   #define matlufactor_                 MATLUFACTOR
89   #define matilufactor_                MATILUFACTOR
90   #define matlufactorsymbolic_         MATLUFACTORSYMBOLIC
91   #define matlufactornumeric_          MATLUFACTORNUMERIC
92   #define matcholeskyfactor_           MATCHOLESKYFACTOR
93   #define matcholeskyfactorsymbolic_   MATCHOLESKYFACTORSYMBOLIC
94   #define matcholeskyfactornumeric_    MATCHOLESKYFACTORNUMERIC
95   #define matilufactorsymbolic_        MATILUFACTORSYMBOLIC
96   #define maticcfactorsymbolic_        MATICCFACTORSYMBOLIC
97   #define maticcfactor_                MATICCFACTOR
98   #define matfactorinfoinitialize_     MATFACTORINFOINITIALIZE
99   #define matnullspacesetfunction_     MATNULLSPACESETFUNCTION
100   #define matfindnonzerorows_          MATFINDNONZEROROWS
101   #define matgetsize_                  MATGETSIZE
102   #define matgetsize00_                MATGETSIZE00
103   #define matgetsize10_                MATGETSIZE10
104   #define matgetsize01_                MATGETSIZE01
105   #define matgetlocalsize_             MATGETLOCALSIZE
106   #define matgetlocalsize00_           MATGETLOCALSIZE00
107   #define matgetlocalsize10_           MATGETLOCALSIZE10
108   #define matgetlocalsize01_           MATGETLOCALSIZE01
109   #define matsetnullspace_             MATSETNULLSPACE
110   #define matgetownershiprange_        MATGETOWNERSHIPRANGE
111   #define matgetownershiprange00_      MATGETOWNERSHIPRANGE00
112   #define matgetownershiprange10_      MATGETOWNERSHIPRANGE10
113   #define matgetownershiprange01_      MATGETOWNERSHIPRANGE01
114   #define matgetownershiprange11_      MATGETOWNERSHIPRANGE11
115   #define matgetownershipis_           MATGETOWNERSHIPIS
116   #define matgetownershiprangecolumn_  MATGETOWNERSHIPRANGECOLUMN
117   #define matviewfromoptions_          MATVIEWFROMOPTIONS
118   #define matdestroy_                  MATDESTROY
119   #define matcreatefromoptions_        MATCREATEFROMOPTIONS
120 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
121   #define matsetvalues_                matsetvalues
122   #define matsetvaluesnnnn_            matsetvaluesnnnn
123   #define matsetvalues0_               matsetvalues0
124   #define matsetvaluesnn1_             matsetvaluesnn1
125   #define matsetvalues11_              matsetvalues11
126   #define matsetvaluesn1_              matsetvaluesn1
127   #define matsetvalues1n_              matsetvalues1n
128   #define matsetvalueslocal_           matsetvalueslocal
129   #define matsetvalueslocal0_          matsetvalueslocal0
130   #define matsetvalueslocal11_         matsetvalueslocal11
131   #define matsetvalueslocal11nn_       matsetvalueslocal11nn
132   #define matsetvalueslocal111_        matsetvalueslocal111
133   #define matsetvalueslocal1n_         matsetvalueslocal1n
134   #define matsetvalueslocaln1_         matsetvalueslocaln1
135   #define matsetvaluesblocked_         matsetvaluesblocked
136   #define matsetvaluesblocked0_        matsetvaluesblocked0
137   #define matsetvaluesblocked2_        matsetvaluesblocked2
138   #define matsetvaluesblocked11_       matsetvaluesblocked11
139   #define matsetvaluesblocked111_      matsetvaluesblocked111
140   #define matsetvaluesblocked1n_       matsetvaluesblocked1n
141   #define matsetvaluesblockedn1_       matsetvaluesblockedn1
142   #define matsetvaluesblockedlocal_    matsetvaluesblockedlocal
143   #define matsetvaluesblockedlocal0_   matsetvaluesblockedlocal0
144   #define matsetvaluesblockedlocal11_  matsetvaluesblockedlocal11
145   #define matsetvaluesblockedlocal111_ matsetvaluesblockedlocal111
146   #define matsetvaluesblockedlocal1n_  matsetvaluesblockedlocal1n
147   #define matsetvaluesblockedlocaln1_  matsetvaluesblockedlocaln1
148   #define matgetrowmin_                matgetrowmin
149   #define matgetrowminabs_             matgetrowminabs
150   #define matgetrowmax_                matgetrowmax
151   #define matgetrowmaxabs_             matgetrowmaxabs
152   #define matdestroymatrices_          matdestroymatrices
153   #define matdestroysubmatrices_       matdestroysubmatrices
154   #define matgetfactor_                matgetfactor
155   #define matfactorgetsolverpackage_   matfactorgetsolverpackage
156   #define matcreatevecs_               matcreatevecs
157   #define matgetrowij_                 matgetrowij
158   #define matrestorerowij_             matrestorerowij
159   #define matgetrow_                   matgetrow
160   #define matrestorerow_               matrestorerow
161   #define matview_                     matview
162   #define matload_                     matload
163   #define matseqaijgetarray_           matseqaijgetarray
164   #define matseqaijrestorearray_       matseqaijrestorearray
165   #define matdensegetarray_            matdensegetarray
166   #define matdensegetarrayread_        matdensegetarrayread
167   #define matdenserestorearray_        matdenserestorearray
168   #define matdenserestorearrayread_    matdenserestorearrayread
169   #define matconvert_                  matconvert
170   #define matcreatesubmatrices_        matcreatesubmatrices
171   #define matcreatesubmatricesmpi_     matcreatesubmatricesmpi
172   #define matzerorowscolumns_          matzerorowscolumns
173   #define matzerorowscolumnsis_        matzerorowscolumnsis
174   #define matzerorowsstencil_          matzerorowsstencil
175   #define matzerorowscolumnsstencil_   matzerorowscolumnsstencil
176   #define matzerorows_                 matzerorows
177   #define matzerorowsis_               matzerorowsis
178   #define matzerorowslocal_            matzerorowslocal
179   #define matzerorowslocalis_          matzerorowslocalis
180   #define matzerorowscolumnslocal_     matzerorowscolumnslocal
181   #define matzerorowscolumnslocalis_   matzerorowscolumnslocalis
182   #define matsetoptionsprefix_         matsetoptionsprefix
183   #define matnullspaceremove_          matnullspaceremove
184   #define matgetinfo_                  matgetinfo
185   #define matlufactor_                 matlufactor
186   #define matilufactor_                matilufactor
187   #define matlufactorsymbolic_         matlufactorsymbolic
188   #define matlufactornumeric_          matlufactornumeric
189   #define matcholeskyfactor_           matcholeskyfactor
190   #define matcholeskyfactorsymbolic_   matcholeskyfactorsymbolic
191   #define matcholeskyfactornumeric_    matcholeskyfactornumeric
192   #define matilufactorsymbolic_        matilufactorsymbolic
193   #define maticcfactorsymbolic_        maticcfactorsymbolic
194   #define maticcfactor_                maticcfactor
195   #define matfactorinfoinitialize_     matfactorinfoinitialize
196   #define matnullspacesetfunction_     matnullspacesetfunction
197   #define matfindnonzerorows_          matfindnonzerorows
198   #define matgetsize_                  matgetsize
199   #define matgetsize00_                matgetsize00
200   #define matgetsize10_                matgetsize10
201   #define matgetsize01_                matgetsize01
202   #define matgetlocalsize_             matgetlocalsize
203   #define matgetlocalsize00_           matgetlocalsize00
204   #define matgetlocalsize10_           matgetlocalsize10
205   #define matgetlocalsize01_           matgetlocalsize01
206   #define matgetvalues_                matgetvalues
207   #define matgetvalues0_               matgetvalues0
208   #define matgetvaluesnn1_             matgetvaluesnn1
209   #define matgetvaluesnnnn_            matgetvaluesnnnn
210   #define matgetvalues11_              matgetvalues11
211   #define matgetvalues11a_             matgetvalues11a
212   #define matgetvalues1n_              matgetvalues1n
213   #define matgetvaluesn1_              matgetvaluesn1
214   #define matgetvalueslocal_           matgetvalueslocal
215   #define matgetvalueslocal0_          matgetvalueslocal0
216   #define matgetvalueslocalnn1_        matgetvalueslocalnn1
217   #define matgetvalueslocalnnnn_       matgetvalueslocalnnnn
218   #define matgetvalueslocal11_         matgetvalueslocal11
219   #define matgetvalueslocal1n_         matgetvalueslocal1n
220   #define matgetvalueslocaln1_         matgetvalueslocaln1
221   #define matsetnullspace_             matsetnullspace
222   #define matgetownershiprange_        matgetownershiprange
223   #define matgetownershiprange00_      matgetownershiprange00
224   #define matgetownershiprange10_      matgetownershiprange10
225   #define matgetownershiprange01_      matgetownershiprange01
226   #define matgetownershiprange11_      matgetownershiprange11
227   #define matgetownershipis_           matgetownershipis
228   #define matgetownershiprangecolumn_  matgetownershiprangecolumn
229   #define matviewfromoptions_          matviewfromoptions
230   #define matdestroy_                  matdestroy
231   #define matcreatefromoptions_        matcreatefromoptions
232 #endif
233 
234 PETSC_EXTERN void matcreatefromoptions_(MPI_Fint *comm, char *prefix, PetscInt *bs, PetscInt *m, PetscInt *n, PetscInt *M, PetscInt *N, Mat *A, int *ierr, PETSC_FORTRAN_CHARLEN_T len)
235 {
236   char *fprefix;
237   FIXCHAR(prefix, len, fprefix);
238   *ierr = MatCreateFromOptions(MPI_Comm_f2c(*(comm)), fprefix, *bs, *m, *n, *M, *N, A);
239   if (*ierr) return;
240   FREECHAR(prefix, fprefix);
241 }
242 
243 PETSC_EXTERN void matgetvalues_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
244 {
245   *ierr = MatGetValues(*mat, *m, idxm, *n, idxn, v);
246 }
247 
248 PETSC_EXTERN void matgetvalues0_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
249 {
250   matgetvalues_(mat, m, idxm, n, idxn, v, ierr);
251 }
252 
253 PETSC_EXTERN void matgetvaluesnn1_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
254 {
255   matgetvalues_(mat, m, idxm, n, idxn, v, ierr);
256 }
257 
258 PETSC_EXTERN void matgetvaluesnnnn_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
259 {
260   matgetvalues_(mat, m, idxm, n, idxn, v, ierr);
261 }
262 
263 PETSC_EXTERN void matgetvalues11_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
264 {
265   matgetvalues_(mat, m, idxm, n, idxn, v, ierr);
266 }
267 
268 PETSC_EXTERN void matgetvalues11a_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
269 {
270   matgetvalues_(mat, m, idxm, n, idxn, v, ierr);
271 }
272 
273 PETSC_EXTERN void matgetvalues1n_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
274 {
275   matgetvalues_(mat, m, idxm, n, idxn, v, ierr);
276 }
277 
278 PETSC_EXTERN void matgetvaluesn1_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
279 {
280   matgetvalues_(mat, m, idxm, n, idxn, v, ierr);
281 }
282 
283 PETSC_EXTERN void matgetvalueslocal_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
284 {
285   *ierr = MatGetValuesLocal(*mat, *m, idxm, *n, idxn, v);
286 }
287 
288 PETSC_EXTERN void matgetvalueslocal0_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
289 {
290   matgetvalueslocal_(mat, m, idxm, n, idxn, v, ierr);
291 }
292 
293 PETSC_EXTERN void matgetvalueslocalnn1_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
294 {
295   matgetvalueslocal_(mat, m, idxm, n, idxn, v, ierr);
296 }
297 
298 PETSC_EXTERN void matgetvalueslocalnnnn_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
299 {
300   matgetvalueslocal_(mat, m, idxm, n, idxn, v, ierr);
301 }
302 
303 PETSC_EXTERN void matgetvalueslocal11_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
304 {
305   matgetvalueslocal_(mat, m, idxm, n, idxn, v, ierr);
306 }
307 
308 PETSC_EXTERN void matgetvalueslocal11a_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
309 {
310   matgetvalueslocal_(mat, m, idxm, n, idxn, v, ierr);
311 }
312 
313 PETSC_EXTERN void matgetvalueslocal1n_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
314 {
315   matgetvalueslocal_(mat, m, idxm, n, idxn, v, ierr);
316 }
317 
318 PETSC_EXTERN void matgetvalueslocaln1_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], int *ierr)
319 {
320   matgetvalueslocal_(mat, m, idxm, n, idxn, v, ierr);
321 }
322 
323 PETSC_EXTERN void matgetownershiprange_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
324 {
325   CHKFORTRANNULLINTEGER(m);
326   CHKFORTRANNULLINTEGER(n);
327   *ierr = MatGetOwnershipRange(*mat, m, n);
328 }
329 
330 PETSC_EXTERN void matgetownershiprange00_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
331 {
332   CHKFORTRANNULLINTEGER(m);
333   CHKFORTRANNULLINTEGER(n);
334   *ierr = MatGetOwnershipRange(*mat, m, n);
335 }
336 
337 PETSC_EXTERN void matgetownershiprange10_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
338 {
339   CHKFORTRANNULLINTEGER(m);
340   CHKFORTRANNULLINTEGER(n);
341   *ierr = MatGetOwnershipRange(*mat, m, n);
342 }
343 
344 PETSC_EXTERN void matgetownershiprange01_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
345 {
346   CHKFORTRANNULLINTEGER(m);
347   CHKFORTRANNULLINTEGER(n);
348   *ierr = MatGetOwnershipRange(*mat, m, n);
349 }
350 
351 PETSC_EXTERN void matgetownershiprange11_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
352 {
353   CHKFORTRANNULLINTEGER(m);
354   CHKFORTRANNULLINTEGER(n);
355   *ierr = MatGetOwnershipRange(*mat, m, n);
356 }
357 
358 PETSC_EXTERN void matgetownershipis_(Mat *mat, IS *m, IS *n, int *ierr)
359 {
360   CHKFORTRANNULLOBJECT(m);
361   CHKFORTRANNULLOBJECT(n);
362   *ierr = MatGetOwnershipIS(*mat, m, n);
363 }
364 
365 PETSC_EXTERN void matgetownershiprangecolumn_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
366 {
367   CHKFORTRANNULLINTEGER(m);
368   CHKFORTRANNULLINTEGER(n);
369   *ierr = MatGetOwnershipRangeColumn(*mat, m, n);
370 }
371 
372 PETSC_EXTERN void matgetsize_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
373 {
374   CHKFORTRANNULLINTEGER(m);
375   CHKFORTRANNULLINTEGER(n);
376   *ierr = MatGetSize(*mat, m, n);
377 }
378 
379 PETSC_EXTERN void matgetsize00_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
380 {
381   matgetsize_(mat, m, n, ierr);
382 }
383 
384 PETSC_EXTERN void matgetsize10_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
385 {
386   matgetsize_(mat, m, n, ierr);
387 }
388 
389 PETSC_EXTERN void matgetsize01_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
390 {
391   matgetsize_(mat, m, n, ierr);
392 }
393 
394 PETSC_EXTERN void matgetlocalsize_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
395 {
396   CHKFORTRANNULLINTEGER(m);
397   CHKFORTRANNULLINTEGER(n);
398   *ierr = MatGetLocalSize(*mat, m, n);
399 }
400 
401 PETSC_EXTERN void matgetlocalsize00_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
402 {
403   matgetlocalsize_(mat, m, n, ierr);
404 }
405 
406 PETSC_EXTERN void matgetlocalsize10_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
407 {
408   matgetlocalsize_(mat, m, n, ierr);
409 }
410 
411 PETSC_EXTERN void matgetlocalsize01_(Mat *mat, PetscInt *m, PetscInt *n, int *ierr)
412 {
413   matgetlocalsize_(mat, m, n, ierr);
414 }
415 
416 PETSC_EXTERN void matsetvaluesblocked_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
417 {
418   *ierr = MatSetValuesBlocked(*mat, *m, idxm, *n, idxn, v, *addv);
419 }
420 
421 PETSC_EXTERN void matsetvaluesblocked2_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], F90Array2d *y, InsertMode *addv, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
422 {
423   PetscScalar *fa;
424   *ierr = F90Array2dAccess(y, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
425   if (*ierr) return;
426   matsetvaluesblocked_(mat, m, idxm, n, idxn, fa, addv, ierr);
427 }
428 
429 PETSC_EXTERN void matsetvaluesblocked0_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
430 {
431   matsetvaluesblocked_(mat, m, idxm, n, idxn, v, addv, ierr);
432 }
433 
434 PETSC_EXTERN void matsetvaluesblocked11_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
435 {
436   matsetvaluesblocked_(mat, m, idxm, n, idxn, v, addv, ierr);
437 }
438 
439 PETSC_EXTERN void matsetvaluesblocked111_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
440 {
441   matsetvaluesblocked_(mat, m, idxm, n, idxn, v, addv, ierr);
442 }
443 
444 PETSC_EXTERN void matsetvaluesblocked1n_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
445 {
446   matsetvaluesblocked_(mat, m, idxm, n, idxn, v, addv, ierr);
447 }
448 
449 PETSC_EXTERN void matsetvaluesblockedn1_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
450 {
451   matsetvaluesblocked_(mat, m, idxm, n, idxn, v, addv, ierr);
452 }
453 
454 PETSC_EXTERN void matsetvaluesblockedlocal_(Mat *mat, PetscInt *nrow, PetscInt irow[], PetscInt *ncol, PetscInt icol[], PetscScalar y[], InsertMode *addv, int *ierr)
455 {
456   *ierr = MatSetValuesBlockedLocal(*mat, *nrow, irow, *ncol, icol, y, *addv);
457 }
458 
459 PETSC_EXTERN void matsetvaluesblockedlocal0_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
460 {
461   matsetvaluesblockedlocal_(mat, m, idxm, n, idxn, v, addv, ierr);
462 }
463 
464 PETSC_EXTERN void matsetvaluesblockedlocal11_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
465 {
466   matsetvaluesblockedlocal_(mat, m, idxm, n, idxn, v, addv, ierr);
467 }
468 
469 PETSC_EXTERN void matsetvaluesblockedlocal111_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
470 {
471   matsetvaluesblockedlocal_(mat, m, idxm, n, idxn, v, addv, ierr);
472 }
473 
474 PETSC_EXTERN void matsetvaluesblockedlocal1n_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
475 {
476   matsetvaluesblockedlocal_(mat, m, idxm, n, idxn, v, addv, ierr);
477 }
478 
479 PETSC_EXTERN void matsetvaluesblockedlocaln1_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
480 {
481   matsetvaluesblockedlocal_(mat, m, idxm, n, idxn, v, addv, ierr);
482 }
483 
484 PETSC_EXTERN void matsetvalues_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
485 {
486   *ierr = MatSetValues(*mat, *m, idxm, *n, idxn, v, *addv);
487 }
488 
489 PETSC_EXTERN void matsetvaluesnnnn_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
490 {
491   matsetvalues_(mat, m, idxm, n, idxn, v, addv, ierr);
492 }
493 
494 PETSC_EXTERN void matsetvalues0_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
495 {
496   matsetvalues_(mat, m, idxm, n, idxn, v, addv, ierr);
497 }
498 
499 PETSC_EXTERN void matsetvaluesnn1_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
500 {
501   matsetvalues_(mat, m, idxm, n, idxn, v, addv, ierr);
502 }
503 
504 PETSC_EXTERN void matsetvalues11_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
505 {
506   matsetvalues_(mat, m, idxm, n, idxn, v, addv, ierr);
507 }
508 
509 PETSC_EXTERN void matsetvaluesn1_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
510 {
511   matsetvalues_(mat, m, idxm, n, idxn, v, addv, ierr);
512 }
513 
514 PETSC_EXTERN void matsetvalues1n_(Mat *mat, PetscInt *m, PetscInt idxm[], PetscInt *n, PetscInt idxn[], PetscScalar v[], InsertMode *addv, int *ierr)
515 {
516   matsetvalues_(mat, m, idxm, n, idxn, v, addv, ierr);
517 }
518 
519 PETSC_EXTERN void matsetvalueslocal_(Mat *mat, PetscInt *nrow, PetscInt irow[], PetscInt *ncol, PetscInt icol[], PetscScalar y[], InsertMode *addv, int *ierr)
520 {
521   *ierr = MatSetValuesLocal(*mat, *nrow, irow, *ncol, icol, y, *addv);
522 }
523 
524 PETSC_EXTERN void matsetvalueslocal0_(Mat *mat, PetscInt *nrow, PetscInt irow[], PetscInt *ncol, PetscInt icol[], PetscScalar y[], InsertMode *addv, int *ierr)
525 {
526   matsetvalueslocal_(mat, nrow, irow, ncol, icol, y, addv, ierr);
527 }
528 
529 PETSC_EXTERN void matsetvalueslocal11_(Mat *mat, PetscInt *nrow, PetscInt irow[], PetscInt *ncol, PetscInt icol[], PetscScalar y[], InsertMode *addv, int *ierr)
530 {
531   matsetvalueslocal_(mat, nrow, irow, ncol, icol, y, addv, ierr);
532 }
533 
534 PETSC_EXTERN void matsetvalueslocal11nn_(Mat *mat, PetscInt *nrow, PetscInt irow[], PetscInt *ncol, PetscInt icol[], PetscScalar y[], InsertMode *addv, int *ierr)
535 {
536   matsetvalueslocal_(mat, nrow, irow, ncol, icol, y, addv, ierr);
537 }
538 
539 PETSC_EXTERN void matsetvalueslocal111_(Mat *mat, PetscInt *nrow, PetscInt irow[], PetscInt *ncol, PetscInt icol[], PetscScalar y[], InsertMode *addv, int *ierr)
540 {
541   matsetvalueslocal_(mat, nrow, irow, ncol, icol, y, addv, ierr);
542 }
543 
544 PETSC_EXTERN void matsetvalueslocal1n_(Mat *mat, PetscInt *nrow, PetscInt irow[], PetscInt *ncol, PetscInt icol[], PetscScalar y[], InsertMode *addv, int *ierr)
545 {
546   matsetvalueslocal_(mat, nrow, irow, ncol, icol, y, addv, ierr);
547 }
548 
549 PETSC_EXTERN void matsetvalueslocaln1_(Mat *mat, PetscInt *nrow, PetscInt irow[], PetscInt *ncol, PetscInt icol[], PetscScalar y[], InsertMode *addv, int *ierr)
550 {
551   matsetvalueslocal_(mat, nrow, irow, ncol, icol, y, addv, ierr);
552 }
553 
554 PETSC_EXTERN void matgetrowmin_(Mat *mat, Vec *v, PetscInt idx[], int *ierr)
555 {
556   CHKFORTRANNULLINTEGER(idx);
557   *ierr = MatGetRowMin(*mat, *v, idx);
558 }
559 
560 PETSC_EXTERN void matgetrowminabs_(Mat *mat, Vec *v, PetscInt idx[], int *ierr)
561 {
562   CHKFORTRANNULLINTEGER(idx);
563   *ierr = MatGetRowMinAbs(*mat, *v, idx);
564 }
565 
566 PETSC_EXTERN void matgetrowmax_(Mat *mat, Vec *v, PetscInt idx[], int *ierr)
567 {
568   CHKFORTRANNULLINTEGER(idx);
569   *ierr = MatGetRowMax(*mat, *v, idx);
570 }
571 
572 PETSC_EXTERN void matgetrowmaxabs_(Mat *mat, Vec *v, PetscInt idx[], int *ierr)
573 {
574   CHKFORTRANNULLINTEGER(idx);
575   *ierr = MatGetRowMaxAbs(*mat, *v, idx);
576 }
577 
578 static PetscErrorCode ournullfunction(MatNullSpace sp, Vec x, void *ctx)
579 {
580   PetscCallFortranVoidFunction((*(void (*)(MatNullSpace *, Vec *, void *, PetscErrorCode *))(((PetscObject)sp)->fortran_func_pointers[0]))(&sp, &x, ctx, &ierr));
581   return PETSC_SUCCESS;
582 }
583 
584 PETSC_EXTERN void matnullspacesetfunction_(MatNullSpace *sp, PetscErrorCode (*rem)(MatNullSpace, Vec, void *), void *ctx, PetscErrorCode *ierr)
585 {
586   PetscObjectAllocateFortranPointers(*sp, 1);
587   ((PetscObject)*sp)->fortran_func_pointers[0] = (PetscVoidFn *)rem;
588 
589   *ierr = MatNullSpaceSetFunction(*sp, ournullfunction, ctx);
590 }
591 
592 PETSC_EXTERN void matcreatevecs_(Mat *mat, Vec *right, Vec *left, int *ierr)
593 {
594   CHKFORTRANNULLOBJECT(right);
595   CHKFORTRANNULLOBJECT(left);
596   *ierr = MatCreateVecs(*mat, right, left);
597 }
598 
599 PETSC_EXTERN void matgetrowij_(Mat *B, PetscInt *shift, PetscBool *sym, PetscBool *blockcompressed, PetscInt *n, PetscInt *ia, size_t *iia, PetscInt *ja, size_t *jja, PetscBool *done, PetscErrorCode *ierr)
600 {
601   const PetscInt *IA, *JA;
602   *ierr = MatGetRowIJ(*B, *shift, *sym, *blockcompressed, n, &IA, &JA, done);
603   if (*ierr) return;
604   *iia = PetscIntAddressToFortran(ia, (PetscInt *)IA);
605   *jja = PetscIntAddressToFortran(ja, (PetscInt *)JA);
606 }
607 
608 PETSC_EXTERN void matrestorerowij_(Mat *B, PetscInt *shift, PetscBool *sym, PetscBool *blockcompressed, PetscInt *n, PetscInt *ia, size_t *iia, PetscInt *ja, size_t *jja, PetscBool *done, PetscErrorCode *ierr)
609 {
610   const PetscInt *IA = PetscIntAddressFromFortran(ia, *iia), *JA = PetscIntAddressFromFortran(ja, *jja);
611   *ierr = MatRestoreRowIJ(*B, *shift, *sym, *blockcompressed, n, &IA, &JA, done);
612 }
613 
614 /*
615    This is a poor way of storing the column and value pointers
616   generated by MatGetRow() to be returned with MatRestoreRow()
617   but there is not natural,good place else to store them. Hence
618   Fortran programmers can only have one outstanding MatGetRows()
619   at a time.
620 */
621 static int                matgetrowactive = 0;
622 static const PetscInt    *my_ocols        = NULL;
623 static const PetscScalar *my_ovals        = NULL;
624 
625 PETSC_EXTERN void matgetrow_(Mat *mat, PetscInt *row, PetscInt *ncols, PetscInt *cols, PetscScalar *vals, PetscErrorCode *ierr)
626 {
627   const PetscInt    **oocols = &my_ocols;
628   const PetscScalar **oovals = &my_ovals;
629 
630   if (matgetrowactive) {
631     *ierr = PetscError(PETSC_COMM_SELF, __LINE__, "MatGetRow_Fortran", __FILE__, PETSC_ERR_ARG_WRONGSTATE, PETSC_ERROR_INITIAL, "Cannot have two MatGetRow() active simultaneously\n\
632                call MatRestoreRow() before calling MatGetRow() a second time");
633     *ierr = PETSC_ERR_ARG_WRONGSTATE;
634     return;
635   }
636 
637   CHKFORTRANNULLINTEGER(cols);
638   if (!cols) oocols = NULL;
639   CHKFORTRANNULLSCALAR(vals);
640   if (!vals) oovals = NULL;
641 
642   *ierr = MatGetRow(*mat, *row, ncols, oocols, oovals);
643   if (*ierr) return;
644 
645   if (oocols) {
646     *ierr = PetscArraycpy(cols, my_ocols, *ncols);
647     if (*ierr) return;
648   }
649   if (oovals) {
650     *ierr = PetscArraycpy(vals, my_ovals, *ncols);
651     if (*ierr) return;
652   }
653   matgetrowactive = 1;
654 }
655 
656 PETSC_EXTERN void matrestorerow_(Mat *mat, PetscInt *row, PetscInt *ncols, PetscInt *cols, PetscScalar *vals, PetscErrorCode *ierr)
657 {
658   const PetscInt    **oocols = &my_ocols;
659   const PetscScalar **oovals = &my_ovals;
660 
661   if (!matgetrowactive) {
662     *ierr = PetscError(PETSC_COMM_SELF, __LINE__, "MatRestoreRow_Fortran", __FILE__, PETSC_ERR_ARG_WRONGSTATE, PETSC_ERROR_INITIAL, "Must call MatGetRow() first");
663     *ierr = PETSC_ERR_ARG_WRONGSTATE;
664     return;
665   }
666   CHKFORTRANNULLINTEGER(cols);
667   if (!cols) oocols = NULL;
668   CHKFORTRANNULLSCALAR(vals);
669   if (!vals) oovals = NULL;
670 
671   *ierr           = MatRestoreRow(*mat, *row, ncols, oocols, oovals);
672   matgetrowactive = 0;
673 }
674 
675 PETSC_EXTERN void matview_(Mat *mat, PetscViewer *vin, PetscErrorCode *ierr)
676 {
677   PetscViewer v;
678   PetscPatchDefaultViewers_Fortran(vin, v);
679   *ierr = MatView(*mat, v);
680 }
681 
682 PETSC_EXTERN void matload_(Mat *mat, PetscViewer *vin, PetscErrorCode *ierr)
683 {
684   PetscViewer v;
685   PetscPatchDefaultViewers_Fortran(vin, v);
686   *ierr = MatLoad(*mat, v);
687 }
688 
689 PETSC_EXTERN void matseqaijgetarray_(Mat *mat, PetscScalar *fa, size_t *ia, PetscErrorCode *ierr)
690 {
691   PetscScalar *mm;
692   PetscInt     m, n;
693 
694   *ierr = MatSeqAIJGetArray(*mat, &mm);
695   if (*ierr) return;
696   *ierr = MatGetSize(*mat, &m, &n);
697   if (*ierr) return;
698   *ierr = PetscScalarAddressToFortran((PetscObject)*mat, 1, fa, mm, m * n, ia);
699   if (*ierr) return;
700 }
701 
702 PETSC_EXTERN void matseqaijrestorearray_(Mat *mat, PetscScalar *fa, size_t *ia, PetscErrorCode *ierr)
703 {
704   PetscScalar *lx;
705   PetscInt     m, n;
706 
707   *ierr = MatGetSize(*mat, &m, &n);
708   if (*ierr) return;
709   *ierr = PetscScalarAddressFromFortran((PetscObject)*mat, fa, *ia, m * n, &lx);
710   if (*ierr) return;
711   *ierr = MatSeqAIJRestoreArray(*mat, &lx);
712   if (*ierr) return;
713 }
714 
715 PETSC_EXTERN void matdensegetarray_(Mat *mat, PetscScalar *fa, size_t *ia, PetscErrorCode *ierr)
716 {
717   PetscScalar *mm;
718   PetscInt     m, n;
719 
720   *ierr = MatDenseGetArray(*mat, &mm);
721   if (*ierr) return;
722   *ierr = MatGetSize(*mat, &m, &n);
723   if (*ierr) return;
724   *ierr = PetscScalarAddressToFortran((PetscObject)*mat, 1, fa, mm, m * n, ia);
725   if (*ierr) return;
726 }
727 
728 PETSC_EXTERN void matdenserestorearray_(Mat *mat, PetscScalar *fa, size_t *ia, PetscErrorCode *ierr)
729 {
730   PetscScalar *lx;
731   PetscInt     m, n;
732 
733   *ierr = MatGetSize(*mat, &m, &n);
734   if (*ierr) return;
735   *ierr = PetscScalarAddressFromFortran((PetscObject)*mat, fa, *ia, m * n, &lx);
736   if (*ierr) return;
737   *ierr = MatDenseRestoreArray(*mat, &lx);
738   if (*ierr) return;
739 }
740 
741 PETSC_EXTERN void matdensegetarrayread_(Mat *mat, PetscScalar *fa, size_t *ia, PetscErrorCode *ierr)
742 {
743   const PetscScalar *mm;
744   PetscInt           m, n;
745 
746   *ierr = MatDenseGetArrayRead(*mat, &mm);
747   if (*ierr) return;
748   *ierr = MatGetSize(*mat, &m, &n);
749   if (*ierr) return;
750   *ierr = PetscScalarAddressToFortran((PetscObject)*mat, 1, fa, (PetscScalar *)mm, m * n, ia);
751   if (*ierr) return;
752 }
753 
754 PETSC_EXTERN void matdenserestorearrayread_(Mat *mat, PetscScalar *fa, size_t *ia, PetscErrorCode *ierr)
755 {
756   const PetscScalar *lx;
757   PetscInt           m, n;
758 
759   *ierr = MatGetSize(*mat, &m, &n);
760   if (*ierr) return;
761   *ierr = PetscScalarAddressFromFortran((PetscObject)*mat, fa, *ia, m * n, (PetscScalar **)&lx);
762   if (*ierr) return;
763   *ierr = MatDenseRestoreArrayRead(*mat, &lx);
764   if (*ierr) return;
765 }
766 
767 PETSC_EXTERN void matfactorgetsolverpackage_(Mat *mat, char *name, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len)
768 {
769   const char *tname;
770 
771   *ierr = MatFactorGetSolverType(*mat, &tname);
772   if (*ierr) return;
773   if (name != PETSC_NULL_CHARACTER_Fortran) {
774     *ierr = PetscStrncpy(name, tname, len);
775     if (*ierr) return;
776   }
777   FIXRETURNCHAR(PETSC_TRUE, name, len);
778 }
779 
780 PETSC_EXTERN void matgetfactor_(Mat *mat, char *outtype, MatFactorType *ftype, Mat *M, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len)
781 {
782   char *t;
783   FIXCHAR(outtype, len, t);
784   *ierr = MatGetFactor(*mat, t, *ftype, M);
785   if (*ierr) return;
786   FREECHAR(outtype, t);
787 }
788 
789 PETSC_EXTERN void matconvert_(Mat *mat, char *outtype, MatReuse *reuse, Mat *M, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len)
790 {
791   char *t;
792   FIXCHAR(outtype, len, t);
793   *ierr = MatConvert(*mat, t, *reuse, M);
794   if (*ierr) return;
795   FREECHAR(outtype, t);
796 }
797 
798 /*
799     MatCreateSubmatrices() is slightly different from C since the
800     Fortran provides the array to hold the submatrix objects,while in C that
801     array is allocated by the MatCreateSubmatrices()
802 */
803 PETSC_EXTERN void matcreatesubmatrices_(Mat *mat, PetscInt *n, IS *isrow, IS *iscol, MatReuse *scall, Mat *smat, PetscErrorCode *ierr)
804 {
805   Mat     *lsmat;
806   PetscInt i;
807 
808   if (*scall == MAT_INITIAL_MATRIX) {
809     *ierr = MatCreateSubMatrices(*mat, *n, isrow, iscol, *scall, &lsmat);
810     for (i = 0; i <= *n; i++) { /* lsmat[*n] might be a dummy matrix for saving data structure */
811       smat[i] = lsmat[i];
812     }
813     *ierr = PetscFree(lsmat);
814   } else {
815     *ierr = MatCreateSubMatrices(*mat, *n, isrow, iscol, *scall, &smat);
816   }
817 }
818 
819 /*
820     MatCreateSubmatrices() is slightly different from C since the
821     Fortran provides the array to hold the submatrix objects,while in C that
822     array is allocated by the MatCreateSubmatrices()
823 */
824 PETSC_EXTERN void matcreatesubmatricesmpi_(Mat *mat, PetscInt *n, IS *isrow, IS *iscol, MatReuse *scall, Mat *smat, PetscErrorCode *ierr)
825 {
826   Mat     *lsmat;
827   PetscInt i;
828 
829   if (*scall == MAT_INITIAL_MATRIX) {
830     *ierr = MatCreateSubMatricesMPI(*mat, *n, isrow, iscol, *scall, &lsmat);
831     for (i = 0; i <= *n; i++) { /* lsmat[*n] might be a dummy matrix for saving data structure */
832       smat[i] = lsmat[i];
833     }
834     *ierr = PetscFree(lsmat);
835   } else {
836     *ierr = MatCreateSubMatricesMPI(*mat, *n, isrow, iscol, *scall, &smat);
837   }
838 }
839 
840 /*
841     MatDestroyMatrices() is slightly different from C since the
842     Fortran does not free the array of matrix objects, while in C that
843     the array is freed
844 */
845 PETSC_EXTERN void matdestroymatrices_(PetscInt *n, Mat *smat, PetscErrorCode *ierr)
846 {
847   PetscInt i;
848 
849   for (i = 0; i < *n; i++) {
850     PETSC_FORTRAN_OBJECT_F_DESTROYED_TO_C_NULL(&smat[i]);
851     *ierr = MatDestroy(&smat[i]);
852     if (*ierr) return;
853     PETSC_FORTRAN_OBJECT_C_NULL_TO_F_DESTROYED(&smat[i]);
854   }
855 }
856 
857 /*
858     MatDestroySubMatrices() is slightly different from C since the
859     Fortran provides the array to hold the submatrix objects, while in C that
860     array is allocated by the MatCreateSubmatrices()
861 */
862 PETSC_EXTERN void matdestroysubmatrices_(PetscInt *n, Mat *smat, PetscErrorCode *ierr)
863 {
864   Mat     *lsmat;
865   PetscInt i;
866 
867   *ierr = PetscMalloc1(*n + 1, &lsmat);
868   for (i = 0; i <= *n; i++) {
869     PETSC_FORTRAN_OBJECT_F_DESTROYED_TO_C_NULL(&smat[i]);
870     lsmat[i] = smat[i];
871   }
872   *ierr = MatDestroySubMatrices(*n, &lsmat);
873   for (i = 0; i <= *n; i++) { PETSC_FORTRAN_OBJECT_C_NULL_TO_F_DESTROYED(&smat[i]); }
874 }
875 
876 PETSC_EXTERN void matdestroy_(Mat *x, int *ierr)
877 {
878   PETSC_FORTRAN_OBJECT_F_DESTROYED_TO_C_NULL(x);
879   *ierr = MatDestroy(x);
880   if (*ierr) return;
881   PETSC_FORTRAN_OBJECT_C_NULL_TO_F_DESTROYED(x);
882 }
883 
884 PETSC_EXTERN void matsetoptionsprefix_(Mat *mat, char *prefix, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len)
885 {
886   char *t;
887 
888   FIXCHAR(prefix, len, t);
889   *ierr = MatSetOptionsPrefix(*mat, t);
890   if (*ierr) return;
891   FREECHAR(prefix, t);
892 }
893 
894 PETSC_EXTERN void matnullspaceremove_(MatNullSpace *sp, Vec *vec, PetscErrorCode *ierr)
895 {
896   CHKFORTRANNULLOBJECT(*sp);
897   *ierr = MatNullSpaceRemove(*sp, *vec);
898 }
899 
900 PETSC_EXTERN void matgetinfo_(Mat *mat, MatInfoType *flag, MatInfo *info, int *ierr)
901 {
902   *ierr = MatGetInfo(*mat, *flag, info);
903 }
904 
905 PETSC_EXTERN void matlufactor_(Mat *mat, IS *row, IS *col, const MatFactorInfo *info, int *ierr)
906 {
907   CHKFORTRANNULLOBJECT(row);
908   CHKFORTRANNULLOBJECT(col);
909   *ierr = MatLUFactor(*mat, row ? *row : NULL, col ? *col : NULL, info);
910 }
911 
912 PETSC_EXTERN void matilufactor_(Mat *mat, IS *row, IS *col, const MatFactorInfo *info, int *ierr)
913 {
914   CHKFORTRANNULLOBJECT(row);
915   CHKFORTRANNULLOBJECT(col);
916   *ierr = MatILUFactor(*mat, row ? *row : NULL, col ? *col : NULL, info);
917 }
918 
919 PETSC_EXTERN void matlufactorsymbolic_(Mat *fact, Mat *mat, IS *row, IS *col, const MatFactorInfo *info, int *ierr)
920 {
921   CHKFORTRANNULLOBJECT(row);
922   CHKFORTRANNULLOBJECT(col);
923   *ierr = MatLUFactorSymbolic(*fact, *mat, row ? *row : NULL, col ? *col : NULL, info);
924 }
925 
926 PETSC_EXTERN void matlufactornumeric_(Mat *fact, Mat *mat, const MatFactorInfo *info, int *ierr)
927 {
928   *ierr = MatLUFactorNumeric(*fact, *mat, info);
929 }
930 
931 PETSC_EXTERN void matcholeskyfactor_(Mat *mat, IS *perm, const MatFactorInfo *info, int *ierr)
932 {
933   CHKFORTRANNULLOBJECT(perm);
934   *ierr = MatCholeskyFactor(*mat, perm ? *perm : NULL, info);
935 }
936 
937 PETSC_EXTERN void matcholeskyfactorsymbolic_(Mat *fact, Mat *mat, IS *perm, const MatFactorInfo *info, int *ierr)
938 {
939   CHKFORTRANNULLOBJECT(perm);
940   *ierr = MatCholeskyFactorSymbolic(*fact, *mat, perm ? *perm : NULL, info);
941 }
942 
943 PETSC_EXTERN void matcholeskyfactornumeric_(Mat *fact, Mat *mat, const MatFactorInfo *info, int *ierr)
944 {
945   *ierr = MatCholeskyFactorNumeric(*fact, *mat, info);
946 }
947 
948 PETSC_EXTERN void matilufactorsymbolic_(Mat *fact, Mat *mat, IS *row, IS *col, const MatFactorInfo *info, int *ierr)
949 {
950   CHKFORTRANNULLOBJECT(row);
951   CHKFORTRANNULLOBJECT(col);
952   *ierr = MatILUFactorSymbolic(*fact, *mat, row ? *row : NULL, col ? *col : NULL, info);
953 }
954 
955 PETSC_EXTERN void maticcfactorsymbolic_(Mat *fact, Mat *mat, IS *perm, const MatFactorInfo *info, int *ierr)
956 {
957   CHKFORTRANNULLOBJECT(perm);
958   *ierr = MatICCFactorSymbolic(*fact, *mat, perm ? *perm : NULL, info);
959 }
960 
961 PETSC_EXTERN void maticcfactor_(Mat *mat, IS *perm, const MatFactorInfo *info, int *ierr)
962 {
963   CHKFORTRANNULLOBJECT(perm);
964   *ierr = MatICCFactor(*mat, perm ? *perm : NULL, info);
965 }
966 
967 PETSC_EXTERN void matfactorinfoinitialize_(MatFactorInfo *info, int *ierr)
968 {
969   *ierr = MatFactorInfoInitialize(info);
970 }
971 PETSC_EXTERN void matzerorowslocal_(Mat *mat, PetscInt *numRows, PetscInt rows[], PetscScalar *diag, Vec *x, Vec *b, int *ierr)
972 {
973   *ierr = MatZeroRowsLocal(*mat, *numRows, rows, *diag, *x, *b);
974 }
975 PETSC_EXTERN void matzerorowslocal0_(Mat *mat, PetscInt *numRows, PetscInt rows[], PetscScalar *diag, Vec *x, Vec *b, int *ierr)
976 {
977   matzerorowslocal_(mat, numRows, rows, diag, x, b, ierr);
978 }
979 PETSC_EXTERN void matzerorowslocal1_(Mat *mat, PetscInt *numRows, PetscInt rows[], PetscScalar *diag, Vec *x, Vec *b, int *ierr)
980 {
981   matzerorowslocal_(mat, numRows, rows, diag, x, b, ierr);
982 }
983 PETSC_EXTERN void matviewfromoptions_(Mat *ao, PetscObject obj, char *type, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len)
984 {
985   char *t;
986 
987   FIXCHAR(type, len, t);
988   CHKFORTRANNULLOBJECT(obj);
989   *ierr = MatViewFromOptions(*ao, obj, t);
990   if (*ierr) return;
991   FREECHAR(type, t);
992 }
993