Actual source code: test1.c

slepc-3.11.2 2019-07-30
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-2019, 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 MatCreateTile.\n\n";

 13: #include <slepcsys.h>

 15: int main(int argc,char **argv)
 16: {
 17:   Mat            T,E,A;
 18:   PetscInt       i,Istart,Iend,n=10;

 21:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 22:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
 23:   PetscPrintf(PETSC_COMM_WORLD,"MatCreateTile test, n=%D\n",n);

 25:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 26:      Create T=tridiag([-1 2 -1],n,n) and E=eye(n)
 27:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 29:   MatCreate(PETSC_COMM_WORLD,&T);
 30:   MatSetSizes(T,PETSC_DECIDE,PETSC_DECIDE,n,n);
 31:   MatSetFromOptions(T);
 32:   MatSetUp(T);

 34:   MatGetOwnershipRange(T,&Istart,&Iend);
 35:   for (i=Istart;i<Iend;i++) {
 36:     if (i>0) { MatSetValue(T,i,i-1,-1.0,INSERT_VALUES); }
 37:     if (i<n-1) { MatSetValue(T,i,i+1,-1.0,INSERT_VALUES); }
 38:     MatSetValue(T,i,i,2.0,INSERT_VALUES);
 39:   }
 40:   MatAssemblyBegin(T,MAT_FINAL_ASSEMBLY);
 41:   MatAssemblyEnd(T,MAT_FINAL_ASSEMBLY);

 43:   MatCreate(PETSC_COMM_WORLD,&E);
 44:   MatSetSizes(E,PETSC_DECIDE,PETSC_DECIDE,n,n);
 45:   MatSetFromOptions(E);
 46:   MatSetUp(E);

 48:   MatGetOwnershipRange(E,&Istart,&Iend);
 49:   for (i=Istart;i<Iend;i++) {
 50:     MatSetValue(E,i,i,1.0,INSERT_VALUES);
 51:   }
 52:   MatAssemblyBegin(E,MAT_FINAL_ASSEMBLY);
 53:   MatAssemblyEnd(E,MAT_FINAL_ASSEMBLY);

 55:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 56:      Create tiled matrix A = [ 2*T -E; 0 3*T ]
 57:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 58:   MatCreateTile(2.0,T,-1.0,E,0.0,E,3.0,T,&A);
 59:   MatView(A,NULL);

 61:   MatDestroy(&T);
 62:   MatDestroy(&E);
 63:   MatDestroy(&A);
 64:   SlepcFinalize();
 65:   return ierr;
 66: }

 68: /*TEST

 70:    test:
 71:       suffix: 1
 72:       nsize: 1

 74:    test:
 75:       suffix: 2
 76:       nsize: 2

 78: TEST*/