Actual source code: ex75.c
1: #include <petsc.h>
3: static char help[] = "Solves a series of linear systems using KSPHPDDM.\n\n";
5: int main(int argc,char **args)
6: {
7: Vec x,b; /* computed solution and RHS */
8: Mat A; /* linear system matrix */
9: KSP ksp; /* linear solver context */
10: #if defined(PETSC_HAVE_HPDDM)
11: Mat U; /* deflation space */
12: #endif
13: PetscInt i,j,nmat = 10;
14: PetscViewer viewer;
15: char dir[PETSC_MAX_PATH_LEN],name[256];
16: PetscBool flg,reset = PETSC_FALSE;
19: PetscInitialize(&argc,&args,NULL,help);if (ierr) return ierr;
20: PetscStrcpy(dir,".");
21: PetscOptionsGetString(NULL,NULL,"-load_dir",dir,sizeof(dir),NULL);
22: PetscOptionsGetInt(NULL,NULL,"-nmat",&nmat,NULL);
23: PetscOptionsGetBool(NULL,NULL,"-reset",&reset,NULL);
24: MatCreate(PETSC_COMM_WORLD,&A);
25: KSPCreate(PETSC_COMM_WORLD,&ksp);
26: KSPSetOperators(ksp,A,A);
27: for (i=0; i<nmat; i++) {
28: j = i+400;
29: PetscSNPrintf(name,sizeof(name),"%s/A_%d.dat",dir,j);
30: PetscViewerBinaryOpen(PETSC_COMM_WORLD,name,FILE_MODE_READ,&viewer);
31: MatLoad(A,viewer);
32: PetscViewerDestroy(&viewer);
33: if (i == 0) {
34: MatCreateVecs(A,&x,&b);
35: }
36: PetscSNPrintf(name,sizeof(name),"%s/rhs_%d.dat",dir,j);
37: PetscViewerBinaryOpen(PETSC_COMM_WORLD,name,FILE_MODE_READ,&viewer);
38: VecLoad(b,viewer);
39: PetscViewerDestroy(&viewer);
40: KSPSetFromOptions(ksp);
41: KSPSolve(ksp,b,x);
42: PetscObjectTypeCompare((PetscObject)ksp,KSPHPDDM,&flg);
43: #if defined(PETSC_HAVE_HPDDM)
44: if (flg && reset) {
45: KSPHPDDMGetDeflationSpace(ksp,&U);
46: KSPReset(ksp);
47: KSPSetOperators(ksp,A,A);
48: KSPSetFromOptions(ksp);
49: KSPSetUp(ksp);
50: if (U) {
51: KSPHPDDMSetDeflationSpace(ksp,U);
52: MatDestroy(&U);
53: }
54: }
55: #endif
56: }
57: VecDestroy(&x);
58: VecDestroy(&b);
59: MatDestroy(&A);
60: KSPDestroy(&ksp);
61: PetscFinalize();
62: return ierr;
63: }
65: /*TEST
67: test:
68: suffix: 1
69: nsize: 1
70: requires: hpddm datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
71: args: -nmat 1 -pc_type none -ksp_converged_reason -ksp_type {{gmres hpddm}shared output} -ksp_max_it 1000 -ksp_gmres_restart 1000 -ksp_rtol 1e-10 -ksp_hpddm_type {{gmres bgmres}shared output} -options_left no -load_dir ${DATAFILESPATH}/matrices/hpddm/GCRODR
73: test:
74: requires: hpddm datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
75: suffix: 1_icc
76: nsize: 1
77: args: -nmat 1 -pc_type icc -ksp_converged_reason -ksp_type {{gmres hpddm}shared output} -ksp_max_it 1000 -ksp_gmres_restart 1000 -ksp_rtol 1e-10 -load_dir ${DATAFILESPATH}/matrices/hpddm/GCRODR
79: testset:
80: requires: hpddm datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
81: args: -nmat 3 -pc_type none -ksp_converged_reason -ksp_type hpddm -ksp_max_it 1000 -ksp_gmres_restart 40 -ksp_rtol 1e-10 -ksp_hpddm_type {{gcrodr bgcrodr}shared output} -ksp_hpddm_recycle 20 -load_dir ${DATAFILESPATH}/matrices/hpddm/GCRODR
82: test:
83: nsize: 1
84: suffix: 2_seq
85: output_file: output/ex75_2.out
86: test:
87: nsize: 2
88: suffix: 2_par
89: output_file: output/ex75_2.out
91: testset:
92: requires: hpddm datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
93: nsize: 1
94: args: -nmat 3 -pc_type icc -ksp_converged_reason -ksp_type hpddm -ksp_max_it 1000 -ksp_gmres_restart 40 -ksp_rtol 1e-10 -ksp_hpddm_type {{gcrodr bgcrodr}shared output} -ksp_hpddm_recycle 20 -reset {{false true}shared output} -load_dir ${DATAFILESPATH}/matrices/hpddm/GCRODR
95: test:
96: suffix: 2_icc
97: args:
98: test:
99: suffix: 2_icc_atol
100: args: -ksp_atol 1e-12
102: test:
103: requires: hpddm datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES) slepc defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
104: nsize: 2
105: suffix: symmetric
106: args: -nmat 3 -pc_type jacobi -ksp_converged_reason -ksp_type hpddm -ksp_max_it 1000 -ksp_gmres_restart 40 -ksp_atol 1e-11 -ksp_hpddm_type bgcrodr -ksp_hpddm_recycle 20 -reset {{false true}shared output} -load_dir ${DATAFILESPATH}/matrices/hpddm/GCRODR -ksp_hpddm_recycle_symmetric true
108: TEST*/