Actual source code: zmat.c

  1: /*$Id: zmat.c,v 1.100 2001/08/07 03:05:11 balay Exp $*/

 3:  #include src/mat/impls/adj/mpi/mpiadj.h
 4:  #include src/fortran/custom/zpetsc.h
 5:  #include petscmat.h

  7: #ifdef PETSC_HAVE_FORTRAN_CAPS
  8: #define matsettype_                      MATSETTYPE
  9: #define matmpiaijgetseqaij_              MATMPIAIJGETSEQAIJ
 10: #define matmpibaijgetseqbaij_            MATMPIBAIJGETSEQBAIJ
 11: #define matgetrowij_                     MATGETROWIJ
 12: #define matrestorerowij_                 MATRESTOREROWIJ
 13: #define matsetfromoptions_               MATSETFROMOPTIONS
 14: #define matcreateseqaijwitharrays_       MATCREATESEQAIJWITHARRAYS
 15: #define matpartitioningdestroy_          MATPARTITIONINGDESTROY
 16: #define matsetvalue_                     MATSETVALUE
 17: #define matsetvaluelocal_                MATSETVALUELOCAL
 18: #define matgetrow_                       MATGETROW
 19: #define matrestorerow_                   MATRESTOREROW
 20: #define matgetordering_                  MATGETORDERING
 21: #define matdestroy_                      MATDESTROY
 22: #define matcreatempiaij_                 MATCREATEMPIAIJ
 23: #define matcreateseqaij_                 MATCREATESEQAIJ
 24: #define matcreatempibaij_                MATCREATEMPIBAIJ
 25: #define matcreateseqbaij_                MATCREATESEQBAIJ
 26: #define matcreate_                       MATCREATE
 27: #define matcreateshell_                  MATCREATESHELL
 28: #define matorderingregisterdestroy_      MATORDERINGREGISTERDESTROY
 29: #define matcreatempirowbs_               MATCREATEMPIROWBS
 30: #define matcreateseqbdiag_               MATCREATESEQBDIAG
 31: #define matcreatempibdiag_               MATCREATEMPIBDIAG
 32: #define matcreateseqdense_               MATCREATESEQDENSE
 33: #define matcreatempidense_               MATCREATEMPIDENSE
 34: #define matconvert_                      MATCONVERT
 35: #define matload_                         MATLOAD
 36: #define mattranspose_                    MATTRANSPOSE
 37: #define matgetarray_                     MATGETARRAY
 38: #define matrestorearray_                 MATRESTOREARRAY
 39: #define matgettype_                      MATGETTYPE
 40: #define matgetinfo_                      MATGETINFO
 41: #define matshellsetoperation_            MATSHELLSETOPERATION
 42: #define matview_                         MATVIEW
 43: #define matfdcoloringcreate_             MATFDCOLORINGCREATE
 44: #define matfdcoloringdestroy_            MATFDCOLORINGDESTROY
 45: #define matfdcoloringsetfunctionsnes_    MATFDCOLORINGSETFUNCTIONSNES
 46: #define matfdcoloringsetfunctionts_      MATFDCOLORINGSETFUNCTIONTS
 47: #define matcopy_                         MATCOPY
 48: #define matgetsubmatrices_               MATGETSUBMATRICES
 49: #define matgetcoloring_                  MATGETCOLORING
 50: #define matpartitioningsettype_          MATPARTITIONINGSETTYPE
 51: #define matduplicate_                    MATDUPLICATE
 52: #define matzerorows_                     MATZEROROWS
 53: #define matzerorowslocal_                MATZEROROWSLOCAL
 54: #define matpartitioningview_             MATPARTITIONINGVIEW
 55: #define matpartitioningcreate_           MATPARTITIONINGCREATE
 56: #define matpartitioningsetadjacency_     MATPARTITIONINGSETADJACENCY
 57: #define matpartitioningapply_            MATPARTITIONINGAPPLY
 58: #define matcreatempiadj_                 MATCREATEMPIADJ
 59: #define matsetvaluesstencil_             MATSETVALUESSTENCIL
 60: #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
 61: #define matsettype_                      matsettype
 62: #define matmpiaijgetseqaij_              matmpiaijgetseqaij
 63: #define matmpibaijgetseqbaij_            matmpibaijgetseqbaij          
 64: #define matrestorerowij_                 matrestorerowij
 65: #define matgetrowij_                     matgetrowij
 66: #define matcreateseqaijwitharrays_       matcreateseqaijwitharrays
 67: #define matpartitioningdestroy_          matpartitioningdestroy
 68: #define matpartitioningsettype_          matpartitioningsettype
 69: #define matsetvalue_                     matsetvalue
 70: #define matsetvaluelocal_                matsetvaluelocal
 71: #define matgetrow_                       matgetrow
 72: #define matrestorerow_                   matrestorerow
 73: #define matview_                         matview
 74: #define matgetinfo_                      matgetinfo
 75: #define matgettype_                      matgettype
 76: #define matdestroy_                      matdestroy
 77: #define matcreatempiaij_                 matcreatempiaij
 78: #define matcreateseqaij_                 matcreateseqaij
 79: #define matcreatempibaij_                matcreatempibaij
 80: #define matcreateseqbaij_                matcreateseqbaij
 81: #define matcreate_                       matcreate
 82: #define matcreateshell_                  matcreateshell
 83: #define matorderingregisterdestroy_      matorderingregisterdestroy
 84: #define matgetordering_                  matgetordering
 85: #define matcreatempirowbs_               matcreatempirowbs
 86: #define matcreateseqbdiag_               matcreateseqbdiag
 87: #define matcreatempibdiag_               matcreatempibdiag
 88: #define matcreateseqdense_               matcreateseqdense
 89: #define matcreatempidense_               matcreatempidense
 90: #define matconvert_                      matconvert
 91: #define matload_                         matload
 92: #define mattranspose_                    mattranspose
 93: #define matgetarray_                     matgetarray
 94: #define matrestorearray_                 matrestorearray
 95: #define matshellsetoperation_            matshellsetoperation
 96: #define matfdcoloringcreate_             matfdcoloringcreate
 97: #define matfdcoloringdestroy_            matfdcoloringdestroy
 98: #define matfdcoloringsetfunctionsnes_    matfdcoloringsetfunctionsnes
 99: #define matfdcoloringsetfunctionts_      matfdcoloringsetfunctionts
100: #define matcopy_                         matcopy
101: #define matgetsubmatrices_               matgetsubmatrices
102: #define matgetcoloring_                  matgetcoloring
103: #define matduplicate_                    matduplicate
104: #define matzerorows_                     matzerorows
105: #define matzerorowslocal_                matzerorowslocal
106: #define matpartitioningview_             matpartitioningview
107: #define matpartitioningcreate_           matpartitioningcreate
108: #define matpartitioningsetadjacency_     matpartitioningsetadjacency
109: #define matpartitioningapply_            matpartitioningapply            
110: #define matcreatempiadj_                 matcreatempiadj
111: #define matsetfromoptions_               matsetfromoptions
112: #define matsetvaluesstencil_             matsetvaluesstencil
113: #endif


116: EXTERN_C_BEGIN

118: void PETSC_STDCALL matsettype_(Mat *x,CHAR type_name PETSC_MIXED_LEN(len),int *ierr PETSC_END_LEN(len))
119: {
120:   char *t;

122:   FIXCHAR(type_name,len,t);
123:   *MatSetType(*x,t);
124:   FREECHAR(type_name,t);
125: }

127: void PETSC_STDCALL matsetvaluesstencil_(Mat *mat,int *m,MatStencil *idxm,int *n,MatStencil *idxn,PetscScalar *v,InsertMode *addv,
128:                                         int *ierr)
129: {
130:   *MatSetValuesStencil(*mat,*m,idxm,*n,idxn,v,*addv);
131: }

133: void PETSC_STDCALL matmpiaijgetseqaij_(Mat *A,Mat *Ad,Mat *Ao,int *ic,long *iic,int *ierr)
134: {
135:   int *i;
136:   *MatMPIAIJGetSeqAIJ(*A,Ad,Ao,&i);if (*ierr) return;
137:   *iic  = PetscIntAddressToFortran(ic,i);
138: }

140: void PETSC_STDCALL matmpibaijgetseqbaij_(Mat *A,Mat *Ad,Mat *Ao,int *ic,long *iic,int *ierr)
141: {
142:   int *i;
143:   *MatMPIBAIJGetSeqBAIJ(*A,Ad,Ao,&i);if (*ierr) return;
144:   *iic  = PetscIntAddressToFortran(ic,i);
145: }

147: void PETSC_STDCALL matgetrowij_(Mat *B,int *shift,PetscTruth *sym,int *n,int *ia,long *iia,int *ja,long *jja,
148:                                 PetscTruth *done,int *ierr)
149: {
150:   int *IA,*JA;
151:   *MatGetRowIJ(*B,*shift,*sym,n,&IA,&JA,done);if (*ierr) return;
152:   *iia  = PetscIntAddressToFortran(ia,IA);
153:   *jja  = PetscIntAddressToFortran(ja,JA);
154: }

156: void PETSC_STDCALL matrestorerowij_(Mat *B,int *shift,PetscTruth *sym,int *n,int *ia,long *iia,int *ja,long *jja,
157:                                     PetscTruth *done,int *ierr)
158: {
159:   int *IA = PetscIntAddressFromFortran(ia,*iia),*JA = PetscIntAddressFromFortran(ja,*jja);
160:   *MatRestoreRowIJ(*B,*shift,*sym,n,&IA,&JA,done);
161: }

163: void PETSC_STDCALL matsetfromoptions_(Mat *B,int *ierr)
164: {
165:   *MatSetFromOptions(*B);
166: }

168: void PETSC_STDCALL matcreateseqaijwitharrays_(MPI_Comm *comm,int *m,int *n,int *i,int *j,PetscScalar *a,Mat *mat,int *ierr)
169: {
170:   *MatCreateSeqAIJWithArrays((MPI_Comm)PetscToPointerComm(*comm),*m,*n,i,j,a,mat);
171: }

173: void PETSC_STDCALL matcreatempiadj_(MPI_Comm *comm,int *m,int *n,int *i,int *j,int *values,Mat *A,int *ierr)
174: {
175:   Mat_MPIAdj *adj;

177:   CHKFORTRANNULLINTEGER(values);
178:   *MatCreateMPIAdj((MPI_Comm)PetscToPointerComm(*comm),*m,*n,i,j,values,A);
179:   adj = (Mat_MPIAdj*)(*A)->data;
180:   adj->freeaij = PETSC_FALSE;
181: }

183: void PETSC_STDCALL matpartitioningdestroy_(MatPartitioning *part,int *ierr)
184: {
185:   *MatPartitioningDestroy(*part);
186: }

188: void PETSC_STDCALL matpartitioningcreate_(MPI_Comm *comm,MatPartitioning *part, int *ierr)
189: {
190:   *MatPartitioningCreate((MPI_Comm)PetscToPointerComm(*comm),part);
191: }

193: void PETSC_STDCALL matpartitioningapply_(MatPartitioning *part,IS *is,int *ierr)
194: {
195:   *MatPartitioningApply(*part,is);
196: }

198: void PETSC_STDCALL matpartitioningsetadjacency_(MatPartitioning *part,Mat *mat,int *ierr)
199: {
200:   *MatPartitioningSetAdjacency(*part,*mat);
201: }

203: void PETSC_STDCALL matpartitioningview_(MatPartitioning  *part,PetscViewer *viewer, int *ierr)
204: {
205:   PetscViewer v;
206:   PetscPatchDefaultViewers_Fortran(viewer,v);
207:   *MatPartitioningView(*part,v);
208: }

210: void PETSC_STDCALL matpartitioningsettype_(MatPartitioning *part,CHAR type PETSC_MIXED_LEN(len),
211:                                            int *ierr PETSC_END_LEN(len))
212: {
213:   char *t;
214:   FIXCHAR(type,len,t);
215:   *MatPartitioningSetType(*part,t);
216:   FREECHAR(type,t);
217: }

219: void PETSC_STDCALL matgetcoloring_(Mat *mat,CHAR type PETSC_MIXED_LEN(len),ISColoring *iscoloring,
220:                                    int *ierr PETSC_END_LEN(len))
221: {
222:   char *t;
223:   FIXCHAR(type,len,t);
224:   *MatGetColoring(*mat,t,iscoloring);
225:   FREECHAR(type,t);
226: }

228: void PETSC_STDCALL matsetvalue_(Mat *mat,int *i,int *j,PetscScalar *va,InsertMode *mode,int *ierr)
229: {
230:   /* cannot use MatSetValue() here since that usesCHKERRQ() which has a return in it */
231:   *MatSetValues(*mat,1,i,1,j,va,*mode);
232: }

234: void PETSC_STDCALL matsetvaluelocal_(Mat *mat,int *i,int *j,PetscScalar *va,InsertMode *mode,int *ierr)
235: {
236:   /* cannot use MatSetValueLocal() here since that usesCHKERRQ() which has a return in it */
237:   *MatSetValuesLocal(*mat,1,i,1,j,va,*mode);
238: }

240: void PETSC_STDCALL matfdcoloringcreate_(Mat *mat,ISColoring *iscoloring,MatFDColoring *color,int *ierr)
241: {
242:   *MatFDColoringCreate(*mat,*iscoloring,color);
243: }

245: /*
246:    This is a poor way of storing the column and value pointers 
247:   generated by MatGetRow() to be returned with MatRestoreRow()
248:   but there is not natural,good place else to store them. Hence
249:   Fortran programmers can only have one outstanding MatGetRows()
250:   at a time.
251: */
252: static int    matgetrowactive = 0,*my_ocols = 0;
253: static PetscScalar *my_ovals = 0;

255: void PETSC_STDCALL matgetrow_(Mat *mat,int *row,int *ncols,int *cols,PetscScalar *vals,int *ierr)
256: {
257:   int         **oocols = &my_ocols;
258:   PetscScalar **oovals = &my_ovals;

260:   if (matgetrowactive) {
261:      PetscError(__LINE__,"MatGetRow_Fortran",__FILE__,__SDIR__,1,0,
262:                "Cannot have two MatGetRow() active simultaneouslyn
263:                call MatRestoreRow() before calling MatGetRow() a second time");
264:      *1;
265:      return;
266:   }

268:   CHKFORTRANNULLINTEGER(cols); if (!cols) oocols = PETSC_NULL;
269:   CHKFORTRANNULLSCALAR(vals);  if (!vals) oovals = PETSC_NULL;

271:   *MatGetRow(*mat,*row,ncols,oocols,oovals);
272:   if (*ierr) return;

274:   if (oocols) { *PetscMemcpy(cols,my_ocols,(*ncols)*sizeof(int)); if (*ierr) return;}
275:   if (oovals) { *PetscMemcpy(vals,my_ovals,(*ncols)*sizeof(PetscScalar)); if (*ierr) return; }
276:   matgetrowactive = 1;
277: }

279: void PETSC_STDCALL matrestorerow_(Mat *mat,int *row,int *ncols,int *cols,PetscScalar *vals,int *ierr)
280: {
281:   int    **oocols = &my_ocols;
282:   PetscScalar **oovals = &my_ovals;
283:   if (!matgetrowactive) {
284:      PetscError(__LINE__,"MatRestoreRow_Fortran",__FILE__,__SDIR__,1,0,
285:                "Must call MatGetRow() first");
286:      *1;
287:      return;
288:   }
289:   CHKFORTRANNULLINTEGER(cols); if (!cols) oocols = PETSC_NULL;
290:   CHKFORTRANNULLSCALAR(vals);  if (!vals) oovals = PETSC_NULL;

292:   *MatRestoreRow(*mat,*row,ncols,oocols,oovals);
293:   matgetrowactive = 0;
294: }

296: void PETSC_STDCALL matview_(Mat *mat,PetscViewer *vin,int *ierr)
297: {
298:   PetscViewer v;
299:   PetscPatchDefaultViewers_Fortran(vin,v);
300:   *MatView(*mat,v);
301: }

303: void PETSC_STDCALL matcopy_(Mat *A,Mat *B,MatStructure *str,int *ierr)
304: {
305:   *MatCopy(*A,*B,*str);
306: }

308: void PETSC_STDCALL matgetinfo_(Mat *mat,MatInfoType *flag,double *finfo,int *ierr)
309: {
310:   *MatGetInfo(*mat,*flag,(MatInfo*)finfo);
311: }

313: void PETSC_STDCALL matgetarray_(Mat *mat,PetscScalar *fa,long *ia,int *ierr)
314: {
315:   PetscScalar *mm;
316:   int    m,n;

318:   *MatGetArray(*mat,&mm); if (*ierr) return;
319:   *MatGetSize(*mat,&m,&n);  if (*ierr) return;
320:   *PetscScalarAddressToFortran((PetscObject)*mat,fa,mm,m*n,ia); if (*ierr) return;
321: }

323: void PETSC_STDCALL matrestorearray_(Mat *mat,PetscScalar *fa,long *ia,int *ierr)
324: {
325:   PetscScalar          *lx;
326:   int                  m,n;

328:   *MatGetSize(*mat,&m,&n); if (*ierr) return;
329:   *PetscScalarAddressFromFortran((PetscObject)*mat,fa,*ia,m*n,&lx);if (*ierr) return;
330:   *MatRestoreArray(*mat,&lx);if (*ierr) return;
331: }

333: void PETSC_STDCALL mattranspose_(Mat *mat,Mat *B,int *ierr)
334: {
335:   CHKFORTRANNULLINTEGER(B);
336:   *MatTranspose(*mat,B);
337: }

339: void PETSC_STDCALL matload_(PetscViewer *viewer,CHAR outtype PETSC_MIXED_LEN(len),Mat *newmat,int *ierr PETSC_END_LEN(len))
340: {
341:   char *t;
342:   PetscViewer v;
343:   FIXCHAR(outtype,len,t);
344:   PetscPatchDefaultViewers_Fortran(viewer,v);
345:   *MatLoad(v,t,newmat);
346:   FREECHAR(outtype,t);
347: }

349: void PETSC_STDCALL matconvert_(Mat *mat,CHAR outtype PETSC_MIXED_LEN(len),Mat *M,int *ierr PETSC_END_LEN(len))
350: {
351:   char *t;
352:   FIXCHAR(outtype,len,t);
353:   *MatConvert(*mat,t,M);
354:   FREECHAR(outtype,t);
355: }

357: void PETSC_STDCALL matcreateseqdense_(MPI_Comm *comm,int *m,int *n,PetscScalar *data,Mat *newmat,int *ierr)
358: {
359:   CHKFORTRANNULLSCALAR(data);
360:   *MatCreateSeqDense((MPI_Comm)PetscToPointerComm(*comm),*m,*n,data,newmat);
361: }

363: void PETSC_STDCALL matcreatempidense_(MPI_Comm *comm,int *m,int *n,int *M,int *N,PetscScalar *data,Mat *newmat,
364:                         int *ierr)
365: {
366:   CHKFORTRANNULLSCALAR(data);
367:   *MatCreateMPIDense((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*M,*N,data,newmat);
368: }

370: /* Fortran ignores diagv */
371: void PETSC_STDCALL matcreatempibdiag_(MPI_Comm *comm,int *m,int *M,int *N,int *nd,int *bs,
372:                         int *diag,PetscScalar **diagv,Mat *newmat,int *ierr)
373: {
374:   *MatCreateMPIBDiag((MPI_Comm)PetscToPointerComm(*comm),
375:                               *m,*M,*N,*nd,*bs,diag,PETSC_NULL,newmat);
376: }

378: /* Fortran ignores diagv */
379: void PETSC_STDCALL matcreateseqbdiag_(MPI_Comm *comm,int *m,int *n,int *nd,int *bs,
380:                         int *diag,PetscScalar **diagv,Mat *newmat,int *ierr)
381: {
382:   *MatCreateSeqBDiag((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*nd,*bs,diag,
383:                                PETSC_NULL,newmat);
384: }

386: #if defined(PETSC_HAVE_BLOCKSOLVE) && !defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_SINGLE)
387: /*  Fortran cannot pass in procinfo,hence ignored */
388: void PETSC_STDCALL matcreatempirowbs_(MPI_Comm *comm,int *m,int *M,int *nz,int *nnz,Mat *newmat,int *ierr)
389: {
390:   CHKFORTRANNULLINTEGER(nnz);
391:   *MatCreateMPIRowbs((MPI_Comm)PetscToPointerComm(*comm),*m,*M,*nz,nnz,newmat);
392: }
393: #endif

395: void PETSC_STDCALL matgetordering_(Mat *mat,CHAR type PETSC_MIXED_LEN(len),IS *rperm,IS *cperm,
396:                        int *ierr PETSC_END_LEN(len))
397: {
398:   char *t;
399:   FIXCHAR(type,len,t);
400:   *MatGetOrdering(*mat,t,rperm,cperm);
401:   FREECHAR(type,t);
402: }

404: void PETSC_STDCALL matorderingregisterdestroy_(int *ierr)
405: {
406:   *MatOrderingRegisterDestroy();
407: }

409: void PETSC_STDCALL matgettype_(Mat *mm,CHAR name PETSC_MIXED_LEN(len),int *ierr PETSC_END_LEN(len))
410: {
411:   char *tname;

413:   *MatGetType(*mm,&tname);
414: #if defined(PETSC_USES_CPTOFCD)
415:   {
416:     char *t = _fcdtocp(name); int len1 = _fcdlen(name);
417:     if (t != PETSC_NULL_CHARACTER_Fortran) {
418:       *PetscStrncpy(t,tname,len1);if (*ierr) return;
419:     }
420:   }
421: #else
422:   if (name != PETSC_NULL_CHARACTER_Fortran) {
423:     *PetscStrncpy(name,tname,len);if (*ierr) return;
424:   }
425: #endif
426: }

428: void PETSC_STDCALL matcreate_(MPI_Comm *comm,int *m,int *n,int *M,int *N,Mat *V,int *ierr)
429: {
430:   *MatCreate((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*M,*N,V);
431: }

433: void PETSC_STDCALL matcreateseqaij_(MPI_Comm *comm,int *m,int *n,int *nz,
434:                            int *nnz,Mat *newmat,int *ierr)
435: {
436:   CHKFORTRANNULLINTEGER(nnz);
437:   *MatCreateSeqAIJ((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*nz,nnz,newmat);
438: }

440: void PETSC_STDCALL matcreateseqbaij_(MPI_Comm *comm,int *bs,int *m,int *n,int *nz,
441:                            int *nnz,Mat *newmat,int *ierr)
442: {
443:   CHKFORTRANNULLINTEGER(nnz);
444:   *MatCreateSeqBAIJ((MPI_Comm)PetscToPointerComm(*comm),*bs,*m,*n,*nz,nnz,newmat);
445: }

447: void PETSC_STDCALL matfdcoloringdestroy_(MatFDColoring *mat,int *ierr)
448: {
449:   *MatFDColoringDestroy(*mat);
450: }

452: void PETSC_STDCALL matdestroy_(Mat *mat,int *ierr)
453: {
454:   *MatDestroy(*mat);
455: }

457: void PETSC_STDCALL matcreatempiaij_(MPI_Comm *comm,int *m,int *n,int *M,int *N,
458:          int *d_nz,int *d_nnz,int *o_nz,int *o_nnz,Mat *newmat,int *ierr)
459: {
460:   CHKFORTRANNULLINTEGER(d_nnz);
461:   CHKFORTRANNULLINTEGER(o_nnz);

463:   *MatCreateMPIAIJ((MPI_Comm)PetscToPointerComm(*comm),
464:                              *m,*n,*M,*N,*d_nz,d_nnz,*o_nz,o_nnz,newmat);
465: }
466: void PETSC_STDCALL matcreatempibaij_(MPI_Comm *comm,int *bs,int *m,int *n,int *M,int *N,
467:          int *d_nz,int *d_nnz,int *o_nz,int *o_nnz,Mat *newmat,int *ierr)
468: {
469:   CHKFORTRANNULLINTEGER(d_nnz);
470:   CHKFORTRANNULLINTEGER(o_nnz);
471:   *MatCreateMPIBAIJ((MPI_Comm)PetscToPointerComm(*comm),
472:                              *bs,*m,*n,*M,*N,*d_nz,d_nnz,*o_nz,o_nnz,newmat);
473: }


476: /*
477:       The MatShell Matrix Vector product requires a C routine.
478:    This C routine then calls the corresponding Fortran routine that was
479:    set by the user.
480: */
481: void PETSC_STDCALL matcreateshell_(MPI_Comm *comm,int *m,int *n,int *M,int *N,void **ctx,Mat *mat,int *ierr)
482: {
483:   *MatCreateShell((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*M,*N,*ctx,mat);
484:   if (*ierr) return;
485:   *PetscMalloc(4*sizeof(void *),&((PetscObject)*mat)->fortran_func_pointers);
486: }

488: static int ourmult(Mat mat,Vec x,Vec y)
489: {
490:   int              0;
491:   (*(int (PETSC_STDCALL *)(Mat*,Vec*,Vec*,int*))(((PetscObject)mat)->fortran_func_pointers[0]))(&mat,&x,&y,&ierr);
492:   return ierr;
493: }

495: static int ourmulttranspose(Mat mat,Vec x,Vec y)
496: {
497:   int              0;
498:   (*(int (PETSC_STDCALL *)(Mat*,Vec*,Vec*,int*))(((PetscObject)mat)->fortran_func_pointers[2]))(&mat,&x,&y,&ierr);
499:   return ierr;
500: }

502: static int ourmultadd(Mat mat,Vec x,Vec y,Vec z)
503: {
504:   int              0;
505:   (*(int (PETSC_STDCALL *)(Mat*,Vec*,Vec*,Vec*,int*))(((PetscObject)mat)->fortran_func_pointers[1]))(&mat,&x,&y,&z,&ierr);
506:   return ierr;
507: }

509: static int ourmulttransposeadd(Mat mat,Vec x,Vec y,Vec z)
510: {
511:   int              0;
512:   (*(int (PETSC_STDCALL *)(Mat*,Vec*,Vec*,Vec*,int*))(((PetscObject)mat)->fortran_func_pointers[3]))(&mat,&x,&y,&z,&ierr);
513:   return ierr;
514: }

516: void PETSC_STDCALL matshellsetoperation_(Mat *mat,MatOperation *op,int (PETSC_STDCALL *f)(Mat*,Vec*,Vec*,int*),int *ierr)
517: {
518:   if (*op == MATOP_MULT) {
519:     *MatShellSetOperation(*mat,*op,(void(*)(void))ourmult);
520:     ((PetscObject)*mat)->fortran_func_pointers[0] = (void(*)(void))f;
521:   } else if (*op == MATOP_MULT_TRANSPOSE) {
522:     *MatShellSetOperation(*mat,*op,(void(*)(void))ourmulttranspose);
523:     ((PetscObject)*mat)->fortran_func_pointers[2] = (void(*)(void))f;
524:   } else if (*op == MATOP_MULT_ADD) {
525:     *MatShellSetOperation(*mat,*op,(void(*)(void))ourmultadd);
526:     ((PetscObject)*mat)->fortran_func_pointers[1] = (void(*)(void))f;
527:   } else if (*op == MATOP_MULT_TRANSPOSE_ADD) {
528:     *MatShellSetOperation(*mat,*op,(void(*)(void))ourmulttransposeadd);
529:     ((PetscObject)*mat)->fortran_func_pointers[3] = (void(*)(void))f;
530:   } else {
531:     PetscError(__LINE__,"MatShellSetOperation_Fortran",__FILE__,__SDIR__,1,0,
532:                "Cannot set that matrix operation");
533:     *1;
534:   }
535: }

537:  #include petscts.h
538: /*
539:         MatFDColoringSetFunction sticks the Fortran function into the fortran_func_pointers
540:     this function is then accessed by ourmatfdcoloringfunction()

542:    NOTE: FORTRAN USER CANNOT PUT IN A NEW J OR B currently.

544:    USER CAN HAVE ONLY ONE MatFDColoring in code Because there is no place to hang f7!
545: */

547: static void (PETSC_STDCALL *f7)(TS*,double*,Vec*,Vec*,void*,int*);

549: static int ourmatfdcoloringfunctionts(TS ts,double t,Vec x,Vec y,void *ctx)
550: {
551:   int 0;
552:   (*f7)(&ts,&t,&x,&y,ctx,&ierr);
553:   return ierr;
554: }

556: void PETSC_STDCALL matfdcoloringsetfunctionts_(MatFDColoring *fd,void (PETSC_STDCALL *f)(TS*,double*,Vec*,Vec*,void*,int*),
557:                                  void *ctx,int *ierr)
558: {
559:   f7 = f;
560:   *MatFDColoringSetFunction(*fd,(int (*)(void))ourmatfdcoloringfunctionts,ctx);
561: }

563: static void (PETSC_STDCALL *f8)(SNES*,Vec*,Vec*,void*,int*);

565: static int ourmatfdcoloringfunctionsnes(SNES ts,Vec x,Vec y,void *ctx)
566: {
567:   int 0;
568:   (*f8)(&ts,&x,&y,ctx,&ierr);
569:   return ierr;
570: }


573: void PETSC_STDCALL matfdcoloringsetfunctionsnes_(MatFDColoring *fd,void (PETSC_STDCALL *f)(SNES*,Vec*,Vec*,void*,int*),
574:                                  void *ctx,int *ierr)
575: {
576:   f8 = f;
577:   *MatFDColoringSetFunction(*fd,(int (*)(void))ourmatfdcoloringfunctionsnes,ctx);
578: }

580: /*
581:     MatGetSubmatrices() is slightly different from C since the 
582:     Fortran provides the array to hold the submatrix objects,while in C that 
583:     array is allocated by the MatGetSubmatrices()
584: */
585: void PETSC_STDCALL matgetsubmatrices_(Mat *mat,int *n,IS *isrow,IS *iscol,MatReuse *scall,Mat *smat,int *ierr)
586: {
587:   Mat *lsmat;
588:   int i;

590:   if (*scall == MAT_INITIAL_MATRIX) {
591:     *MatGetSubMatrices(*mat,*n,isrow,iscol,*scall,&lsmat);
592:     for (i=0; i<*n; i++) {
593:       smat[i] = lsmat[i];
594:     }
595:     PetscFree(lsmat);
596:   } else {
597:     *MatGetSubMatrices(*mat,*n,isrow,iscol,*scall,&smat);
598:   }
599: }

601: void PETSC_STDCALL matduplicate_(Mat *matin,MatDuplicateOption *op,Mat *matout,int *ierr)
602: {
603:   *MatDuplicate(*matin,*op,matout);
604: }

606: void PETSC_STDCALL matzerorows_(Mat *mat,IS *is,PetscScalar *diag,int *ierr)
607: {
608:   CHKFORTRANNULLSCALAR(diag);
609:   *MatZeroRows(*mat,*is,diag);
610: }

612: void PETSC_STDCALL matzerorowslocal_(Mat *mat,IS *is,PetscScalar *diag,int *ierr)
613: {
614:   CHKFORTRANNULLSCALAR(diag);
615:   *MatZeroRowsLocal(*mat,*is,diag);
616: }

618: EXTERN_C_END