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
115: EXTERN_C_BEGIN
117: void PETSC_STDCALL matsettype_(Mat *x,CHAR type_name PETSC_MIXED_LEN(len),int *ierr PETSC_END_LEN(len))
118: {
119: char *t;
121: FIXCHAR(type_name,len,t);
122: *MatSetType(*x,t);
123: FREECHAR(type_name,t);
124: }
126: void PETSC_STDCALL matsetvaluesstencil_(Mat *mat,int *m,MatStencil *idxm,int *n,MatStencil *idxn,PetscScalar *v,InsertMode *addv,
127: int *ierr)
128: {
129: *MatSetValuesStencil(*mat,*m,idxm,*n,idxn,v,*addv);
130: }
132: void PETSC_STDCALL matmpiaijgetseqaij_(Mat *A,Mat *Ad,Mat *Ao,int *ic,long *iic,int *ierr)
133: {
134: int *i;
135: *MatMPIAIJGetSeqAIJ(*A,Ad,Ao,&i);if (*ierr) return;
136: *iic = PetscIntAddressToFortran(ic,i);
137: }
139: void PETSC_STDCALL matmpibaijgetseqbaij_(Mat *A,Mat *Ad,Mat *Ao,int *ic,long *iic,int *ierr)
140: {
141: int *i;
142: *MatMPIBAIJGetSeqBAIJ(*A,Ad,Ao,&i);if (*ierr) return;
143: *iic = PetscIntAddressToFortran(ic,i);
144: }
146: void PETSC_STDCALL matgetrowij_(Mat *B,int *shift,PetscTruth *sym,int *n,int *ia,long *iia,int *ja,long *jja,
147: PetscTruth *done,int *ierr)
148: {
149: int *IA,*JA;
150: *MatGetRowIJ(*B,*shift,*sym,n,&IA,&JA,done);if (*ierr) return;
151: *iia = PetscIntAddressToFortran(ia,IA);
152: *jja = PetscIntAddressToFortran(ja,JA);
153: }
155: void PETSC_STDCALL matrestorerowij_(Mat *B,int *shift,PetscTruth *sym,int *n,int *ia,long *iia,int *ja,long *jja,
156: PetscTruth *done,int *ierr)
157: {
158: int *IA = PetscIntAddressFromFortran(ia,*iia),*JA = PetscIntAddressFromFortran(ja,*jja);
159: *MatRestoreRowIJ(*B,*shift,*sym,n,&IA,&JA,done);
160: }
162: void PETSC_STDCALL matsetfromoptions_(Mat *B,int *ierr)
163: {
164: *MatSetFromOptions(*B);
165: }
167: void PETSC_STDCALL matcreateseqaijwitharrays_(MPI_Comm *comm,int *m,int *n,int *i,int *j,PetscScalar *a,Mat *mat,int *ierr)
168: {
169: *MatCreateSeqAIJWithArrays((MPI_Comm)PetscToPointerComm(*comm),*m,*n,i,j,a,mat);
170: }
172: void PETSC_STDCALL matcreatempiadj_(MPI_Comm *comm,int *m,int *n,int *i,int *j,int *values,Mat *A,int *ierr)
173: {
174: Mat_MPIAdj *adj;
176: CHKFORTRANNULLINTEGER(values);
177: *MatCreateMPIAdj((MPI_Comm)PetscToPointerComm(*comm),*m,*n,i,j,values,A);
178: adj = (Mat_MPIAdj*)(*A)->data;
179: adj->freeaij = PETSC_FALSE;
180: }
182: void PETSC_STDCALL matpartitioningdestroy_(MatPartitioning *part,int *ierr)
183: {
184: *MatPartitioningDestroy(*part);
185: }
187: void PETSC_STDCALL matpartitioningcreate_(MPI_Comm *comm,MatPartitioning *part, int *ierr)
188: {
189: *MatPartitioningCreate((MPI_Comm)PetscToPointerComm(*comm),part);
190: }
192: void PETSC_STDCALL matpartitioningapply_(MatPartitioning *part,IS *is,int *ierr)
193: {
194: *MatPartitioningApply(*part,is);
195: }
197: void PETSC_STDCALL matpartitioningsetadjacency_(MatPartitioning *part,Mat *mat,int *ierr)
198: {
199: *MatPartitioningSetAdjacency(*part,*mat);
200: }
202: void PETSC_STDCALL matpartitioningview_(MatPartitioning *part,PetscViewer *viewer, int *ierr)
203: {
204: PetscViewer v;
205: PetscPatchDefaultViewers_Fortran(viewer,v);
206: *MatPartitioningView(*part,v);
207: }
209: void PETSC_STDCALL matpartitioningsettype_(MatPartitioning *part,CHAR type PETSC_MIXED_LEN(len),
210: int *ierr PETSC_END_LEN(len))
211: {
212: char *t;
213: FIXCHAR(type,len,t);
214: *MatPartitioningSetType(*part,t);
215: FREECHAR(type,t);
216: }
218: void PETSC_STDCALL matgetcoloring_(Mat *mat,CHAR type PETSC_MIXED_LEN(len),ISColoring *iscoloring,
219: int *ierr PETSC_END_LEN(len))
220: {
221: char *t;
222: FIXCHAR(type,len,t);
223: *MatGetColoring(*mat,t,iscoloring);
224: FREECHAR(type,t);
225: }
227: void PETSC_STDCALL matsetvalue_(Mat *mat,int *i,int *j,PetscScalar *va,InsertMode *mode,int *ierr)
228: {
229: /* cannot use MatSetValue() here since that usesCHKERRQ() which has a return in it */
230: *MatSetValues(*mat,1,i,1,j,va,*mode);
231: }
233: void PETSC_STDCALL matsetvaluelocal_(Mat *mat,int *i,int *j,PetscScalar *va,InsertMode *mode,int *ierr)
234: {
235: /* cannot use MatSetValueLocal() here since that usesCHKERRQ() which has a return in it */
236: *MatSetValuesLocal(*mat,1,i,1,j,va,*mode);
237: }
239: void PETSC_STDCALL matfdcoloringcreate_(Mat *mat,ISColoring *iscoloring,MatFDColoring *color,int *ierr)
240: {
241: *MatFDColoringCreate(*mat,*iscoloring,color);
242: }
244: /*
245: This is a poor way of storing the column and value pointers
246: generated by MatGetRow() to be returned with MatRestoreRow()
247: but there is not natural,good place else to store them. Hence
248: Fortran programmers can only have one outstanding MatGetRows()
249: at a time.
250: */
251: static int matgetrowactive = 0,*my_ocols = 0;
252: static PetscScalar *my_ovals = 0;
254: void PETSC_STDCALL matgetrow_(Mat *mat,int *row,int *ncols,int *cols,PetscScalar *vals,int *ierr)
255: {
256: int **oocols = &my_ocols;
257: PetscScalar **oovals = &my_ovals;
259: if (matgetrowactive) {
260: PetscError(__LINE__,"MatGetRow_Fortran",__FILE__,__SDIR__,1,0,
261: "Cannot have two MatGetRow() active simultaneouslyn
262: call MatRestoreRow() before calling MatGetRow() a second time");
263: *1;
264: return;
265: }
267: CHKFORTRANNULLINTEGER(cols);
268: CHKFORTRANNULLSCALAR(vals);
270: *MatGetRow(*mat,*row,ncols,oocols,oovals);
271: if (*ierr) return;
273: if (oocols) { *PetscMemcpy(cols,my_ocols,(*ncols)*sizeof(int)); if (*ierr) return;}
274: if (oovals) { *PetscMemcpy(vals,my_ovals,(*ncols)*sizeof(PetscScalar)); if (*ierr) return; }
275: matgetrowactive = 1;
276: }
278: void PETSC_STDCALL matrestorerow_(Mat *mat,int *row,int *ncols,int *cols,PetscScalar *vals,int *ierr)
279: {
280: int **oocols = &my_ocols;
281: PetscScalar **oovals = &my_ovals;
282: if (!matgetrowactive) {
283: PetscError(__LINE__,"MatRestoreRow_Fortran",__FILE__,__SDIR__,1,0,
284: "Must call MatGetRow() first");
285: *1;
286: return;
287: }
288: CHKFORTRANNULLINTEGER(cols);
289: CHKFORTRANNULLSCALAR(vals);
290: *MatRestoreRow(*mat,*row,ncols,oocols,oovals);
291: matgetrowactive = 0;
292: }
294: void PETSC_STDCALL matview_(Mat *mat,PetscViewer *vin,int *ierr)
295: {
296: PetscViewer v;
297: PetscPatchDefaultViewers_Fortran(vin,v);
298: *MatView(*mat,v);
299: }
301: void PETSC_STDCALL matcopy_(Mat *A,Mat *B,MatStructure *str,int *ierr)
302: {
303: *MatCopy(*A,*B,*str);
304: }
306: void PETSC_STDCALL matgetinfo_(Mat *mat,MatInfoType *flag,double *finfo,int *ierr)
307: {
308: *MatGetInfo(*mat,*flag,(MatInfo*)finfo);
309: }
311: void PETSC_STDCALL matgetarray_(Mat *mat,PetscScalar *fa,long *ia,int *ierr)
312: {
313: PetscScalar *mm;
314: int m,n;
316: *MatGetArray(*mat,&mm); if (*ierr) return;
317: *MatGetSize(*mat,&m,&n); if (*ierr) return;
318: *PetscScalarAddressToFortran((PetscObject)*mat,fa,mm,m*n,ia); if (*ierr) return;
319: }
321: void PETSC_STDCALL matrestorearray_(Mat *mat,PetscScalar *fa,long *ia,int *ierr)
322: {
323: PetscScalar *lx;
324: int m,n;
326: *MatGetSize(*mat,&m,&n); if (*ierr) return;
327: *PetscScalarAddressFromFortran((PetscObject)*mat,fa,*ia,m*n,&lx);if (*ierr) return;
328: *MatRestoreArray(*mat,&lx);if (*ierr) return;
329: }
331: void PETSC_STDCALL mattranspose_(Mat *mat,Mat *B,int *ierr)
332: {
333: CHKFORTRANNULLINTEGER(B);
334: *MatTranspose(*mat,B);
335: }
337: void PETSC_STDCALL matload_(PetscViewer *viewer,CHAR outtype PETSC_MIXED_LEN(len),Mat *newmat,int *ierr PETSC_END_LEN(len))
338: {
339: char *t;
340: PetscViewer v;
341: FIXCHAR(outtype,len,t);
342: PetscPatchDefaultViewers_Fortran(viewer,v);
343: *MatLoad(v,t,newmat);
344: FREECHAR(outtype,t);
345: }
347: void PETSC_STDCALL matconvert_(Mat *mat,CHAR outtype PETSC_MIXED_LEN(len),Mat *M,int *ierr PETSC_END_LEN(len))
348: {
349: char *t;
350: FIXCHAR(outtype,len,t);
351: *MatConvert(*mat,t,M);
352: FREECHAR(outtype,t);
353: }
355: void PETSC_STDCALL matcreateseqdense_(MPI_Comm *comm,int *m,int *n,PetscScalar *data,Mat *newmat,int *ierr)
356: {
357: CHKFORTRANNULLSCALAR(data);
358: *MatCreateSeqDense((MPI_Comm)PetscToPointerComm(*comm),*m,*n,data,newmat);
359: }
361: void PETSC_STDCALL matcreatempidense_(MPI_Comm *comm,int *m,int *n,int *M,int *N,PetscScalar *data,Mat *newmat,
362: int *ierr)
363: {
364: CHKFORTRANNULLSCALAR(data);
365: *MatCreateMPIDense((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*M,*N,data,newmat);
366: }
368: /* Fortran ignores diagv */
369: void PETSC_STDCALL matcreatempibdiag_(MPI_Comm *comm,int *m,int *M,int *N,int *nd,int *bs,
370: int *diag,PetscScalar **diagv,Mat *newmat,int *ierr)
371: {
372: *MatCreateMPIBDiag((MPI_Comm)PetscToPointerComm(*comm),
373: *m,*M,*N,*nd,*bs,diag,PETSC_NULL,newmat);
374: }
376: /* Fortran ignores diagv */
377: void PETSC_STDCALL matcreateseqbdiag_(MPI_Comm *comm,int *m,int *n,int *nd,int *bs,
378: int *diag,PetscScalar **diagv,Mat *newmat,int *ierr)
379: {
380: *MatCreateSeqBDiag((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*nd,*bs,diag,
381: PETSC_NULL,newmat);
382: }
384: #if defined(PETSC_HAVE_BLOCKSOLVE) && !defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_SINGLE)
385: /* Fortran cannot pass in procinfo,hence ignored */
386: void PETSC_STDCALL matcreatempirowbs_(MPI_Comm *comm,int *m,int *M,int *nz,int *nnz,Mat *newmat,int *ierr)
387: {
388: CHKFORTRANNULLINTEGER(nnz);
389: *MatCreateMPIRowbs((MPI_Comm)PetscToPointerComm(*comm),*m,*M,*nz,nnz,newmat);
390: }
391: #endif
393: void PETSC_STDCALL matgetordering_(Mat *mat,CHAR type PETSC_MIXED_LEN(len),IS *rperm,IS *cperm,
394: int *ierr PETSC_END_LEN(len))
395: {
396: char *t;
397: FIXCHAR(type,len,t);
398: *MatGetOrdering(*mat,t,rperm,cperm);
399: FREECHAR(type,t);
400: }
402: void PETSC_STDCALL matorderingregisterdestroy_(int *ierr)
403: {
404: *MatOrderingRegisterDestroy();
405: }
407: void PETSC_STDCALL matgettype_(Mat *mm,CHAR name PETSC_MIXED_LEN(len),int *ierr PETSC_END_LEN(len))
408: {
409: char *tname;
411: *MatGetType(*mm,&tname);
412: #if defined(PETSC_USES_CPTOFCD)
413: {
414: char *t = _fcdtocp(name); int len1 = _fcdlen(name);
415: if (t != PETSC_NULL_CHARACTER_Fortran) {
416: *PetscStrncpy(t,tname,len1);if (*ierr) return;
417: }
418: }
419: #else
420: if (name != PETSC_NULL_CHARACTER_Fortran) {
421: *PetscStrncpy(name,tname,len);if (*ierr) return;
422: }
423: #endif
424: }
426: void PETSC_STDCALL matcreate_(MPI_Comm *comm,int *m,int *n,int *M,int *N,Mat *V,int *ierr)
427: {
428: *MatCreate((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*M,*N,V);
429: }
431: void PETSC_STDCALL matcreateseqaij_(MPI_Comm *comm,int *m,int *n,int *nz,
432: int *nnz,Mat *newmat,int *ierr)
433: {
434: CHKFORTRANNULLINTEGER(nnz);
435: *MatCreateSeqAIJ((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*nz,nnz,newmat);
436: }
438: void PETSC_STDCALL matcreateseqbaij_(MPI_Comm *comm,int *bs,int *m,int *n,int *nz,
439: int *nnz,Mat *newmat,int *ierr)
440: {
441: CHKFORTRANNULLINTEGER(nnz);
442: *MatCreateSeqBAIJ((MPI_Comm)PetscToPointerComm(*comm),*bs,*m,*n,*nz,nnz,newmat);
443: }
445: void PETSC_STDCALL matfdcoloringdestroy_(MatFDColoring *mat,int *ierr)
446: {
447: *MatFDColoringDestroy(*mat);
448: }
450: void PETSC_STDCALL matdestroy_(Mat *mat,int *ierr)
451: {
452: *MatDestroy(*mat);
453: }
455: void PETSC_STDCALL matcreatempiaij_(MPI_Comm *comm,int *m,int *n,int *M,int *N,
456: int *d_nz,int *d_nnz,int *o_nz,int *o_nnz,Mat *newmat,int *ierr)
457: {
458: CHKFORTRANNULLINTEGER(d_nnz);
459: CHKFORTRANNULLINTEGER(o_nnz);
461: *MatCreateMPIAIJ((MPI_Comm)PetscToPointerComm(*comm),
462: *m,*n,*M,*N,*d_nz,d_nnz,*o_nz,o_nnz,newmat);
463: }
464: void PETSC_STDCALL matcreatempibaij_(MPI_Comm *comm,int *bs,int *m,int *n,int *M,int *N,
465: int *d_nz,int *d_nnz,int *o_nz,int *o_nnz,Mat *newmat,int *ierr)
466: {
467: CHKFORTRANNULLINTEGER(d_nnz);
468: CHKFORTRANNULLINTEGER(o_nnz);
469: *MatCreateMPIBAIJ((MPI_Comm)PetscToPointerComm(*comm),
470: *bs,*m,*n,*M,*N,*d_nz,d_nnz,*o_nz,o_nnz,newmat);
471: }
474: /*
475: The MatShell Matrix Vector product requires a C routine.
476: This C routine then calls the corresponding Fortran routine that was
477: set by the user.
478: */
479: void PETSC_STDCALL matcreateshell_(MPI_Comm *comm,int *m,int *n,int *M,int *N,void **ctx,Mat *mat,int *ierr)
480: {
481: *MatCreateShell((MPI_Comm)PetscToPointerComm(*comm),*m,*n,*M,*N,*ctx,mat);
482: if (*ierr) return;
483: *PetscMalloc(4*sizeof(void *),&((PetscObject)*mat)->fortran_func_pointers);
484: }
486: static int ourmult(Mat mat,Vec x,Vec y)
487: {
488: int 0;
489: (*(int (PETSC_STDCALL *)(Mat*,Vec*,Vec*,int*))(((PetscObject)mat)->fortran_func_pointers[0]))(&mat,&x,&y,&ierr);
490: return ierr;
491: }
493: static int ourmulttranspose(Mat mat,Vec x,Vec y)
494: {
495: int 0;
496: (*(int (PETSC_STDCALL *)(Mat*,Vec*,Vec*,int*))(((PetscObject)mat)->fortran_func_pointers[2]))(&mat,&x,&y,&ierr);
497: return ierr;
498: }
500: static int ourmultadd(Mat mat,Vec x,Vec y,Vec z)
501: {
502: int 0;
503: (*(int (PETSC_STDCALL *)(Mat*,Vec*,Vec*,Vec*,int*))(((PetscObject)mat)->fortran_func_pointers[1]))(&mat,&x,&y,&z,&ierr);
504: return ierr;
505: }
507: static int ourmulttransposeadd(Mat mat,Vec x,Vec y,Vec z)
508: {
509: int 0;
510: (*(int (PETSC_STDCALL *)(Mat*,Vec*,Vec*,Vec*,int*))(((PetscObject)mat)->fortran_func_pointers[3]))(&mat,&x,&y,&z,&ierr);
511: return ierr;
512: }
514: void PETSC_STDCALL matshellsetoperation_(Mat *mat,MatOperation *op,int (PETSC_STDCALL *f)(Mat*,Vec*,Vec*,int*),int *ierr)
515: {
516: if (*op == MATOP_MULT) {
517: *MatShellSetOperation(*mat,*op,(void(*)(void))ourmult);
518: ((PetscObject)*mat)->fortran_func_pointers[0] = (void(*)(void))f;
519: } else if (*op == MATOP_MULT_TRANSPOSE) {
520: *MatShellSetOperation(*mat,*op,(void(*)(void))ourmulttranspose);
521: ((PetscObject)*mat)->fortran_func_pointers[2] = (void(*)(void))f;
522: } else if (*op == MATOP_MULT_ADD) {
523: *MatShellSetOperation(*mat,*op,(void(*)(void))ourmultadd);
524: ((PetscObject)*mat)->fortran_func_pointers[1] = (void(*)(void))f;
525: } else if (*op == MATOP_MULT_TRANSPOSE_ADD) {
526: *MatShellSetOperation(*mat,*op,(void(*)(void))ourmulttransposeadd);
527: ((PetscObject)*mat)->fortran_func_pointers[3] = (void(*)(void))f;
528: } else {
529: PetscError(__LINE__,"MatShellSetOperation_Fortran",__FILE__,__SDIR__,1,0,
530: "Cannot set that matrix operation");
531: *1;
532: }
533: }
535: #include petscts.h
536: /*
537: MatFDColoringSetFunction sticks the Fortran function into the fortran_func_pointers
538: this function is then accessed by ourmatfdcoloringfunction()
540: NOTE: FORTRAN USER CANNOT PUT IN A NEW J OR B currently.
542: USER CAN HAVE ONLY ONE MatFDColoring in code Because there is no place to hang f7!
543: */
545: static void (PETSC_STDCALL *f7)(TS*,double*,Vec*,Vec*,void*,int*);
547: static int ourmatfdcoloringfunctionts(TS ts,double t,Vec x,Vec y,void *ctx)
548: {
549: int 0;
550: (*f7)(&ts,&t,&x,&y,ctx,&ierr);
551: return ierr;
552: }
554: void PETSC_STDCALL matfdcoloringsetfunctionts_(MatFDColoring *fd,void (PETSC_STDCALL *f)(TS*,double*,Vec*,Vec*,void*,int*),
555: void *ctx,int *ierr)
556: {
557: f7 = f;
558: *MatFDColoringSetFunction(*fd,(int (*)(void))ourmatfdcoloringfunctionts,ctx);
559: }
561: static void (PETSC_STDCALL *f8)(SNES*,Vec*,Vec*,void*,int*);
563: static int ourmatfdcoloringfunctionsnes(SNES ts,Vec x,Vec y,void *ctx)
564: {
565: int 0;
566: (*f8)(&ts,&x,&y,ctx,&ierr);
567: return ierr;
568: }
571: void PETSC_STDCALL matfdcoloringsetfunctionsnes_(MatFDColoring *fd,void (PETSC_STDCALL *f)(SNES*,Vec*,Vec*,void*,int*),
572: void *ctx,int *ierr)
573: {
574: f8 = f;
575: *MatFDColoringSetFunction(*fd,(int (*)(void))ourmatfdcoloringfunctionsnes,ctx);
576: }
578: /*
579: MatGetSubmatrices() is slightly different from C since the
580: Fortran provides the array to hold the submatrix objects,while in C that
581: array is allocated by the MatGetSubmatrices()
582: */
583: void PETSC_STDCALL matgetsubmatrices_(Mat *mat,int *n,IS *isrow,IS *iscol,MatReuse *scall,Mat *smat,int *ierr)
584: {
585: Mat *lsmat;
586: int i;
588: if (*scall == MAT_INITIAL_MATRIX) {
589: *MatGetSubMatrices(*mat,*n,isrow,iscol,*scall,&lsmat);
590: for (i=0; i<*n; i++) {
591: smat[i] = lsmat[i];
592: }
593: PetscFree(lsmat);
594: } else {
595: *MatGetSubMatrices(*mat,*n,isrow,iscol,*scall,&smat);
596: }
597: }
599: void PETSC_STDCALL matduplicate_(Mat *matin,MatDuplicateOption *op,Mat *matout,int *ierr)
600: {
601: *MatDuplicate(*matin,*op,matout);
602: }
604: void PETSC_STDCALL matzerorows_(Mat *mat,IS *is,PetscScalar *diag,int *ierr)
605: {
606: CHKFORTRANNULLSCALAR(diag);
607: *MatZeroRows(*mat,*is,diag);
608: }
610: void PETSC_STDCALL matzerorowslocal_(Mat *mat,IS *is,PetscScalar *diag,int *ierr)
611: {
612: CHKFORTRANNULLSCALAR(diag);
613: *MatZeroRowsLocal(*mat,*is,diag);
614: }
616: EXTERN_C_END