Date: 2015-09-03T15:04:59+00:00

Actual source code: slepc-interface.c
slepc-3.6.1 2015-09-03
Report Typos and Errors

      1: /*
      2:    Modification of the *temp* implementation of the BLOPEX multivector in order
      3:    to wrap created PETSc vectors as multivectors.

      5:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      6:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      7:    Copyright (c) 2002-2015, Universitat Politecnica de Valencia, Spain

      9:    This file is part of SLEPc.

     11:    SLEPc is free software: you can redistribute it and/or modify it under  the
     12:    terms of version 3 of the GNU Lesser General Public License as published by
     13:    the Free Software Foundation.

     15:    SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
     16:    WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
     17:    FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
     18:    more details.

     20:    You  should have received a copy of the GNU Lesser General  Public  License
     21:    along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
     22:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     23: */

     25: #include <slepc/private/bvimpl.h>
     26: #include <stdlib.h>
     27: #include <blopex_interpreter.h>
     28: #include <blopex_temp_multivector.h>
     29: #include "slepc-interface.h"

     31: static void* mv_TempMultiVectorCreateFromBV(void* ii_,BlopexInt n,void* sample)
     32: {
     33:   PetscErrorCode          ierr;
     34:   BV                      bv = (BV)sample;
     35:   Vec                     v;
     36:   PetscInt                i,l,k,nc,useconstr=PETSC_FALSE,flg;
     37:   mv_TempMultiVector      *x;
     38:   mv_InterfaceInterpreter *ii = (mv_InterfaceInterpreter*)ii_;

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

     43:   x->interpreter = ii;
     44:   x->numVectors  = n;

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

     49:   x->ownsVectors = 1;
     50:   x->mask = NULL;
     51:   x->ownsMask = 0;

     53:   BVGetActiveColumns(bv,&l,&k);CHKERRABORT(PETSC_COMM_SELF,ierr);
     54:   PetscObjectComposedDataGetInt((PetscObject)bv,SLEPC_BLOPEX_USECONSTR,useconstr,flg);CHKERRABORT(PETSC_COMM_SELF,ierr);
     55:   if (!l && useconstr) {
     56:     BVGetNumConstraints(bv,&nc);CHKERRABORT(PETSC_COMM_SELF,ierr);
     57:     l = -nc;
     58:   }
     59:   if (n != k-l) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"BV active columns plus constraints do not match argument n");
     60:   for (i=0;i<n;i++) {
     61:     BVGetColumn(bv,l+i,&v);CHKERRABORT(PETSC_COMM_SELF,ierr);
     62:     PetscObjectReference((PetscObject)v);CHKERRABORT(PETSC_COMM_SELF,ierr);
     63:     x->vector[i] = (void*)v;
     64:     BVRestoreColumn(bv,l+i,&v);CHKERRABORT(PETSC_COMM_SELF,ierr);
     65:   }
     66:   return x;
     67: }

     69: static void mv_TempMultiPETSCVectorDestroy(void* x_)
     70: {
     71:   mv_TempMultiVector* x = (mv_TempMultiVector*)x_;

     73:   if (!x) return;

     75:   if (x->ownsVectors && x->vector) free(x->vector);
     76:   if (x->mask && x->ownsMask) free(x->mask);
     77:   free(x);
     78: }

     80: /*
     81:     Create an InterfaceInterpreter using the PETSc implementation
     82:     but overloading CreateMultiVector that doesn't create any
     83:     new vector.
     84: */
     85: int SLEPCSetupInterpreter(mv_InterfaceInterpreter *i)
     86: {
     87:   PETSCSetupInterpreter(i);
     88:   i->CreateMultiVector = mv_TempMultiVectorCreateFromBV;

     90:   return 0;
     91: }

     93: /*
     94:     Change the multivector destructor in order to destroy the multivector
     95:     structure without destroy the PETSc vectors.
     96: */
     97: void SLEPCSetupInterpreterForDignifiedDeath(mv_InterfaceInterpreter *i)
     98: {
     99:   i->DestroyMultiVector = mv_TempMultiPETSCVectorDestroy;
    100: }