Date: 2026-07-30T21:14:16+00:00

Actual source code: zmatrixf90.c

      1: #include <petscmat.h>
      2: #include <petsc/private/ftnimpl.h>

      4: #if defined(PETSC_HAVE_FORTRAN_CAPS)
      5:   #define matgetrow_                   MATGETROW
      6:   #define matrestorerow_               MATRESTOREROW
      7:   #define matmpiaijgetseqaij_          MATMPIAIJGETSEQAIJ
      8:   #define matmpiaijrestoreseqaij_      MATMPIAIJRESTORESEQAIJ
      9:   #define matdensegetarray1d_          MATDENSEGETARRAY1D
     10:   #define matdenserestorearray1d_      MATDENSERESTOREARRAY1D
     11:   #define matdensegetarrayread1d_      MATDENSEGETARRAYREAD1D
     12:   #define matdenserestorearrayread1d_  MATDENSERESTOREARRAYREAD1D
     13:   #define matdensegetarraywrite1d_     MATDENSEGETARRAYWRITE1D
     14:   #define matdenserestorearraywrite1d_ MATDENSERESTOREARRAYWRITE1D
     15:   #define matdensegetarray2d_          MATDENSEGETARRAY2D
     16:   #define matdenserestorearray2d_      MATDENSERESTOREARRAY2D
     17:   #define matdensegetarrayread2d_      MATDENSEGETARRAYREAD2D
     18:   #define matdenserestorearrayread2d_  MATDENSERESTOREARRAYREAD2D
     19:   #define matdensegetarraywrite2d_     MATDENSEGETARRAYWRITE2D
     20:   #define matdenserestorearraywrite2d_ MATDENSERESTOREARRAYWRITE2D
     21:   #define matdensegetcolumn_           MATDENSEGETCOLUMN
     22:   #define matdenserestorecolumn_       MATDENSERESTORECOLUMN
     23:   #define matseqaijgetarray_           MATSEQAIJGETARRAY
     24:   #define matseqaijrestorearray_       MATSEQAIJRESTOREARRAY
     25:   #define matseqaijgetarrayread_       MATSEQAIJGETARRAYREAD
     26:   #define matseqaijrestorearrayread_   MATSEQAIJRESTOREARRAYREAD
     27:   #define matseqaijgetarraywrite_      MATSEQAIJGETARRAYWRITE
     28:   #define matseqaijrestorearraywrite_  MATSEQAIJRESTOREARRAYWRITE
     29:   #define matgetghosts_                MATGETGHOSTS
     30:   #define matgetrowij_                 MATGETROWIJ
     31:   #define matrestorerowij_             MATRESTOREROWIJ
     32: #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
     33:   #define matgetrow_                   matgetrow
     34:   #define matrestorerow_               matrestorerow
     35:   #define matmpiaijgetseqaij_          matmpiaijgetseqaij
     36:   #define matmpiaijrestoreseqaij_      matmpiaijrestoreseqaij
     37:   #define matdensegetarray1d_          matdensegetarray1d
     38:   #define matdenserestorearray1d_      matdenserestorearray1d
     39:   #define matdensegetarrayread1d_      matdensegetarrayread1d
     40:   #define matdenserestorearrayread1d_  matdenserestorearrayread1d
     41:   #define matdensegetarraywrite1d_     matdensegetarraywrite1d
     42:   #define matdenserestorearraywrite1d_ matdenserestorearraywrite1d
     43:   #define matdensegetarray2d_          matdensegetarray2d
     44:   #define matdenserestorearray2d_      matdenserestorearray2d
     45:   #define matdensegetarrayread2d_      matdensegetarrayread2d
     46:   #define matdenserestorearrayread2d_  matdenserestorearrayread2d
     47:   #define matdensegetarraywrite2d_     matdensegetarraywrite2d
     48:   #define matdenserestorearraywrite2d_ matdenserestorearraywrite2d
     49:   #define matdensegetcolumn_           matdensegetcolumn
     50:   #define matdenserestorecolumn_       matdenserestorecolumn
     51:   #define matseqaijgetarray_           matseqaijgetarray
     52:   #define matseqaijrestorearray_       matseqaijrestorearray
     53:   #define matseqaijgetarrayread_       matseqaijgetarrayread
     54:   #define matseqaijrestorearrayread_   matseqaijrestorearrayread
     55:   #define matseqaijgetarraywrite_      matseqaijgetarraywrite
     56:   #define matseqaijrestorearraywrite_  matseqaijrestorearraywrite
     57:   #define matgetghosts_                matgetghosts
     58:   #define matgetrowij_                 matgetrowij
     59:   #define matrestorerowij_             matrestorerowij
     60: #endif

     62: PETSC_EXTERN void matgetrow_(Mat *B, PetscInt *row, PetscInt *N, F90Array1d *ia, F90Array1d *a, PetscErrorCode *ierr PETSC_F90_2PTR_PROTO(iad) PETSC_F90_2PTR_PROTO(jad))
     63: {
     64:   PetscInt           n;
     65:   const PetscInt    *II = NULL;
     66:   const PetscScalar *A  = NULL;

     68:   if (FORTRANNULLINTEGERPOINTER(ia) && FORTRANNULLSCALARPOINTER(a)) {
     69:     *ierr = MatGetRow(*B, *row, &n, NULL, NULL);
     70:   } else if (FORTRANNULLINTEGERPOINTER(ia)) {
     71:     *ierr = MatGetRow(*B, *row, &n, NULL, &A);
     72:   } else if (FORTRANNULLSCALARPOINTER(a)) {
     73:     *ierr = MatGetRow(*B, *row, &n, &II, NULL);
     74:   } else {
     75:     *ierr = MatGetRow(*B, *row, &n, &II, &A);
     76:   }
     77:   if (*ierr) return;
     78:   if (II) *ierr = F90Array1dCreate((void *)II, MPIU_INT, 1, n, ia PETSC_F90_2PTR_PARAM(iad));
     79:   if (A) *ierr = F90Array1dCreate((void *)A, MPIU_SCALAR, 1, n, a PETSC_F90_2PTR_PARAM(jad));
     80:   if (!FORTRANNULLINTEGER(N)) *N = n;
     81: }
     82: PETSC_EXTERN void matrestorerow_(Mat *B, PetscInt *row, PetscInt *N, F90Array1d *ia, F90Array1d *a, PetscErrorCode *ierr PETSC_F90_2PTR_PROTO(iad) PETSC_F90_2PTR_PROTO(jad))
     83: {
     84:   const PetscInt    *IA = NULL;
     85:   const PetscScalar *A  = NULL;
     86:   PetscInt           n;

     88:   if (FORTRANNULLINTEGERPOINTER(ia) && FORTRANNULLSCALARPOINTER(a)) {
     89:     *ierr = MatRestoreRow(*B, *row, &n, NULL, NULL);
     90:     return;
     91:   }
     92:   if (!FORTRANNULLINTEGERPOINTER(ia)) {
     93:     *ierr = F90Array1dAccess(ia, MPIU_INT, (void **)&IA PETSC_F90_2PTR_PARAM(iad));
     94:     if (*ierr) return;
     95:     *ierr = F90Array1dDestroy(ia, MPIU_INT PETSC_F90_2PTR_PARAM(iad));
     96:     if (*ierr) return;
     97:   }
     98:   if (!FORTRANNULLSCALARPOINTER(a)) {
     99:     *ierr = F90Array1dAccess(a, MPIU_SCALAR, (void **)&A PETSC_F90_2PTR_PARAM(jad));
    100:     if (*ierr) return;
    101:     *ierr = F90Array1dDestroy(a, MPIU_INT PETSC_F90_2PTR_PARAM(jad));
    102:     if (*ierr) return;
    103:   }
    104:   if (FORTRANNULLINTEGERPOINTER(ia)) {
    105:     *ierr = MatRestoreRow(*B, *row, &n, NULL, &A);
    106:   } else if (FORTRANNULLSCALARPOINTER(a)) {
    107:     *ierr = MatRestoreRow(*B, *row, &n, &IA, NULL);
    108:   } else {
    109:     *ierr = MatRestoreRow(*B, *row, &n, &IA, &A);
    110:   }
    111: }
    112: PETSC_EXTERN void matgetghosts_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    113: {
    114:   const PetscInt *ghosts;
    115:   PetscInt        N;

    117:   *ierr = MatGetGhosts(*mat, &N, &ghosts);
    118:   if (*ierr) return;
    119:   *ierr = F90Array1dCreate((PetscInt *)ghosts, MPIU_INT, 1, N, ptr PETSC_F90_2PTR_PARAM(ptrd));
    120: }
    121: PETSC_EXTERN void matdensegetarray2d_(Mat *mat, F90Array2d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    122: {
    123:   PetscScalar *fa;
    124:   PetscInt     m, N, lda;
    125:   *ierr = MatDenseGetArray(*mat, &fa);
    126:   if (*ierr) return;
    127:   *ierr = MatGetLocalSize(*mat, &m, NULL);
    128:   if (*ierr) return;
    129:   *ierr = MatGetSize(*mat, NULL, &N);
    130:   if (*ierr) return;
    131:   *ierr = MatDenseGetLDA(*mat, &lda);
    132:   if (*ierr) return;
    133:   if (m != lda) { // TODO: add F90Array2dLDACreate()
    134:     *ierr = PetscError(((PetscObject)*mat)->comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_ARG_BADPTR, PETSC_ERROR_INITIAL, "Array lda %" PetscInt_FMT " must match number of local rows %" PetscInt_FMT, lda, m);
    135:     return;
    136:   }
    137:   *ierr = F90Array2dCreate(fa, MPIU_SCALAR, 1, m, 1, N, ptr PETSC_F90_2PTR_PARAM(ptrd));
    138: }
    139: PETSC_EXTERN void matdenserestorearray2d_(Mat *mat, F90Array2d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    140: {
    141:   PetscScalar *fa;
    142:   *ierr = F90Array2dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    143:   if (*ierr) return;
    144:   *ierr = F90Array2dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    145:   if (*ierr) return;
    146:   *ierr = MatDenseRestoreArray(*mat, &fa);
    147: }
    148: PETSC_EXTERN void matdensegetarrayread2d_(Mat *mat, F90Array2d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    149: {
    150:   const PetscScalar *fa;
    151:   PetscInt           m, N, lda;
    152:   *ierr = MatDenseGetArrayRead(*mat, &fa);
    153:   if (*ierr) return;
    154:   *ierr = MatGetLocalSize(*mat, &m, NULL);
    155:   if (*ierr) return;
    156:   *ierr = MatGetSize(*mat, NULL, &N);
    157:   if (*ierr) return;
    158:   *ierr = MatDenseGetLDA(*mat, &lda);
    159:   if (*ierr) return;
    160:   if (m != lda) { // TODO: add F90Array2dLDACreate()
    161:     *ierr = PetscError(((PetscObject)*mat)->comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_ARG_BADPTR, PETSC_ERROR_INITIAL, "Array lda %" PetscInt_FMT " must match number of local rows %" PetscInt_FMT, lda, m);
    162:     return;
    163:   }
    164:   *ierr = F90Array2dCreate((void **)fa, MPIU_SCALAR, 1, m, 1, N, ptr PETSC_F90_2PTR_PARAM(ptrd));
    165: }
    166: PETSC_EXTERN void matdenserestorearrayread2d_(Mat *mat, F90Array2d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    167: {
    168:   const PetscScalar *fa;
    169:   *ierr = F90Array2dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    170:   if (*ierr) return;
    171:   *ierr = F90Array2dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    172:   if (*ierr) return;
    173:   *ierr = MatDenseRestoreArrayRead(*mat, &fa);
    174: }
    175: PETSC_EXTERN void matdensegetarraywrite2d_(Mat *mat, F90Array2d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    176: {
    177:   PetscScalar *fa;
    178:   PetscInt     m, N, lda;
    179:   *ierr = MatDenseGetArrayWrite(*mat, &fa);
    180:   if (*ierr) return;
    181:   *ierr = MatGetLocalSize(*mat, &m, NULL);
    182:   if (*ierr) return;
    183:   *ierr = MatGetSize(*mat, NULL, &N);
    184:   if (*ierr) return;
    185:   *ierr = MatDenseGetLDA(*mat, &lda);
    186:   if (*ierr) return;
    187:   if (m != lda) { // TODO: add F90Array2dLDACreate()
    188:     *ierr = PetscError(((PetscObject)*mat)->comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_ARG_BADPTR, PETSC_ERROR_INITIAL, "Array lda %" PetscInt_FMT " must match number of local rows %" PetscInt_FMT, lda, m);
    189:     return;
    190:   }
    191:   *ierr = F90Array2dCreate(fa, MPIU_SCALAR, 1, m, 1, N, ptr PETSC_F90_2PTR_PARAM(ptrd));
    192: }
    193: PETSC_EXTERN void matdenserestorearraywrite2d_(Mat *mat, F90Array2d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    194: {
    195:   PetscScalar *fa;
    196:   *ierr = F90Array2dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    197:   if (*ierr) return;
    198:   *ierr = F90Array2dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    199:   if (*ierr) return;
    200:   *ierr = MatDenseRestoreArrayWrite(*mat, &fa);
    201: }
    202: PETSC_EXTERN void matdensegetarray1d_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    203: {
    204:   PetscScalar *fa;
    205:   PetscInt     m, N, lda;
    206:   *ierr = MatDenseGetArray(*mat, &fa);
    207:   if (*ierr) return;
    208:   *ierr = MatGetLocalSize(*mat, &m, NULL);
    209:   if (*ierr) return;
    210:   *ierr = MatGetSize(*mat, NULL, &N);
    211:   if (*ierr) return;
    212:   *ierr = MatDenseGetLDA(*mat, &lda);
    213:   if (*ierr) return;
    214:   if (m != lda) { // TODO: add F90Array1dLDACreate()
    215:     *ierr = PetscError(((PetscObject)*mat)->comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_ARG_BADPTR, PETSC_ERROR_INITIAL, "Array lda %" PetscInt_FMT " must match number of local rows %" PetscInt_FMT, lda, m);
    216:     return;
    217:   }
    218:   *ierr = F90Array1dCreate(fa, MPIU_SCALAR, 1, m * N, ptr PETSC_F90_2PTR_PARAM(ptrd));
    219: }
    220: PETSC_EXTERN void matdenserestorearray1d_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    221: {
    222:   PetscScalar *fa;
    223:   *ierr = F90Array1dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    224:   if (*ierr) return;
    225:   *ierr = F90Array1dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    226:   if (*ierr) return;
    227:   *ierr = MatDenseRestoreArray(*mat, &fa);
    228: }
    229: PETSC_EXTERN void matdensegetarrayread1d_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    230: {
    231:   const PetscScalar *fa;
    232:   PetscInt           m, N, lda;
    233:   *ierr = MatDenseGetArrayRead(*mat, &fa);
    234:   if (*ierr) return;
    235:   *ierr = MatGetLocalSize(*mat, &m, NULL);
    236:   if (*ierr) return;
    237:   *ierr = MatGetSize(*mat, NULL, &N);
    238:   if (*ierr) return;
    239:   *ierr = MatDenseGetLDA(*mat, &lda);
    240:   if (*ierr) return;
    241:   if (m != lda) { // TODO: add F90Array1dLDACreate()
    242:     *ierr = PetscError(((PetscObject)*mat)->comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_ARG_BADPTR, PETSC_ERROR_INITIAL, "Array lda %" PetscInt_FMT " must match number of local rows %" PetscInt_FMT, lda, m);
    243:     return;
    244:   }
    245:   *ierr = F90Array1dCreate((void **)fa, MPIU_SCALAR, 1, m * N, ptr PETSC_F90_2PTR_PARAM(ptrd));
    246: }
    247: PETSC_EXTERN void matdenserestorearrayread1d_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    248: {
    249:   const PetscScalar *fa;
    250:   *ierr = F90Array1dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    251:   if (*ierr) return;
    252:   *ierr = F90Array1dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    253:   if (*ierr) return;
    254:   *ierr = MatDenseRestoreArrayRead(*mat, &fa);
    255: }
    256: PETSC_EXTERN void matdensegetarraywrite1d_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    257: {
    258:   PetscScalar *fa;
    259:   PetscInt     m, N, lda;
    260:   *ierr = MatDenseGetArrayWrite(*mat, &fa);
    261:   if (*ierr) return;
    262:   *ierr = MatGetLocalSize(*mat, &m, NULL);
    263:   if (*ierr) return;
    264:   *ierr = MatGetSize(*mat, NULL, &N);
    265:   if (*ierr) return;
    266:   *ierr = MatDenseGetLDA(*mat, &lda);
    267:   if (*ierr) return;
    268:   if (m != lda) { // TODO: add F90Array1dLDACreate()
    269:     *ierr = PetscError(((PetscObject)*mat)->comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, PETSC_ERR_ARG_BADPTR, PETSC_ERROR_INITIAL, "Array lda %" PetscInt_FMT " must match number of local rows %" PetscInt_FMT, lda, m);
    270:     return;
    271:   }
    272:   *ierr = F90Array1dCreate(fa, MPIU_SCALAR, 1, m * N, ptr PETSC_F90_2PTR_PARAM(ptrd));
    273: }
    274: PETSC_EXTERN void matdenserestorearraywrite1d_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    275: {
    276:   PetscScalar *fa;
    277:   *ierr = F90Array1dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    278:   if (*ierr) return;
    279:   *ierr = F90Array1dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    280:   if (*ierr) return;
    281:   *ierr = MatDenseRestoreArrayWrite(*mat, &fa);
    282: }
    283: PETSC_EXTERN void matdensegetcolumn_(Mat *mat, PetscInt *col, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    284: {
    285:   PetscScalar *fa;
    286:   PetscInt     m;
    287:   *ierr = MatDenseGetColumn(*mat, *col, &fa);
    288:   if (*ierr) return;
    289:   *ierr = MatGetLocalSize(*mat, &m, NULL);
    290:   if (*ierr) return;
    291:   *ierr = F90Array1dCreate(fa, MPIU_SCALAR, 1, m, ptr PETSC_F90_2PTR_PARAM(ptrd));
    292: }
    293: PETSC_EXTERN void matdenserestorecolumn_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    294: {
    295:   PetscScalar *fa;
    296:   *ierr = F90Array1dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    297:   if (*ierr) return;
    298:   *ierr = MatDenseRestoreColumn(*mat, &fa);
    299: }

    301: #include <../src/mat/impls/aij/seq/aij.h>
    302: PETSC_EXTERN void matseqaijgetarray_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    303: {
    304:   PetscScalar *fa;
    305:   Mat_SeqAIJ  *a  = (Mat_SeqAIJ *)(*mat)->data;
    306:   PetscInt     nz = (*mat)->rmap->n ? a->i[(*mat)->rmap->n] : 0;

    308:   *ierr = MatSeqAIJGetArray(*mat, &fa);
    309:   if (*ierr) return;
    310:   *ierr = F90Array1dCreate(fa, MPIU_SCALAR, 1, nz, ptr PETSC_F90_2PTR_PARAM(ptrd));
    311: }
    312: PETSC_EXTERN void matseqaijrestorearray_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    313: {
    314:   PetscScalar *fa;
    315:   *ierr = F90Array1dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    316:   if (*ierr) return;
    317:   *ierr = F90Array1dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    318:   if (*ierr) return;
    319:   *ierr = MatSeqAIJRestoreArray(*mat, &fa);
    320: }
    321: PETSC_EXTERN void matseqaijgetarrayread_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    322: {
    323:   const PetscScalar *fa;
    324:   Mat_SeqAIJ        *a  = (Mat_SeqAIJ *)(*mat)->data;
    325:   PetscInt           nz = (*mat)->rmap->n ? a->i[(*mat)->rmap->n] : 0;

    327:   *ierr = MatSeqAIJGetArrayRead(*mat, &fa);
    328:   if (*ierr) return;
    329:   *ierr = F90Array1dCreate((void *)fa, MPIU_SCALAR, 1, nz, ptr PETSC_F90_2PTR_PARAM(ptrd));
    330: }
    331: PETSC_EXTERN void matseqaijrestorearrayread_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    332: {
    333:   const PetscScalar *fa;
    334:   *ierr = F90Array1dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    335:   if (*ierr) return;
    336:   *ierr = F90Array1dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    337:   if (*ierr) return;
    338:   *ierr = MatSeqAIJRestoreArrayRead(*mat, &fa);
    339: }
    340: PETSC_EXTERN void matseqaijgetarraywrite_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    341: {
    342:   PetscScalar *fa;
    343:   Mat_SeqAIJ  *a  = (Mat_SeqAIJ *)(*mat)->data;
    344:   PetscInt     nz = (*mat)->rmap->n ? a->i[(*mat)->rmap->n] : 0;

    346:   *ierr = MatSeqAIJGetArrayWrite(*mat, &fa);
    347:   if (*ierr) return;
    348:   *ierr = F90Array1dCreate(fa, MPIU_SCALAR, 1, nz, ptr PETSC_F90_2PTR_PARAM(ptrd));
    349: }
    350: PETSC_EXTERN void matseqaijrestorearraywrite_(Mat *mat, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    351: {
    352:   PetscScalar *fa;
    353:   *ierr = F90Array1dAccess(ptr, MPIU_SCALAR, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
    354:   if (*ierr) return;
    355:   *ierr = F90Array1dDestroy(ptr, MPIU_SCALAR PETSC_F90_2PTR_PARAM(ptrd));
    356:   if (*ierr) return;
    357:   *ierr = MatSeqAIJRestoreArrayWrite(*mat, &fa);
    358: }
    359: PETSC_EXTERN void matgetrowij_(Mat *B, PetscInt *shift, PetscBool *sym, PetscBool *blockcompressed, PetscInt *n, F90Array1d *ia, F90Array1d *ja, PetscBool *done, PetscErrorCode *ierr PETSC_F90_2PTR_PROTO(iad) PETSC_F90_2PTR_PROTO(jad))
    360: {
    361:   const PetscInt *IA, *JA;
    362:   *ierr = MatGetRowIJ(*B, *shift, *sym, *blockcompressed, n, &IA, &JA, done);
    363:   if (*ierr) return;
    364:   if (!*done) return;
    365:   *ierr = F90Array1dCreate((PetscInt *)IA, MPIU_INT, 1, *n + 1, ia PETSC_F90_2PTR_PARAM(iad));
    366:   *ierr = F90Array1dCreate((PetscInt *)JA, MPIU_INT, 1, IA[*n], ja PETSC_F90_2PTR_PARAM(jad));
    367: }
    368: PETSC_EXTERN void matrestorerowij_(Mat *B, PetscInt *shift, PetscBool *sym, PetscBool *blockcompressed, PetscInt *n, F90Array1d *ia, F90Array1d *ja, PetscBool *done, PetscErrorCode *ierr PETSC_F90_2PTR_PROTO(iad) PETSC_F90_2PTR_PROTO(jad))
    369: {
    370:   const PetscInt *IA, *JA;
    371:   *ierr = F90Array1dAccess(ia, MPIU_INT, (void **)&IA PETSC_F90_2PTR_PARAM(iad));
    372:   if (*ierr) return;
    373:   *ierr = F90Array1dDestroy(ia, MPIU_INT PETSC_F90_2PTR_PARAM(iad));
    374:   if (*ierr) return;
    375:   *ierr = F90Array1dAccess(ja, MPIU_INT, (void **)&JA PETSC_F90_2PTR_PARAM(jad));
    376:   if (*ierr) return;
    377:   *ierr = F90Array1dDestroy(ja, MPIU_INT PETSC_F90_2PTR_PARAM(jad));
    378:   if (*ierr) return;
    379:   *ierr = MatRestoreRowIJ(*B, *shift, *sym, *blockcompressed, n, &IA, &JA, done);
    380: }
    381: PETSC_EXTERN void matmpiaijgetseqaij_(Mat *mat, Mat *A, Mat *B, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    382: {
    383:   const PetscInt *fa;
    384:   PetscInt        n;
    385:   *ierr = MatMPIAIJGetSeqAIJ(*mat, A, B, &fa);
    386:   if (*ierr) return;
    387:   *ierr = MatGetLocalSize(*B, NULL, &n);
    388:   if (*ierr) return;
    389:   *ierr = F90Array1dCreate((void *)fa, MPIU_INT, 1, n, ptr PETSC_F90_2PTR_PARAM(ptrd));
    390: }
    391: PETSC_EXTERN void matmpiaijrestoreseqaij_(Mat *mat, Mat *A, Mat *B, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
    392: {
    393:   *ierr = F90Array1dDestroy(ptr, MPIU_INT PETSC_F90_2PTR_PARAM(ptrd));
    394:   if (*ierr) return;
    395: }