LCOV - code coverage report
Current view: top level - sys/classes/bv/tests - test13.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 41 46 89.1 %
Date: 2024-11-23 00:34:26 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
       5             : 
       6             :    This file is part of SLEPc.
       7             :    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
       8             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       9             : */
      10             : 
      11             : static char help[] = "Test BV operations using internal buffer instead of array arguments.\n\n";
      12             : 
      13             : #include <slepcbv.h>
      14             : 
      15           4 : int main(int argc,char **argv)
      16             : {
      17           4 :   Vec            t,v,z;
      18           4 :   BV             X;
      19           4 :   PetscInt       i,j,n=10,k=5,l=3;
      20           4 :   PetscReal      nrm;
      21           4 :   PetscViewer    view;
      22           4 :   PetscBool      verbose;
      23             : 
      24           4 :   PetscFunctionBeginUser;
      25           4 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      26           4 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
      27           4 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-k",&k,NULL));
      28           4 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-l",&l,NULL));
      29           4 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-verbose",&verbose));
      30           4 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Test BV with %" PetscInt_FMT " columns of dimension %" PetscInt_FMT ".\n",k,n));
      31             : 
      32             :   /* Create template vector */
      33           4 :   PetscCall(VecCreate(PETSC_COMM_WORLD,&t));
      34           4 :   PetscCall(VecSetSizes(t,PETSC_DECIDE,n));
      35           4 :   PetscCall(VecSetFromOptions(t));
      36             : 
      37             :   /* Create BV object X */
      38           4 :   PetscCall(BVCreate(PETSC_COMM_WORLD,&X));
      39           4 :   PetscCall(PetscObjectSetName((PetscObject)X,"X"));
      40           4 :   PetscCall(BVSetSizesFromVec(X,t,k));
      41           4 :   PetscCall(BVSetFromOptions(X));
      42             : 
      43             :   /* Set up viewer */
      44           4 :   PetscCall(PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&view));
      45           4 :   if (verbose) PetscCall(PetscViewerPushFormat(view,PETSC_VIEWER_ASCII_MATLAB));
      46             : 
      47             :   /* Fill X entries */
      48          24 :   for (j=0;j<k;j++) {
      49          20 :     PetscCall(BVGetColumn(X,j,&v));
      50          20 :     PetscCall(VecSet(v,0.0));
      51         100 :     for (i=0;i<4;i++) {
      52          80 :       if (i+j<n) PetscCall(VecSetValue(v,i+j,(PetscScalar)(3*i+j-2),INSERT_VALUES));
      53             :     }
      54          20 :     PetscCall(VecAssemblyBegin(v));
      55          20 :     PetscCall(VecAssemblyEnd(v));
      56          20 :     PetscCall(BVRestoreColumn(X,j,&v));
      57             :   }
      58           4 :   if (verbose) PetscCall(BVView(X,view));
      59             : 
      60             :   /* Test BVDotColumn */
      61           4 :   PetscCall(BVDotColumn(X,2,NULL));
      62           4 :   if (verbose) {
      63           0 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD,"After BVDotColumn - - - - - - -\n"));
      64           0 :     PetscCall(BVGetBufferVec(X,&z));
      65           0 :     PetscCall(VecView(z,view));
      66             :   }
      67             :   /* Test BVMultColumn */
      68           4 :   PetscCall(BVMultColumn(X,-1.0,1.0,2,NULL));
      69           4 :   if (verbose) {
      70           0 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD,"After BVMultColumn - - - - - - - - -\n"));
      71           0 :     PetscCall(BVView(X,view));
      72             :   }
      73             : 
      74           4 :   PetscCall(BVNorm(X,NORM_FROBENIUS,&nrm));
      75           4 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Frobenius Norm or X = %g\n",(double)nrm));
      76             : 
      77           4 :   PetscCall(BVDestroy(&X));
      78           4 :   PetscCall(VecDestroy(&t));
      79           4 :   PetscCall(SlepcFinalize());
      80             :   return 0;
      81             : }
      82             : 
      83             : /*TEST
      84             : 
      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 mat}} -vec_type cuda
      93             :          requires: cuda
      94             :       test:
      95             :          suffix: 1_hip
      96             :          args: -bv_type {{svec mat}} -vec_type hip
      97             :          requires: hip
      98             : 
      99             : TEST*/

Generated by: LCOV version 1.14