Date: 2021-02-01T14:41:45+00:00

Actual source code: test13.c
slepc-3.14.2 2021-02-01
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2020, 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 DSHEP with block size larger than one.\n\n";

     13: #include <slepcds.h>

     15: int main(int argc,char **argv)
     16: {
     18:   DS             ds;
     19:   SlepcSC        sc;
     20:   PetscScalar    *A,*eig;
     21:   PetscInt       i,j,n,ld,bs,maxbw=3,nblks=8;
     22:   PetscViewer    viewer;
     23:   PetscBool      verbose;

     25:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
     26:   PetscOptionsGetInt(NULL,NULL,"-maxbw",&maxbw,NULL);
     27:   PetscOptionsGetInt(NULL,NULL,"-nblks",&nblks,NULL);
     28:   n = maxbw*nblks;
     29:   bs = maxbw;
     30:   PetscPrintf(PETSC_COMM_WORLD,"Solve a block HEP Dense System - dimension %D (bandwidth=%D, blocks=%D).\n",n,maxbw,nblks);
     31:   PetscOptionsHasName(NULL,NULL,"-verbose",&verbose);

     33:   /* Create DS object */
     34:   DSCreate(PETSC_COMM_WORLD,&ds);
     35:   DSSetType(ds,DSHEP);
     36:   DSSetMethod(ds,3);   /* Select block divide-and-conquer */
     37:   DSSetBlockSize(ds,bs);
     38:   DSSetFromOptions(ds);
     39:   ld = n;
     40:   DSAllocate(ds,ld);
     41:   DSSetDimensions(ds,n,0,0,0);

     43:   /* Set up viewer */
     44:   PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&viewer);
     45:   PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_INFO_DETAIL);
     46:   DSView(ds,viewer);
     47:   PetscViewerPopFormat(viewer);
     48:   if (verbose) {
     49:     PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
     50:   }

     52:   /* Fill with a symmetric band Toeplitz matrix */
     53:   DSGetArray(ds,DS_MAT_A,&A);
     54:   for (i=0;i<n;i++) A[i+i*ld]=2.0;
     55:   for (j=1;j<=bs;j++) {
     56:     for (i=0;i<n-j;i++) { A[i+(i+j)*ld]=1.0; A[(i+j)+i*ld]=1.0; }
     57:   }
     58:   DSRestoreArray(ds,DS_MAT_A,&A);
     59:   DSSetState(ds,DS_STATE_RAW);
     60:   if (verbose) {
     61:     PetscPrintf(PETSC_COMM_WORLD,"Initial - - - - - - - - -\n");
     62:     DSView(ds,viewer);
     63:   }

     65:   /* Solve */
     66:   PetscMalloc1(n,&eig);
     67:   DSGetSlepcSC(ds,&sc);
     68:   sc->comparison    = SlepcCompareSmallestReal;
     69:   sc->comparisonctx = NULL;
     70:   sc->map           = NULL;
     71:   sc->mapobj        = NULL;
     72:   DSSolve(ds,eig,NULL);
     73:   DSSort(ds,eig,NULL,NULL,NULL,NULL);
     74:   if (verbose) {
     75:     PetscPrintf(PETSC_COMM_WORLD,"After solve - - - - - - - - -\n");
     76:     DSView(ds,viewer);
     77:   }

     79:   /* Print eigenvalues */
     80:   PetscPrintf(PETSC_COMM_WORLD,"Computed eigenvalues =\n");
     81:   for (i=0;i<n;i++) {
     82:     PetscViewerASCIIPrintf(viewer,"  %.5f\n",(double)PetscRealPart(eig[i]));
     83:   }

     85:   PetscFree(eig);
     86:   DSDestroy(&ds);
     87:   SlepcFinalize();
     88:   return ierr;
     89: }

     91: /*TEST

     93:    test:
     94:       suffix: 1
     95:       requires: !complex !single

     97:    test:
     98:       suffix: 2
     99:       args: -nblks 1
    100:       requires: !complex

    102: TEST*/