LCOV - code coverage report
Current view: top level - sys/classes/ds/tests - test13.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 49 53 92.5 %
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 DSHEP with block size larger than one.\n\n";
      12             : 
      13             : #include <slepcds.h>
      14             : 
      15           2 : int main(int argc,char **argv)
      16             : {
      17           2 :   DS             ds;
      18           2 :   SlepcSC        sc;
      19           2 :   PetscScalar    *A,*eig;
      20           2 :   PetscInt       i,j,n,ld,bs,maxbw=3,nblks=8;
      21           2 :   PetscViewer    viewer;
      22           2 :   PetscBool      verbose;
      23             : 
      24           2 :   PetscFunctionBeginUser;
      25           2 :   PetscCall(SlepcInitialize(&argc,&argv,NULL,help));
      26           2 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-maxbw",&maxbw,NULL));
      27           2 :   PetscCall(PetscOptionsGetInt(NULL,NULL,"-nblks",&nblks,NULL));
      28           2 :   n = maxbw*nblks;
      29           2 :   bs = maxbw;
      30           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Solve a block HEP Dense System - dimension %" PetscInt_FMT " (bandwidth=%" PetscInt_FMT ", blocks=%" PetscInt_FMT ").\n",n,maxbw,nblks));
      31           2 :   PetscCall(PetscOptionsHasName(NULL,NULL,"-verbose",&verbose));
      32             : 
      33             :   /* Create DS object */
      34           2 :   PetscCall(DSCreate(PETSC_COMM_WORLD,&ds));
      35           2 :   PetscCall(DSSetType(ds,DSHEP));
      36           2 :   PetscCall(DSSetMethod(ds,3));   /* Select block divide-and-conquer */
      37           2 :   PetscCall(DSSetBlockSize(ds,bs));
      38           2 :   PetscCall(DSSetFromOptions(ds));
      39           2 :   ld = n;
      40           2 :   PetscCall(DSAllocate(ds,ld));
      41           2 :   PetscCall(DSSetDimensions(ds,n,0,0));
      42             : 
      43             :   /* Set up viewer */
      44           2 :   PetscCall(PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&viewer));
      45           2 :   PetscCall(PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_INFO_DETAIL));
      46           2 :   PetscCall(DSView(ds,viewer));
      47           2 :   PetscCall(PetscViewerPopFormat(viewer));
      48           2 :   if (verbose) PetscCall(PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB));
      49             : 
      50             :   /* Fill with a symmetric band Toeplitz matrix */
      51           2 :   PetscCall(DSGetArray(ds,DS_MAT_A,&A));
      52          29 :   for (i=0;i<n;i++) A[i+i*ld]=2.0;
      53           8 :   for (j=1;j<=bs;j++) {
      54          75 :     for (i=0;i<n-j;i++) { A[i+(i+j)*ld]=1.0; A[(i+j)+i*ld]=1.0; }
      55             :   }
      56           2 :   PetscCall(DSRestoreArray(ds,DS_MAT_A,&A));
      57           2 :   PetscCall(DSSetState(ds,DS_STATE_RAW));
      58           2 :   if (verbose) {
      59           0 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Initial - - - - - - - - -\n"));
      60           0 :     PetscCall(DSView(ds,viewer));
      61             :   }
      62             : 
      63             :   /* Solve */
      64           2 :   PetscCall(PetscMalloc1(n,&eig));
      65           2 :   PetscCall(DSGetSlepcSC(ds,&sc));
      66           2 :   sc->comparison    = SlepcCompareSmallestReal;
      67           2 :   sc->comparisonctx = NULL;
      68           2 :   sc->map           = NULL;
      69           2 :   sc->mapobj        = NULL;
      70           2 :   PetscCall(DSSolve(ds,eig,NULL));
      71           2 :   PetscCall(DSSort(ds,eig,NULL,NULL,NULL,NULL));
      72           2 :   if (verbose) {
      73           0 :     PetscCall(PetscPrintf(PETSC_COMM_WORLD,"After solve - - - - - - - - -\n"));
      74           0 :     PetscCall(DSView(ds,viewer));
      75             :   }
      76             : 
      77             :   /* Print eigenvalues */
      78           2 :   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Computed eigenvalues =\n"));
      79          29 :   for (i=0;i<n;i++) PetscCall(PetscViewerASCIIPrintf(viewer,"  %.5f\n",(double)PetscRealPart(eig[i])));
      80             : 
      81           2 :   PetscCall(PetscFree(eig));
      82           2 :   PetscCall(DSDestroy(&ds));
      83           2 :   PetscCall(SlepcFinalize());
      84             :   return 0;
      85             : }
      86             : 
      87             : /*TEST
      88             : 
      89             :    test:
      90             :       suffix: 1
      91             :       requires: !complex !single
      92             : 
      93             :    test:
      94             :       suffix: 2
      95             :       args: -nblks 1
      96             :       requires: !complex
      97             : 
      98             : TEST*/

Generated by: LCOV version 1.14