Actual source code: slepc-interface.c
slepc-3.10.1 2018-10-23
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2018, 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:    Modification of the *temp* implementation of the BLOPEX multivector in order
     12:    to wrap created PETSc vectors as multivectors.
     13: */

     15: #include <slepc/private/bvimpl.h>
     16: #include <stdlib.h>
     17: #include <blopex_interpreter.h>
     18: #include <blopex_temp_multivector.h>
     19: #include "slepc-interface.h"

     21: static void* mv_TempMultiVectorCreateFromBV(void* ii_,BlopexInt n,void* sample)
     22: {
     23:   PetscErrorCode          ierr;
     24:   BV                      bv = (BV)sample;
     25:   Vec                     v;
     26:   PetscInt                i,l,k,nc,useconstr=PETSC_FALSE,flg;
     27:   mv_TempMultiVector      *x;
     28:   mv_InterfaceInterpreter *ii = (mv_InterfaceInterpreter*)ii_;

     30:   x = (mv_TempMultiVector*)malloc(sizeof(mv_TempMultiVector));
     31:   if (!x) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Allocation for x failed");

     33:   x->interpreter = ii;
     34:   x->numVectors  = n;

     36:   x->vector = (void**)calloc(n,sizeof(void*));
     37:   if (!x->vector) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Allocation for x->vector failed");

     39:   x->ownsVectors = 1;
     40:   x->mask = NULL;
     41:   x->ownsMask = 0;

     43:   BVGetActiveColumns(bv,&l,&k);CHKERRABORT(PETSC_COMM_SELF,ierr);
     44:   PetscObjectComposedDataGetInt((PetscObject)bv,slepc_blopex_useconstr,useconstr,flg);CHKERRABORT(PETSC_COMM_SELF,ierr);
     45:   if (!l && useconstr) {
     46:     BVGetNumConstraints(bv,&nc);CHKERRABORT(PETSC_COMM_SELF,ierr);
     47:     l = -nc;
     48:   }
     49:   if (n != k-l) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"BV active columns plus constraints do not match argument n");
     50:   for (i=0;i<n;i++) {
     51:     BVGetColumn(bv,l+i,&v);CHKERRABORT(PETSC_COMM_SELF,ierr);
     52:     PetscObjectReference((PetscObject)v);CHKERRABORT(PETSC_COMM_SELF,ierr);
     53:     x->vector[i] = (void*)v;
     54:     BVRestoreColumn(bv,l+i,&v);CHKERRABORT(PETSC_COMM_SELF,ierr);
     55:   }
     56:   return x;
     57: }

     59: static void mv_TempMultiPETSCVectorDestroy(void* x_)
     60: {
     61:   mv_TempMultiVector* x = (mv_TempMultiVector*)x_;

     63:   if (!x) return;

     65:   if (x->ownsVectors && x->vector) free(x->vector);
     66:   if (x->mask && x->ownsMask) free(x->mask);
     67:   free(x);
     68: }

     70: /*
     71:     Create an InterfaceInterpreter using the PETSc implementation
     72:     but overloading CreateMultiVector that doesn't create any
     73:     new vector.
     74: */
     75: int SLEPCSetupInterpreter(mv_InterfaceInterpreter *i)
     76: {
     77:   PETSCSetupInterpreter(i);
     78:   i->CreateMultiVector = mv_TempMultiVectorCreateFromBV;

     80:   return 0;
     81: }

     83: /*
     84:     Change the multivector destructor in order to destroy the multivector
     85:     structure without destroy the PETSc vectors.
     86: */
     87: void SLEPCSetupInterpreterForDignifiedDeath(mv_InterfaceInterpreter *i)
     88: {
     89:   i->DestroyMultiVector = mv_TempMultiPETSCVectorDestroy;
     90: }