Date: 2026-03-31T13:23:38+00:00

Actual source code: zlmef.c

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

      6:    This file is part of SLEPc.
      7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
      8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      9: */

     11: #include <petsc/private/ftnimpl.h>
     12: #include <slepclme.h>

     14: #if defined(PETSC_HAVE_FORTRAN_CAPS)
     15: #define lmemonitordefault_                LMEMONITORDEFAULT
     16: #define lmemonitorset_                    LMEMONITORSET
     17: #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
     18: #define lmemonitordefault_                lmemonitordefault
     19: #define lmemonitorset_                    lmemonitorset
     20: #endif

     22: /*
     23:    These cannot be called from Fortran but allow Fortran users
     24:    to transparently set these monitors from .F code
     25: */
     26: SLEPC_EXTERN void lmemonitordefault_(LME*,PetscInt*,PetscReal*,PetscViewerAndFormat*,PetscErrorCode*);

     28: static struct {
     29:   PetscFortranCallbackId monitor;
     30:   PetscFortranCallbackId monitordestroy;
     31: } _cb;

     33: /* These are not extern C because they are passed into non-extern C user level functions */
     34: static PetscErrorCode ourmonitor(LME lme,PetscInt i,PetscReal d,void *ctx)
     35: {
     36:   PetscObjectUseFortranCallback(lme,_cb.monitor,(LME*,PetscInt*,PetscReal*,void*,PetscErrorCode*),(&lme,&i,&d,_ctx,&ierr));
     37: }

     39: static PetscErrorCode ourdestroy(PetscCtxRt ctx)
     40: {
     41:   LME lme = *(LME*)ctx;
     42:   PetscObjectUseFortranCallback(lme,_cb.monitordestroy,(void*,PetscErrorCode*),(_ctx,&ierr));
     43: }

     45: SLEPC_EXTERN void lmemonitorset_(LME *lme,void (*monitor)(LME*,PetscInt*,PetscReal*,void*,PetscErrorCode*),void *mctx,void (*monitordestroy)(void*,PetscErrorCode*),PetscErrorCode *ierr)
     46: {
     47:   CHKFORTRANNULLOBJECT(mctx);
     48:   CHKFORTRANNULLFUNCTION(monitordestroy);
     49:   if ((PetscFortranCallbackFn*)monitor == (PetscFortranCallbackFn*)lmemonitordefault_) {
     50:     *ierr = LMEMonitorSet(*lme,(LMEMonitorFn*)LMEMonitorDefault,*(PetscViewerAndFormat**)mctx,(PetscCtxDestroyFn*)PetscViewerAndFormatDestroy);
     51:   } else {
     52:     *ierr = PetscObjectSetFortranCallback((PetscObject)*lme,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.monitor,(PetscFortranCallbackFn*)monitor,mctx); if (*ierr) return;
     53:     *ierr = PetscObjectSetFortranCallback((PetscObject)*lme,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.monitordestroy,(PetscFortranCallbackFn*)monitordestroy,mctx); if (*ierr) return;
     54:     *ierr = LMEMonitorSet(*lme,ourmonitor,*lme,ourdestroy);
     55:   }
     56: }