Date: 2023-09-05T10:17:48+00:00

Actual source code: primme.c
slepc-3.19.2 2023-09-05
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: */
     10: /*
     11:    This file implements a wrapper to the PRIMME package
     12: */

     14: #include <slepc/private/epsimpl.h>

     16: #include <primme.h>

     18: #if defined(PETSC_USE_COMPLEX)
     19: #if defined(PETSC_USE_REAL_SINGLE)
     20: #define PRIMME_DRIVER cprimme
     21: #else
     22: #define PRIMME_DRIVER zprimme
     23: #endif
     24: #else
     25: #if defined(PETSC_USE_REAL_SINGLE)
     26: #define PRIMME_DRIVER sprimme
     27: #else
     28: #define PRIMME_DRIVER dprimme
     29: #endif
     30: #endif

     32: #if defined(PRIMME_VERSION_MAJOR) && PRIMME_VERSION_MAJOR*100+PRIMME_VERSION_MINOR >= 202
     33: #define SLEPC_HAVE_PRIMME2p2
     34: #endif

     36: typedef struct {
     37:   primme_params        primme;    /* param struct */
     38:   PetscInt             bs;        /* block size */
     39:   primme_preset_method method;    /* primme method */
     40:   Mat                  A,B;       /* problem matrices */
     41:   KSP                  ksp;       /* linear solver and preconditioner */
     42:   Vec                  x,y;       /* auxiliary vectors */
     43:   double               target;    /* a copy of eps's target */
     44: } EPS_PRIMME;

     46: static void par_GlobalSumReal(void *sendBuf,void *recvBuf,int *count,primme_params *primme,int *ierr)
     47: {
     48:   if (sendBuf == recvBuf) {
     49:     *ierr = MPI_Allreduce(MPI_IN_PLACE,recvBuf,*count,MPIU_REAL,MPIU_SUM,PetscObjectComm((PetscObject)primme->commInfo));
     50:   } else {
     51:     *ierr = MPI_Allreduce(sendBuf,recvBuf,*count,MPIU_REAL,MPIU_SUM,PetscObjectComm((PetscObject)primme->commInfo));
     52:   }
     53: }

     55: #if defined(SLEPC_HAVE_PRIMME3)
     56: static void par_broadcastReal(void *buf,int *count,primme_params *primme,int *ierr)
     57: {
     58:   *ierr = MPI_Bcast(buf,*count,MPIU_REAL,0/*root*/,PetscObjectComm((PetscObject)primme->commInfo));
     59: }
     60: #endif

     62: #if defined(SLEPC_HAVE_PRIMME2p2)
     63: static void convTestFun(double *eval,void *evec,double *resNorm,int *isconv,primme_params *primme,int *err)
     64: {
     65:   PetscErrorCode ierr;
     66:   EPS            eps = (EPS)primme->commInfo;
     67:   PetscScalar    eigvr = eval?*eval:0.0;
     68:   PetscReal      r = resNorm?*resNorm:HUGE_VAL,errest;

     70:   ierr = (*eps->converged)(eps,eigvr,0.0,r,&errest,eps->convergedctx);
     71:   if (ierr) *err = 1;
     72:   else {
     73:     *isconv = (errest<=eps->tol?1:0);
     74:     *err = 0;
     75:   }
     76: }

     78: static void monitorFun(void *basisEvals,int *basisSize,int *basisFlags,int *iblock,int *blockSize,void *basisNorms,int *numConverged,void *lockedEvals,int *numLocked,int *lockedFlags,void *lockedNorms,int *inner_its,void *LSRes,
     79: #if defined(SLEPC_HAVE_PRIMME3)
     80:                        const char *msg,double *time,
     81: #endif
     82:                        primme_event *event,struct primme_params *primme,int *err)
     83: {
     84:   PetscErrorCode ierr = PETSC_SUCCESS;
     85:   EPS            eps = (EPS)primme->commInfo;
     86:   PetscInt       i,k,nerrest;

     88:   switch (*event) {
     89:     case primme_event_outer_iteration:
     90:       /* Update EPS */
     91:       eps->its = primme->stats.numOuterIterations;
     92:       eps->nconv = primme->initSize;
     93:       k=0;
     94:       if (lockedEvals && numLocked) for (i=0; i<*numLocked && k<eps->ncv; i++) eps->eigr[k++] = ((PetscReal*)lockedEvals)[i];
     95:       nerrest = k;
     96:       if (iblock && blockSize) {
     97:         for (i=0; i<*blockSize && k+iblock[i]<eps->ncv; i++) eps->errest[k+iblock[i]] = ((PetscReal*)basisNorms)[i];
     98:         nerrest = k+(*blockSize>0?1+iblock[*blockSize-1]:0);
     99:       }
    100:       if (basisEvals && basisSize) for (i=0; i<*basisSize && k<eps->ncv; i++) eps->eigr[k++] = ((PetscReal*)basisEvals)[i];
    101:       /* Show progress */
    102:       ierr = EPSMonitor(eps,eps->its,numConverged?*numConverged:0,eps->eigr,eps->eigi,eps->errest,nerrest);
    103:       break;
    104: #if defined(SLEPC_HAVE_PRIMME3)
    105:     case primme_event_message:
    106:       /* Print PRIMME information messages */
    107:       ierr = PetscInfo(eps,"%s\n",msg);
    108:       break;
    109: #endif
    110:     default:
    111:       break;
    112:   }
    113:   *err = (ierr!=0)? 1: 0;
    114: }
    115: #endif /* SLEPC_HAVE_PRIMME2p2 */

    117: static void matrixMatvec_PRIMME(void *xa,PRIMME_INT *ldx,void *ya,PRIMME_INT *ldy,int *blockSize,struct primme_params *primme,int *ierr)
    118: {
    119:   PetscInt   i;
    120:   EPS_PRIMME *ops = (EPS_PRIMME*)primme->matrix;
    121:   Vec        x = ops->x,y = ops->y;
    122:   Mat        A = ops->A;

    124:   PetscFunctionBegin;
    125:   for (i=0;i<*blockSize;i++) {
    126:     PetscCallAbort(PetscObjectComm((PetscObject)A),VecPlaceArray(x,(PetscScalar*)xa+(*ldx)*i));
    127:     PetscCallAbort(PetscObjectComm((PetscObject)A),VecPlaceArray(y,(PetscScalar*)ya+(*ldy)*i));
    128:     PetscCallAbort(PetscObjectComm((PetscObject)A),MatMult(A,x,y));
    129:     PetscCallAbort(PetscObjectComm((PetscObject)A),VecResetArray(x));
    130:     PetscCallAbort(PetscObjectComm((PetscObject)A),VecResetArray(y));
    131:   }
    132:   PetscFunctionReturnVoid();
    133: }

    135: #if defined(SLEPC_HAVE_PRIMME3)
    136: static void massMatrixMatvec_PRIMME(void *xa,PRIMME_INT *ldx,void *ya,PRIMME_INT *ldy,int *blockSize,struct primme_params *primme,int *ierr)
    137: {
    138:   PetscInt   i;
    139:   EPS_PRIMME *ops = (EPS_PRIMME*)primme->massMatrix;
    140:   Vec        x = ops->x,y = ops->y;
    141:   Mat        B = ops->B;

    143:   PetscFunctionBegin;
    144:   for (i=0;i<*blockSize;i++) {
    145:     PetscCallAbort(PetscObjectComm((PetscObject)B),VecPlaceArray(x,(PetscScalar*)xa+(*ldx)*i));
    146:     PetscCallAbort(PetscObjectComm((PetscObject)B),VecPlaceArray(y,(PetscScalar*)ya+(*ldy)*i));
    147:     PetscCallAbort(PetscObjectComm((PetscObject)B),MatMult(B,x,y));
    148:     PetscCallAbort(PetscObjectComm((PetscObject)B),VecResetArray(x));
    149:     PetscCallAbort(PetscObjectComm((PetscObject)B),VecResetArray(y));
    150:   }
    151:   PetscFunctionReturnVoid();
    152: }
    153: #endif

    155: static void applyPreconditioner_PRIMME(void *xa,PRIMME_INT *ldx,void *ya,PRIMME_INT *ldy,int *blockSize,struct primme_params *primme,int *ierr)
    156: {
    157:   PetscInt   i;
    158:   EPS_PRIMME *ops = (EPS_PRIMME*)primme->matrix;
    159:   Vec        x = ops->x,y = ops->y;

    161:   PetscFunctionBegin;
    162:   for (i=0;i<*blockSize;i++) {
    163:     PetscCallAbort(PetscObjectComm((PetscObject)ops->ksp),VecPlaceArray(x,(PetscScalar*)xa+(*ldx)*i));
    164:     PetscCallAbort(PetscObjectComm((PetscObject)ops->ksp),VecPlaceArray(y,(PetscScalar*)ya+(*ldy)*i));
    165:     PetscCallAbort(PetscObjectComm((PetscObject)ops->ksp),KSPSolve(ops->ksp,x,y));
    166:     PetscCallAbort(PetscObjectComm((PetscObject)ops->ksp),VecResetArray(x));
    167:     PetscCallAbort(PetscObjectComm((PetscObject)ops->ksp),VecResetArray(y));
    168:   }
    169:   PetscFunctionReturnVoid();
    170: }

    172: PetscErrorCode EPSSetUp_PRIMME(EPS eps)
    173: {
    174:   PetscMPIInt    numProcs,procID;
    175:   EPS_PRIMME     *ops = (EPS_PRIMME*)eps->data;
    176:   primme_params  *primme = &ops->primme;
    177:   PetscBool      flg;

    179:   PetscFunctionBegin;
    180:   EPSCheckHermitianDefinite(eps);
    181:   PetscCallMPI(MPI_Comm_size(PetscObjectComm((PetscObject)eps),&numProcs));
    182:   PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)eps),&procID));

    184:   /* Check some constraints and set some default values */
    185:   if (eps->max_it==PETSC_DEFAULT) eps->max_it = PETSC_MAX_INT;
    186:   PetscCall(STGetMatrix(eps->st,0,&ops->A));
    187:   if (eps->isgeneralized) {
    188: #if defined(SLEPC_HAVE_PRIMME3)
    189:     PetscCall(STGetMatrix(eps->st,1,&ops->B));
    190: #else
    191:     SETERRQ(PetscObjectComm((PetscObject)eps),PETSC_ERR_SUP,"This version of PRIMME is not available for generalized problems");
    192: #endif
    193:   }
    194:   EPSCheckUnsupported(eps,EPS_FEATURE_ARBITRARY | EPS_FEATURE_REGION | EPS_FEATURE_STOPPING);
    195:   EPSCheckIgnored(eps,EPS_FEATURE_BALANCE);
    196:   if (!eps->which) eps->which = EPS_LARGEST_REAL;
    197: #if !defined(SLEPC_HAVE_PRIMME2p2)
    198:   if (eps->converged != EPSConvergedAbsolute) PetscCall(PetscInfo(eps,"Warning: using absolute convergence test\n"));
    199: #else
    200:   EPSCheckIgnored(eps,EPS_FEATURE_CONVERGENCE);
    201: #endif

    203:   /* Transfer SLEPc options to PRIMME options */
    204:   primme_free(primme);
    205:   primme_initialize(primme);
    206:   primme->n                             = eps->n;
    207:   primme->nLocal                        = eps->nloc;
    208:   primme->numEvals                      = eps->nev;
    209:   primme->matrix                        = ops;
    210:   primme->matrixMatvec                  = matrixMatvec_PRIMME;
    211: #if defined(SLEPC_HAVE_PRIMME3)
    212:   if (eps->isgeneralized) {
    213:     primme->massMatrix                  = ops;
    214:     primme->massMatrixMatvec            = massMatrixMatvec_PRIMME;
    215:   }
    216: #endif
    217:   primme->commInfo                      = eps;
    218:   primme->maxOuterIterations            = eps->max_it;
    219: #if !defined(SLEPC_HAVE_PRIMME2p2)
    220:   primme->eps                           = SlepcDefaultTol(eps->tol);
    221: #endif
    222:   primme->numProcs                      = numProcs;
    223:   primme->procID                        = procID;
    224:   primme->printLevel                    = 1;
    225:   primme->correctionParams.precondition = 1;
    226:   primme->globalSumReal                 = par_GlobalSumReal;
    227: #if defined(SLEPC_HAVE_PRIMME3)
    228:   primme->broadcastReal                 = par_broadcastReal;
    229: #endif
    230: #if defined(SLEPC_HAVE_PRIMME2p2)
    231:   primme->convTestFun                   = convTestFun;
    232:   primme->monitorFun                    = monitorFun;
    233: #endif
    234:   if (ops->bs > 0) primme->maxBlockSize = ops->bs;

    236:   switch (eps->which) {
    237:     case EPS_LARGEST_REAL:
    238:       primme->target = primme_largest;
    239:       break;
    240:     case EPS_SMALLEST_REAL:
    241:       primme->target = primme_smallest;
    242:       break;
    243:     case EPS_LARGEST_MAGNITUDE:
    244:       primme->target = primme_largest_abs;
    245:       ops->target = 0.0;
    246:       primme->numTargetShifts = 1;
    247:       primme->targetShifts = &ops->target;
    248:       break;
    249:     case EPS_SMALLEST_MAGNITUDE:
    250:       primme->target = primme_closest_abs;
    251:       ops->target = 0.0;
    252:       primme->numTargetShifts = 1;
    253:       primme->targetShifts = &ops->target;
    254:       break;
    255:     case EPS_TARGET_MAGNITUDE:
    256:     case EPS_TARGET_REAL:
    257:       primme->target = primme_closest_abs;
    258:       primme->numTargetShifts = 1;
    259:       ops->target = PetscRealPart(eps->target);
    260:       primme->targetShifts = &ops->target;
    261:       break;
    262:     default:
    263:       SETERRQ(PetscObjectComm((PetscObject)eps),PETSC_ERR_SUP,"'which' value not supported by PRIMME");
    264:   }

    266:   switch (eps->extraction) {
    267:     case EPS_RITZ:
    268:       primme->projectionParams.projection = primme_proj_RR;
    269:       break;
    270:     case EPS_HARMONIC:
    271:       primme->projectionParams.projection = primme_proj_harmonic;
    272:       break;
    273:     case EPS_REFINED:
    274:       primme->projectionParams.projection = primme_proj_refined;
    275:       break;
    276:     default:
    277:       SETERRQ(PetscObjectComm((PetscObject)eps),PETSC_ERR_SUP,"'extraction' value not supported by PRIMME");
    278:   }

    280:   /* If user sets mpd or ncv, maxBasisSize is modified */
    281:   if (eps->mpd!=PETSC_DEFAULT) {
    282:     primme->maxBasisSize = eps->mpd;
    283:     if (eps->ncv!=PETSC_DEFAULT) PetscCall(PetscInfo(eps,"Warning: 'ncv' is ignored by PRIMME\n"));
    284:   } else if (eps->ncv!=PETSC_DEFAULT) primme->maxBasisSize = eps->ncv;

    286:   PetscCheck(primme_set_method(ops->method,primme)>=0,PetscObjectComm((PetscObject)eps),PETSC_ERR_SUP,"PRIMME method not valid");

    288:   eps->mpd = primme->maxBasisSize;
    289:   eps->ncv = (primme->locking?eps->nev:0)+primme->maxBasisSize;
    290:   ops->bs  = primme->maxBlockSize;

    292:   /* Set workspace */
    293:   PetscCall(EPSAllocateSolution(eps,0));

    295:   /* Setup the preconditioner */
    296:   if (primme->correctionParams.precondition) {
    297:     PetscCall(STGetKSP(eps->st,&ops->ksp));
    298:     PetscCall(PetscObjectTypeCompare((PetscObject)ops->ksp,KSPPREONLY,&flg));
    299:     if (!flg) PetscCall(PetscInfo(eps,"Warning: ignoring KSP, should use KSPPREONLY\n"));
    300:     primme->preconditioner = NULL;
    301:     primme->applyPreconditioner = applyPreconditioner_PRIMME;
    302:   }

    304:   /* Prepare auxiliary vectors */
    305:   if (!ops->x) PetscCall(MatCreateVecsEmpty(ops->A,&ops->x,&ops->y));
    306:   PetscFunctionReturn(PETSC_SUCCESS);
    307: }

    309: PetscErrorCode EPSSolve_PRIMME(EPS eps)
    310: {
    311:   EPS_PRIMME     *ops = (EPS_PRIMME*)eps->data;
    312:   PetscScalar    *a;
    313:   PetscInt       i,ierrprimme;
    314:   PetscReal      *evals,*rnorms;

    316:   PetscFunctionBegin;
    317:   /* Reset some parameters left from previous runs */
    318: #if defined(SLEPC_HAVE_PRIMME2p2)
    319:   ops->primme.aNorm    = 0.0;
    320: #else
    321:   /* Force PRIMME to stop by absolute error */
    322:   ops->primme.aNorm    = 1.0;
    323: #endif
    324:   ops->primme.initSize = eps->nini;
    325:   ops->primme.iseed[0] = -1;
    326:   ops->primme.iseed[1] = -1;
    327:   ops->primme.iseed[2] = -1;
    328:   ops->primme.iseed[3] = -1;

    330:   /* Call PRIMME solver */
    331:   PetscCall(BVGetArray(eps->V,&a));
    332:   PetscCall(PetscMalloc2(eps->ncv,&evals,eps->ncv,&rnorms));
    333:   ierrprimme = PRIMME_DRIVER(evals,a,rnorms,&ops->primme);
    334:   for (i=0;i<eps->ncv;i++) eps->eigr[i] = evals[i];
    335:   for (i=0;i<eps->ncv;i++) eps->errest[i] = rnorms[i];
    336:   PetscCall(PetscFree2(evals,rnorms));
    337:   PetscCall(BVRestoreArray(eps->V,&a));

    339:   eps->nconv  = ops->primme.initSize >= 0 ? ops->primme.initSize : 0;
    340:   eps->reason = eps->nconv >= eps->nev ? EPS_CONVERGED_TOL: EPS_DIVERGED_ITS;
    341:   eps->its    = ops->primme.stats.numOuterIterations;

    343:   /* Process PRIMME error code */
    344:   switch (ierrprimme) {
    345:     case 0: /* no error */
    346:       break;
    347:     case -1:
    348:       SETERRQ(PetscObjectComm((PetscObject)eps),PETSC_ERR_LIB,"PRIMME library failed with error code=%" PetscInt_FMT ": unexpected error",ierrprimme);
    349:     case -2:
    350:       SETERRQ(PetscObjectComm((PetscObject)eps),PETSC_ERR_LIB,"PRIMME library failed with error code=%" PetscInt_FMT ": allocation error",ierrprimme);
    351:     case -3: /* stop due to maximum number of iterations or matvecs */
    352:       break;
    353:     default:
    354:       PetscCheck(ierrprimme<-39,PetscObjectComm((PetscObject)eps),PETSC_ERR_LIB,"PRIMME library failed with error code=%" PetscInt_FMT ": configuration error; check PRIMME's manual",ierrprimme);
    355:       PetscCheck(ierrprimme>=-39,PetscObjectComm((PetscObject)eps),PETSC_ERR_LIB,"PRIMME library failed with error code=%" PetscInt_FMT ": runtime error; check PRIMME's manual",ierrprimme);
    356:   }
    357:   PetscFunctionReturn(PETSC_SUCCESS);
    358: }

    360: PetscErrorCode EPSReset_PRIMME(EPS eps)
    361: {
    362:   EPS_PRIMME     *ops = (EPS_PRIMME*)eps->data;

    364:   PetscFunctionBegin;
    365:   primme_free(&ops->primme);
    366:   PetscCall(VecDestroy(&ops->x));
    367:   PetscCall(VecDestroy(&ops->y));
    368:   PetscFunctionReturn(PETSC_SUCCESS);
    369: }

    371: PetscErrorCode EPSDestroy_PRIMME(EPS eps)
    372: {
    373:   PetscFunctionBegin;
    374:   PetscCall(PetscFree(eps->data));
    375:   PetscCall(PetscObjectComposeFunction((PetscObject)eps,"EPSPRIMMESetBlockSize_C",NULL));
    376:   PetscCall(PetscObjectComposeFunction((PetscObject)eps,"EPSPRIMMESetMethod_C",NULL));
    377:   PetscCall(PetscObjectComposeFunction((PetscObject)eps,"EPSPRIMMEGetBlockSize_C",NULL));
    378:   PetscCall(PetscObjectComposeFunction((PetscObject)eps,"EPSPRIMMEGetMethod_C",NULL));
    379:   PetscFunctionReturn(PETSC_SUCCESS);
    380: }

    382: PetscErrorCode EPSView_PRIMME(EPS eps,PetscViewer viewer)
    383: {
    384:   PetscBool      isascii;
    385:   EPS_PRIMME     *ctx = (EPS_PRIMME*)eps->data;
    386:   PetscMPIInt    rank;

    388:   PetscFunctionBegin;
    389:   PetscCall(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii));
    390:   if (isascii) {
    391:     PetscCall(PetscViewerASCIIPrintf(viewer,"  block size=%" PetscInt_FMT "\n",ctx->bs));
    392:     PetscCall(PetscViewerASCIIPrintf(viewer,"  solver method: %s\n",EPSPRIMMEMethods[(EPSPRIMMEMethod)ctx->method]));

    394:     /* Display PRIMME params */
    395:     PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)eps),&rank));
    396:     if (!rank) primme_display_params(ctx->primme);
    397:   }
    398:   PetscFunctionReturn(PETSC_SUCCESS);
    399: }

    401: PetscErrorCode EPSSetFromOptions_PRIMME(EPS eps,PetscOptionItems *PetscOptionsObject)
    402: {
    403:   EPS_PRIMME      *ctx = (EPS_PRIMME*)eps->data;
    404:   PetscInt        bs;
    405:   EPSPRIMMEMethod meth;
    406:   PetscBool       flg;

    408:   PetscFunctionBegin;
    409:   PetscOptionsHeadBegin(PetscOptionsObject,"EPS PRIMME Options");

    411:     PetscCall(PetscOptionsInt("-eps_primme_blocksize","Maximum block size","EPSPRIMMESetBlockSize",ctx->bs,&bs,&flg));
    412:     if (flg) PetscCall(EPSPRIMMESetBlockSize(eps,bs));

    414:     PetscCall(PetscOptionsEnum("-eps_primme_method","Method for solving the eigenproblem","EPSPRIMMESetMethod",EPSPRIMMEMethods,(PetscEnum)ctx->method,(PetscEnum*)&meth,&flg));
    415:     if (flg) PetscCall(EPSPRIMMESetMethod(eps,meth));

    417:   PetscOptionsHeadEnd();
    418:   PetscFunctionReturn(PETSC_SUCCESS);
    419: }

    421: static PetscErrorCode EPSPRIMMESetBlockSize_PRIMME(EPS eps,PetscInt bs)
    422: {
    423:   EPS_PRIMME *ops = (EPS_PRIMME*)eps->data;

    425:   PetscFunctionBegin;
    426:   if (bs == PETSC_DEFAULT) ops->bs = 0;
    427:   else {
    428:     PetscCheck(bs>0,PetscObjectComm((PetscObject)eps),PETSC_ERR_ARG_OUTOFRANGE,"PRIMME: block size must be positive");
    429:     ops->bs = bs;
    430:   }
    431:   PetscFunctionReturn(PETSC_SUCCESS);
    432: }

    434: /*@
    435:    EPSPRIMMESetBlockSize - The maximum block size that PRIMME will try to use.

    437:    Logically Collective

    439:    Input Parameters:
    440: +  eps - the eigenproblem solver context
    441: -  bs - block size

    443:    Options Database Key:
    444: .  -eps_primme_blocksize - Sets the max allowed block size value

    446:    Notes:
    447:    If the block size is not set, the value established by primme_initialize
    448:    is used.

    450:    The user should set the block size based on the architecture specifics
    451:    of the target computer, as well as any a priori knowledge of multiplicities.
    452:    The code does NOT require bs > 1 to find multiple eigenvalues. For some
    453:    methods, keeping bs = 1 yields the best overall performance.

    455:    Level: advanced

    457: .seealso: EPSPRIMMEGetBlockSize()
    458: @*/
    459: PetscErrorCode EPSPRIMMESetBlockSize(EPS eps,PetscInt bs)
    460: {
    461:   PetscFunctionBegin;
    464:   PetscTryMethod(eps,"EPSPRIMMESetBlockSize_C",(EPS,PetscInt),(eps,bs));
    465:   PetscFunctionReturn(PETSC_SUCCESS);
    466: }

    468: static PetscErrorCode EPSPRIMMEGetBlockSize_PRIMME(EPS eps,PetscInt *bs)
    469: {
    470:   EPS_PRIMME *ops = (EPS_PRIMME*)eps->data;

    472:   PetscFunctionBegin;
    473:   *bs = ops->bs;
    474:   PetscFunctionReturn(PETSC_SUCCESS);
    475: }

    477: /*@
    478:    EPSPRIMMEGetBlockSize - Get the maximum block size the code will try to use.

    480:    Not Collective

    482:    Input Parameter:
    483: .  eps - the eigenproblem solver context

    485:    Output Parameter:
    486: .  bs - returned block size

    488:    Level: advanced

    490: .seealso: EPSPRIMMESetBlockSize()
    491: @*/
    492: PetscErrorCode EPSPRIMMEGetBlockSize(EPS eps,PetscInt *bs)
    493: {
    494:   PetscFunctionBegin;
    497:   PetscUseMethod(eps,"EPSPRIMMEGetBlockSize_C",(EPS,PetscInt*),(eps,bs));
    498:   PetscFunctionReturn(PETSC_SUCCESS);
    499: }

    501: static PetscErrorCode EPSPRIMMESetMethod_PRIMME(EPS eps,EPSPRIMMEMethod method)
    502: {
    503:   EPS_PRIMME *ops = (EPS_PRIMME*)eps->data;

    505:   PetscFunctionBegin;
    506:   ops->method = (primme_preset_method)method;
    507:   PetscFunctionReturn(PETSC_SUCCESS);
    508: }

    510: /*@
    511:    EPSPRIMMESetMethod - Sets the method for the PRIMME library.

    513:    Logically Collective

    515:    Input Parameters:
    516: +  eps - the eigenproblem solver context
    517: -  method - method that will be used by PRIMME

    519:    Options Database Key:
    520: .  -eps_primme_method - Sets the method for the PRIMME library

    522:    Note:
    523:    If not set, the method defaults to EPS_PRIMME_DEFAULT_MIN_TIME.

    525:    Level: advanced

    527: .seealso: EPSPRIMMEGetMethod(), EPSPRIMMEMethod
    528: @*/
    529: PetscErrorCode EPSPRIMMESetMethod(EPS eps,EPSPRIMMEMethod method)
    530: {
    531:   PetscFunctionBegin;
    534:   PetscTryMethod(eps,"EPSPRIMMESetMethod_C",(EPS,EPSPRIMMEMethod),(eps,method));
    535:   PetscFunctionReturn(PETSC_SUCCESS);
    536: }

    538: static PetscErrorCode EPSPRIMMEGetMethod_PRIMME(EPS eps,EPSPRIMMEMethod *method)
    539: {
    540:   EPS_PRIMME *ops = (EPS_PRIMME*)eps->data;

    542:   PetscFunctionBegin;
    543:   *method = (EPSPRIMMEMethod)ops->method;
    544:   PetscFunctionReturn(PETSC_SUCCESS);
    545: }

    547: /*@
    548:    EPSPRIMMEGetMethod - Gets the method for the PRIMME library.

    550:    Not Collective

    552:    Input Parameter:
    553: .  eps - the eigenproblem solver context

    555:    Output Parameter:
    556: .  method - method that will be used by PRIMME

    558:    Level: advanced

    560: .seealso: EPSPRIMMESetMethod(), EPSPRIMMEMethod
    561: @*/
    562: PetscErrorCode EPSPRIMMEGetMethod(EPS eps,EPSPRIMMEMethod *method)
    563: {
    564:   PetscFunctionBegin;
    567:   PetscUseMethod(eps,"EPSPRIMMEGetMethod_C",(EPS,EPSPRIMMEMethod*),(eps,method));
    568:   PetscFunctionReturn(PETSC_SUCCESS);
    569: }

    571: SLEPC_EXTERN PetscErrorCode EPSCreate_PRIMME(EPS eps)
    572: {
    573:   EPS_PRIMME     *primme;

    575:   PetscFunctionBegin;
    576:   PetscCall(PetscNew(&primme));
    577:   eps->data = (void*)primme;

    579:   primme_initialize(&primme->primme);
    580:   primme->primme.globalSumReal = par_GlobalSumReal;
    581: #if defined(SLEPC_HAVE_PRIMME3)
    582:   primme->primme.broadcastReal = par_broadcastReal;
    583: #endif
    584: #if defined(SLEPC_HAVE_PRIMME2p2)
    585:   primme->primme.convTestFun = convTestFun;
    586:   primme->primme.monitorFun = monitorFun;
    587: #endif
    588:   primme->method = (primme_preset_method)EPS_PRIMME_DEFAULT_MIN_TIME;

    590:   eps->categ = EPS_CATEGORY_PRECOND;

    592:   eps->ops->solve          = EPSSolve_PRIMME;
    593:   eps->ops->setup          = EPSSetUp_PRIMME;
    594:   eps->ops->setupsort      = EPSSetUpSort_Basic;
    595:   eps->ops->setfromoptions = EPSSetFromOptions_PRIMME;
    596:   eps->ops->destroy        = EPSDestroy_PRIMME;
    597:   eps->ops->reset          = EPSReset_PRIMME;
    598:   eps->ops->view           = EPSView_PRIMME;
    599:   eps->ops->backtransform  = EPSBackTransform_Default;
    600:   eps->ops->setdefaultst   = EPSSetDefaultST_GMRES;

    602:   PetscCall(PetscObjectComposeFunction((PetscObject)eps,"EPSPRIMMESetBlockSize_C",EPSPRIMMESetBlockSize_PRIMME));
    603:   PetscCall(PetscObjectComposeFunction((PetscObject)eps,"EPSPRIMMESetMethod_C",EPSPRIMMESetMethod_PRIMME));
    604:   PetscCall(PetscObjectComposeFunction((PetscObject)eps,"EPSPRIMMEGetBlockSize_C",EPSPRIMMEGetBlockSize_PRIMME));
    605:   PetscCall(PetscObjectComposeFunction((PetscObject)eps,"EPSPRIMMEGetMethod_C",EPSPRIMMEGetMethod_PRIMME));
    606:   PetscFunctionReturn(PETSC_SUCCESS);
    607: }