Date: 2022-11-02T11:46:27+00:00

Actual source code: test13.c
slepc-3.18.1 2022-11-02
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: static char help[] = "Test BV operations using internal buffer instead of array arguments.\n\n";

     13: #include <slepcbv.h>

     15: int main(int argc,char **argv)
     16: {
     17:   Vec            t,v,z;
     18:   BV             X;
     19:   PetscInt       i,j,n=10,k=5,l=3;
     20:   PetscReal      nrm;
     21:   PetscViewer    view;
     22:   PetscBool      verbose;

     25:   SlepcInitialize(&argc,&argv,(char*)0,help);
     26:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     27:   PetscOptionsGetInt(NULL,NULL,"-k",&k,NULL);
     28:   PetscOptionsGetInt(NULL,NULL,"-l",&l,NULL);
     29:   PetscOptionsHasName(NULL,NULL,"-verbose",&verbose);
     30:   PetscPrintf(PETSC_COMM_WORLD,"Test BV with %" PetscInt_FMT " columns of dimension %" PetscInt_FMT ".\n",k,n);

     32:   /* Create template vector */
     33:   VecCreate(PETSC_COMM_WORLD,&t);
     34:   VecSetSizes(t,PETSC_DECIDE,n);
     35:   VecSetFromOptions(t);

     37:   /* Create BV object X */
     38:   BVCreate(PETSC_COMM_WORLD,&X);
     39:   PetscObjectSetName((PetscObject)X,"X");
     40:   BVSetSizesFromVec(X,t,k);
     41:   BVSetFromOptions(X);

     43:   /* Set up viewer */
     44:   PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&view);
     45:   if (verbose) PetscViewerPushFormat(view,PETSC_VIEWER_ASCII_MATLAB);

     47:   /* Fill X entries */
     48:   for (j=0;j<k;j++) {
     49:     BVGetColumn(X,j,&v);
     50:     VecSet(v,0.0);
     51:     for (i=0;i<4;i++) {
     52:       if (i+j<n) VecSetValue(v,i+j,(PetscScalar)(3*i+j-2),INSERT_VALUES);
     53:     }
     54:     VecAssemblyBegin(v);
     55:     VecAssemblyEnd(v);
     56:     BVRestoreColumn(X,j,&v);
     57:   }
     58:   if (verbose) BVView(X,view);

     60:   /* Test BVDotColumn */
     61:   BVDotColumn(X,2,NULL);
     62:   if (verbose) {
     63:     PetscPrintf(PETSC_COMM_WORLD,"After BVDotColumn - - - - - - -\n");
     64:     BVGetBufferVec(X,&z);
     65:     VecView(z,view);
     66:   }
     67:   /* Test BVMultColumn */
     68:   BVMultColumn(X,-1.0,1.0,2,NULL);
     69:   if (verbose) {
     70:     PetscPrintf(PETSC_COMM_WORLD,"After BVMultColumn - - - - - - - - -\n");
     71:     BVView(X,view);
     72:   }

     74:   BVNorm(X,NORM_FROBENIUS,&nrm);
     75:   PetscPrintf(PETSC_COMM_WORLD,"Frobenius Norm or X = %g\n",(double)nrm);

     77:   BVDestroy(&X);
     78:   VecDestroy(&t);
     79:   SlepcFinalize();
     80:   return 0;
     81: }

     83: /*TEST

     85:    testset:
     86:       output_file: output/test13_1.out
     87:       test:
     88:          suffix: 1
     89:          args: -bv_type {{vecs contiguous svec mat}shared output}
     90:       test:
     91:          suffix: 1_cuda
     92:          args: -bv_type svec -vec_type cuda
     93:          requires: cuda

     95: TEST*/