Actual source code: test1.c
slepc-3.17.1 2022-04-11
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 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;
20: SlepcInitialize(&argc,&argv,(char*)0,help);
21: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
22: PetscPrintf(PETSC_COMM_WORLD,"MatCreateTile test, n=%" PetscInt_FMT "\n",n);
24: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25: Create T=tridiag([-1 2 -1],n,n) and E=eye(n)
26: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28: MatCreate(PETSC_COMM_WORLD,&T);
29: MatSetSizes(T,PETSC_DECIDE,PETSC_DECIDE,n,n);
30: MatSetFromOptions(T);
31: MatSetUp(T);
33: MatGetOwnershipRange(T,&Istart,&Iend);
34: for (i=Istart;i<Iend;i++) {
35: if (i>0) MatSetValue(T,i,i-1,-1.0,INSERT_VALUES);
36: if (i<n-1) MatSetValue(T,i,i+1,-1.0,INSERT_VALUES);
37: MatSetValue(T,i,i,2.0,INSERT_VALUES);
38: }
39: MatAssemblyBegin(T,MAT_FINAL_ASSEMBLY);
40: MatAssemblyEnd(T,MAT_FINAL_ASSEMBLY);
42: MatCreate(PETSC_COMM_WORLD,&E);
43: MatSetSizes(E,PETSC_DECIDE,PETSC_DECIDE,n,n);
44: MatSetFromOptions(E);
45: MatSetUp(E);
47: MatGetOwnershipRange(E,&Istart,&Iend);
48: for (i=Istart;i<Iend;i++) MatSetValue(E,i,i,1.0,INSERT_VALUES);
49: MatAssemblyBegin(E,MAT_FINAL_ASSEMBLY);
50: MatAssemblyEnd(E,MAT_FINAL_ASSEMBLY);
52: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53: Create tiled matrix A = [ 2*T -E; 0 3*T ]
54: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
55: MatCreateTile(2.0,T,-1.0,E,0.0,E,3.0,T,&A);
56: MatView(A,NULL);
58: MatDestroy(&T);
59: MatDestroy(&E);
60: MatDestroy(&A);
61: SlepcFinalize();
62: return 0;
63: }
65: /*TEST
67: test:
68: suffix: 1
69: nsize: 1
71: test:
72: suffix: 2
73: nsize: 2
75: TEST*/