Date: 2024-10-28T09:13:39+00:00

Actual source code: zlmef.c
slepc-3.22.1 2024-10-28
Report Typos and Errors

      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/fortranimpl.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 are not usually called from Fortran but allow Fortran users
     24:    to transparently set these monitors from .F code
     25: */
     26: SLEPC_EXTERN void lmemonitordefault_(LME *lme,PetscInt *it,PetscReal *errest,PetscViewerAndFormat **ctx,PetscErrorCode *ierr)
     27: {
     28:   *ierr = LMEMonitorDefault(*lme,*it,*errest,*ctx);
     29: }

     31: static struct {
     32:   PetscFortranCallbackId monitor;
     33:   PetscFortranCallbackId monitordestroy;
     34: } _cb;

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

     42: static PetscErrorCode ourdestroy(void** ctx)
     43: {
     44:   LME lme = (LME)*ctx;
     45:   PetscObjectUseFortranCallback(lme,_cb.monitordestroy,(void*,PetscErrorCode*),(_ctx,&ierr));
     46: }

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