22 |
void Paso_Preconditioner_free(Paso_Solver_Preconditioner* in) { |
void Paso_Preconditioner_free(Paso_Solver_Preconditioner* in) { |
23 |
if (in!=NULL) { |
if (in!=NULL) { |
24 |
Paso_Solver_ILU_free(in->ilu); |
Paso_Solver_ILU_free(in->ilu); |
25 |
|
Paso_Solver_RILU_free(in->rilu); |
26 |
Paso_Solver_Jacobi_free(in->jacobi); |
Paso_Solver_Jacobi_free(in->jacobi); |
27 |
MEMFREE(in); |
MEMFREE(in); |
28 |
} |
} |
31 |
|
|
32 |
void Paso_Solver_setPreconditioner(Paso_SystemMatrix* A,Paso_Options* options) { |
void Paso_Solver_setPreconditioner(Paso_SystemMatrix* A,Paso_Options* options) { |
33 |
Paso_Solver_Preconditioner* prec=NULL; |
Paso_Solver_Preconditioner* prec=NULL; |
34 |
if (A->iterative==NULL) { |
if (A->solver==NULL) { |
35 |
/* allocate structure to hold preconditioner */ |
/* allocate structure to hold preconditioner */ |
36 |
prec=MEMALLOC(1,Paso_Solver_Preconditioner); |
prec=MEMALLOC(1,Paso_Solver_Preconditioner); |
37 |
if (Paso_checkPtr(prec)) return; |
if (Paso_checkPtr(prec)) return; |
38 |
prec->type=UNKNOWN; |
prec->type=UNKNOWN; |
39 |
|
prec->rilu=NULL; |
40 |
prec->ilu=NULL; |
prec->ilu=NULL; |
41 |
prec->jacobi=NULL; |
prec->jacobi=NULL; |
42 |
A->iterative=prec; |
A->solver=prec; |
43 |
switch (options->preconditioner) { |
switch (options->preconditioner) { |
44 |
default: |
default: |
45 |
case PASO_JACOBI: |
case PASO_JACOBI: |
52 |
prec->ilu=Paso_Solver_getILU(A,options->verbose); |
prec->ilu=Paso_Solver_getILU(A,options->verbose); |
53 |
prec->type=PASO_ILU0; |
prec->type=PASO_ILU0; |
54 |
break; |
break; |
55 |
|
case PASO_RILU: |
56 |
|
if (options->verbose) printf("RILU preconditioner is used.\n"); |
57 |
|
prec->rilu=Paso_Solver_getRILU(A,options->verbose); |
58 |
|
prec->type=PASO_RILU; |
59 |
|
break; |
60 |
} |
} |
61 |
if (! Paso_noError()) { |
if (! Paso_noError()) { |
62 |
Paso_Preconditioner_free(prec); |
Paso_Preconditioner_free(prec); |
63 |
A->iterative=NULL; |
A->solver=NULL; |
64 |
} |
} |
65 |
} |
} |
66 |
} |
} |
69 |
/* has to be called within a parallel reqion */ |
/* has to be called within a parallel reqion */ |
70 |
/* barrier synchronization is performed before the evaluation to make sure that the input vector is available */ |
/* barrier synchronization is performed before the evaluation to make sure that the input vector is available */ |
71 |
void Paso_Solver_solvePreconditioner(Paso_SystemMatrix* A,double* x,double* b){ |
void Paso_Solver_solvePreconditioner(Paso_SystemMatrix* A,double* x,double* b){ |
72 |
Paso_Solver_Preconditioner* prec=(Paso_Solver_Preconditioner*) A->iterative; |
Paso_Solver_Preconditioner* prec=(Paso_Solver_Preconditioner*) A->solver; |
73 |
#pragma omp barrier |
#pragma omp barrier |
74 |
switch (prec->type) { |
switch (prec->type) { |
75 |
default: |
default: |
79 |
case PASO_ILU0: |
case PASO_ILU0: |
80 |
Paso_Solver_solveILU(prec->ilu,x,b); |
Paso_Solver_solveILU(prec->ilu,x,b); |
81 |
break; |
break; |
82 |
|
case PASO_RILU: |
83 |
|
Paso_Solver_solveRILU(prec->rilu,x,b); |
84 |
|
break; |
85 |
} |
} |
86 |
} |
} |
87 |
|
|