/[escript]/trunk/paso/src/Solver_AMG.c
ViewVC logotype

Annotation of /trunk/paso/src/Solver_AMG.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2828 - (hide annotations)
Tue Dec 22 01:24:40 2009 UTC (10 years, 2 months ago) by artak
File MIME type: text/plain
File size: 23211 byte(s)
Smoother for AMG now can be selected from python. Now only Jacobi and Gauss-Seidel are available as smoothers.
1 jfenwick 1851
2     /*******************************************************
3     *
4 jfenwick 2548 * Copyright (c) 2003-2009 by University of Queensland
5 jfenwick 1851 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13    
14    
15     /**************************************************************/
16    
17 artak 2475 /* Paso: AMG preconditioner */
18 jfenwick 1851
19     /**************************************************************/
20    
21 jfenwick 2625 /* Author: artak@uq.edu.au */
22 jfenwick 1851
23     /**************************************************************/
24    
25     #include "Paso.h"
26     #include "Solver.h"
27 artak 2475 #include "Options.h"
28 jfenwick 1851 #include "PasoUtil.h"
29 artak 1931 #include "UMFPACK.h"
30 artak 2507 #include "MKL.h"
31     #include "SystemMatrix.h"
32 phornby 1917 #include "Pattern_coupling.h"
33 jfenwick 1851
34     /**************************************************************/
35    
36     /* free all memory used by AMG */
37    
38 artak 2659 void Paso_Solver_AMG_System_free(Paso_Solver_AMG_System * in) {
39 artak 2662 dim_t i;
40 artak 2659 if (in!=NULL) {
41 artak 2662 for (i=0;i<in->block_size;++i) {
42     Paso_Solver_AMG_free(in->amgblock[i]);
43 artak 2670 Paso_SparseMatrix_free(in->block[i]);
44 artak 2662 }
45 artak 2659 MEMFREE(in);
46     }
47     }
48    
49    
50     /* free all memory used by AMG */
51    
52 jfenwick 1851 void Paso_Solver_AMG_free(Paso_Solver_AMG * in) {
53     if (in!=NULL) {
54 artak 2828
55     if(in->Smoother->ID==PASO_JACOBI)
56     Paso_Solver_Jacobi_free(in->Smoother->Jacobi);
57     else if (in->Smoother->ID==PASO_GS)
58     Paso_Solver_GS_free(in->Smoother->GS);
59     MEMFREE(in->Smoother);
60    
61 jfenwick 1851 Paso_SparseMatrix_free(in->A_FC);
62 artak 2760 Paso_SparseMatrix_free(in->A_FF);
63     Paso_SparseMatrix_free(in->W_FC);
64 jfenwick 1851 Paso_SparseMatrix_free(in->A_CF);
65 artak 2760 Paso_SparseMatrix_free(in->P);
66     Paso_SparseMatrix_free(in->R);
67 artak 2556 Paso_SparseMatrix_free(in->A);
68 artak 2711 if(in->coarsest_level==TRUE) {
69     #ifdef MKL
70     Paso_MKL_free1(in->AOffset1);
71     Paso_SparseMatrix_free(in->AOffset1);
72     #else
73     #ifdef UMFPACK
74     Paso_UMFPACK1_free((Paso_UMFPACK_Handler*)(in->solver));
75     #endif
76     #endif
77     }
78 jfenwick 1851 MEMFREE(in->rows_in_F);
79     MEMFREE(in->rows_in_C);
80     MEMFREE(in->mask_F);
81     MEMFREE(in->mask_C);
82     MEMFREE(in->x_F);
83     MEMFREE(in->b_F);
84     MEMFREE(in->x_C);
85     MEMFREE(in->b_C);
86 gross 2551 in->solver=NULL;
87 artak 2760 Paso_Solver_AMG_free(in->AMG_of_Coarse);
88 gross 2551 MEMFREE(in->b_C);
89 jfenwick 1851 MEMFREE(in);
90     }
91     }
92    
93     /**************************************************************/
94    
95     /* constructs the block-block factorization of
96    
97     [ A_FF A_FC ]
98     A_p=
99     [ A_CF A_FF ]
100    
101     to
102    
103     [ I 0 ] [ A_FF 0 ] [ I invA_FF*A_FF ]
104     [ A_CF*invA_FF I ] [ 0 S ] [ 0 I ]
105    
106    
107     where S=A_FF-ACF*invA_FF*A_FC within the shape of S
108    
109     then AMG is applied to S again until S becomes empty
110    
111     */
112 artak 2520 Paso_Solver_AMG* Paso_Solver_getAMG(Paso_SparseMatrix *A_p,dim_t level,Paso_Options* options) {
113 jfenwick 1851 Paso_Solver_AMG* out=NULL;
114 artak 2760 /*
115     Paso_Pattern* temp1=NULL;
116 artak 2556 Paso_Pattern* temp2=NULL;
117 artak 2760 */
118 artak 2520 bool_t verbose=options->verbose;
119 jfenwick 1851 dim_t n=A_p->numRows;
120     dim_t n_block=A_p->row_block_size;
121     index_t* mis_marker=NULL;
122 artak 1881 index_t* counter=NULL;
123 artak 2760 /*index_t iPtr,*index, *where_p;*/
124     dim_t i;
125     Paso_SparseMatrix * A_c=NULL;
126 artak 2765 double time0=0;
127 artak 2784 Paso_SparseMatrix * Atemp=NULL;
128     double sparsity=0;
129 artak 2475
130 artak 2760 /*
131     double *temp,*temp_1;
132     double S;
133     index_t iptr;
134     */
135     /*char filename[8];*/
136     /*sprintf(filename,"AMGLevel%d",level);
137 artak 2726
138 artak 2760 Paso_SparseMatrix_saveMM(A_p,filename);
139 artak 2726 */
140    
141 artak 2439 /*Make sure we have block sizes 1*/
142 gross 2550 if (A_p->col_block_size>1) {
143     Paso_setError(TYPE_ERROR,"Paso_Solver_getAMG: AMG requires column block size 1.");
144     return NULL;
145     }
146     if (A_p->row_block_size>1) {
147     Paso_setError(TYPE_ERROR,"Paso_Solver_getAMG: AMG requires row block size 1.");
148     return NULL;
149     }
150 gross 2551 out=MEMALLOC(1,Paso_Solver_AMG);
151 artak 2828 out->Smoother=MEMALLOC(1,Paso_Solver_Smoother);
152 jfenwick 1851 /* identify independend set of rows/columns */
153     mis_marker=TMPMEMALLOC(n,index_t);
154     counter=TMPMEMALLOC(n,index_t);
155 gross 2551 if ( !( Paso_checkPtr(mis_marker) || Paso_checkPtr(counter) || Paso_checkPtr(out)) ) {
156 artak 2760 out->AMG_of_Coarse=NULL;
157     out->A_FF=NULL;
158 gross 2551 out->A_FC=NULL;
159     out->A_CF=NULL;
160 artak 2760 out->W_FC=NULL;
161     out->P=NULL;
162     out->R=NULL;
163 gross 2551 out->rows_in_F=NULL;
164     out->rows_in_C=NULL;
165     out->mask_F=NULL;
166     out->mask_C=NULL;
167     out->x_F=NULL;
168     out->b_F=NULL;
169     out->x_C=NULL;
170     out->b_C=NULL;
171     out->A=Paso_SparseMatrix_getReference(A_p);
172     out->solver=NULL;
173 artak 2828 out->Smoother->ID=options->smoother;
174     out->Smoother->Jacobi=NULL;
175     out->Smoother->GS=NULL;
176 gross 2551 /*out->GS=Paso_Solver_getGS(A_p,verbose);*/
177     out->level=level;
178 artak 2661 out->n=n;
179 artak 2726 out->n_F=n+1;
180 artak 2661 out->n_block=n_block;
181 artak 2803 out->post_sweeps=options->post_sweeps;
182     out->pre_sweeps=options->pre_sweeps;
183 artak 2556
184 artak 2784 sparsity=(A_p->len*1.)/(1.*A_p->numRows*A_p->numCols);
185    
186     if (verbose) fprintf(stdout,"Stats: Sparsity of the Coarse Matrix with %d non-zeros (%d,%d) in level %d is %.6f\n",A_p->len,A_p->numRows,A_p->numCols,level,sparsity);
187    
188 artak 2802
189 artak 2803 /*if(sparsity>0.01) {
190 artak 2784 level=0;
191     }
192 artak 2803 */
193 artak 2802
194 gross 2551 if (level==0 || n<=options->min_coarse_matrix_size) {
195     out->coarsest_level=TRUE;
196 artak 2784 /*out->GS=Paso_Solver_getJacobi(A_p);*/
197    
198 artak 2712 #ifdef MKL
199 artak 2711 out->AOffset1=Paso_SparseMatrix_alloc(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_OFFSET1, out->A->pattern,1,1, FALSE);
200     #pragma omp parallel for private(i) schedule(static)
201     for (i=0;i<out->A->len;++i) {
202     out->AOffset1->val[i]=out->A->val[i];
203     }
204 artak 2712 #else
205     #ifdef UMFPACK
206     #else
207 artak 2828 if (options->smoother == PASO_JACOBI)
208     out->Smoother->Jacobi=Paso_Solver_getJacobi(A_p);
209     else if (options->smoother == PASO_GS)
210     out->Smoother->GS=Paso_Solver_getGS(A_p,verbose));
211 gross 2551 #endif
212     #endif
213 artak 2784
214 gross 2551 } else {
215     out->coarsest_level=FALSE;
216 artak 2828
217     if (options->smoother == PASO_JACOBI)
218     out->Smoother->Jacobi=Paso_Solver_getJacobi(A_p);
219     else if (options->smoother == PASO_GS)
220     out->Smoother->GS=Paso_Solver_getGS(A_p,verbose);
221 artak 2442
222 gross 2551 /* identify independend set of rows/columns */
223     #pragma omp parallel for private(i) schedule(static)
224     for (i=0;i<n;++i) mis_marker[i]=-1;
225    
226 artak 2765 /*mesuring coarsening time */
227     time0=Paso_timer();
228    
229 gross 2551 if (options->coarsening_method == PASO_YAIR_SHAPIRA_COARSENING) {
230 artak 2652 Paso_Pattern_YS(A_p,mis_marker,options->coarsening_threshold);
231 gross 2551 }
232     else if (options->coarsening_method == PASO_RUGE_STUEBEN_COARSENING) {
233     Paso_Pattern_RS(A_p,mis_marker,options->coarsening_threshold);
234     }
235     else if (options->coarsening_method == PASO_AGGREGATION_COARSENING) {
236     Paso_Pattern_Aggregiation(A_p,mis_marker,options->coarsening_threshold);
237     }
238 artak 2816 else if (options->coarsening_method == PASO_STANDARD_COARSENING) {
239     Paso_Pattern_Standard(A_p,mis_marker,options->coarsening_threshold);
240     }
241 gross 2551 else {
242     /*Default coarseneing*/
243 artak 2816 Paso_Pattern_Standard(A_p,mis_marker,options->coarsening_threshold);
244 artak 2659 /*Paso_Pattern_YS(A_p,mis_marker,options->coarsening_threshold);*/
245 artak 2828 /*Paso_Pattern_greedy_Agg(A_p,mis_marker,options->coarsening_threshold);*/
246 artak 2816 /*Paso_Pattern_greedy(A_p->pattern,mis_marker);*/
247 artak 2726 /*Paso_Pattern_Aggregiation(A_p,mis_marker,options->coarsening_threshold);*/
248 artak 2760
249 gross 2551 }
250 artak 2765
251 artak 2784 if (verbose) fprintf(stdout,"timing: Profilining for level %d:\n",level);
252 artak 2767
253 artak 2765 time0=Paso_timer()-time0;
254 artak 2784 if (verbose) fprintf(stdout,"timing: Coarsening: %e\n",time0);
255 artak 2760
256 artak 2686 #pragma omp parallel for private(i) schedule(static)
257     for (i = 0; i < n; ++i) counter[i]=mis_marker[i];
258 artak 2726
259 artak 2686 out->n_F=Paso_Util_cumsum(n,counter);
260    
261 artak 2726 if (out->n_F==0) {
262 artak 2686 out->coarsest_level=TRUE;
263 artak 2726 level=0;
264 artak 2686 if (verbose) {
265 artak 2726 /*printf("AMG coarsening eliminates all unknowns, switching to Jacobi preconditioner.\n");*/
266     printf("AMG coarsening does not eliminate any of the unknowns, switching to Jacobi preconditioner.\n");
267 artak 2686 }
268 artak 2726 }
269     else if (out->n_F==n) {
270     out->coarsest_level=TRUE;
271     level=0;
272     if (verbose) {
273     /*printf("AMG coarsening eliminates all unknowns, switching to Jacobi preconditioner.\n");*/
274     printf("AMG coarsening eliminates all of the unknowns, switching to Jacobi preconditioner.\n");
275    
276     }
277 artak 2686 } else {
278 artak 2475
279 artak 2686 if (Paso_noError()) {
280    
281     /*#pragma omp parallel for private(i) schedule(static)
282     for (i = 0; i < n; ++i) counter[i]=mis_marker[i];
283     out->n_F=Paso_Util_cumsum(n,counter);
284     */
285 artak 2760
286 artak 2686 out->mask_F=MEMALLOC(n,index_t);
287     out->rows_in_F=MEMALLOC(out->n_F,index_t);
288 artak 2760 if (! (Paso_checkPtr(out->mask_F) || Paso_checkPtr(out->rows_in_F) ) ) {
289 artak 2686 /* creates an index for F from mask */
290     #pragma omp parallel for private(i) schedule(static)
291     for (i = 0; i < out->n_F; ++i) out->rows_in_F[i]=-1;
292     #pragma omp parallel for private(i) schedule(static)
293     for (i = 0; i < n; ++i) {
294     if (mis_marker[i]) {
295     out->rows_in_F[counter[i]]=i;
296     out->mask_F[i]=counter[i];
297     } else {
298     out->mask_F[i]=-1;
299     }
300     }
301    
302 jfenwick 1851 }
303     }
304 artak 2828 /*
305     if(level==1) {
306 artak 2802 printf("##TOTAL: %d, ELIMINATED: %d\n",n,out->n_F);
307     for (i = 0; i < n; ++i) {
308     printf("##%d %d\n",i,mis_marker[i]);
309     }
310 artak 2816 }
311     */
312    
313 artak 2686 /*check whether coarsening process actually makes sense to continue.
314     if coarse matrix at least smaller by 30% then continue, otherwise we stop.*/
315     if ((out->n_F*100/n)<30) {
316     level=1;
317 artak 1881 }
318 gross 2551
319 artak 2686 if ( Paso_noError()) {
320     out->n_C=n-out->n_F;
321     out->rows_in_C=MEMALLOC(out->n_C,index_t);
322     out->mask_C=MEMALLOC(n,index_t);
323     if (! (Paso_checkPtr(out->mask_C) || Paso_checkPtr(out->rows_in_C) ) ) {
324     /* creates an index for C from mask */
325     #pragma omp parallel for private(i) schedule(static)
326     for (i = 0; i < n; ++i) counter[i]=! mis_marker[i];
327     Paso_Util_cumsum(n,counter);
328     #pragma omp parallel for private(i) schedule(static)
329     for (i = 0; i < out->n_C; ++i) out->rows_in_C[i]=-1;
330     #pragma omp parallel for private(i) schedule(static)
331     for (i = 0; i < n; ++i) {
332     if (! mis_marker[i]) {
333     out->rows_in_C[counter[i]]=i;
334     out->mask_C[i]=counter[i];
335     } else {
336     out->mask_C[i]=-1;
337     }
338     }
339     }
340     }
341     if ( Paso_noError()) {
342 artak 2760 /* get A_FF block: */
343     /*
344     out->A_FF=Paso_SparseMatrix_getSubmatrix(A_p,out->n_F,out->n_F,out->rows_in_F,out->mask_F);
345 artak 2686 out->A_CF=Paso_SparseMatrix_getSubmatrix(A_p,out->n_C,out->n_F,out->rows_in_C,out->mask_F);
346     out->A_FC=Paso_SparseMatrix_getSubmatrix(A_p,out->n_F,out->n_C,out->rows_in_F,out->mask_C);
347 artak 2760 */
348    
349     /*Compute W_FC*/
350     /*initialy W_FC=A_FC*/
351     out->W_FC=Paso_SparseMatrix_getSubmatrix(A_p,out->n_F,out->n_C,out->rows_in_F,out->mask_C);
352    
353     /*sprintf(filename,"W_FCbefore_%d",level);
354     Paso_SparseMatrix_saveMM(out->W_FC,filename);
355     */
356 artak 2802 /* for (i = 0; i < n; ++i) {
357     printf("##mis_marker[%d]=%d\n",i,mis_marker[i]);
358     }
359     */
360 artak 2765 time0=Paso_timer();
361 artak 2760 Paso_SparseMatrix_updateWeights(A_p,out->W_FC,mis_marker);
362 artak 2765 time0=Paso_timer()-time0;
363 artak 2784 if (verbose) fprintf(stdout,"timing: updateWeights: %e\n",time0);
364 artak 2765
365 artak 2802
366     /*sprintf(filename,"W_FCafter_%d",level);
367 artak 2760 Paso_SparseMatrix_saveMM(out->W_FC,filename);
368     */
369 artak 2802
370 artak 2760 /* get Prolongation and Restriction */
371 artak 2765 time0=Paso_timer();
372 artak 2760 out->P=Paso_SparseMatrix_getProlongation(out->W_FC,mis_marker);
373 artak 2765 time0=Paso_timer()-time0;
374 artak 2784 if (verbose) fprintf(stdout,"timing: getProlongation: %e\n",time0);
375 artak 2760
376 artak 2802
377 artak 2828 /*
378     sprintf(filename,"P_%d",level);
379 artak 2760 Paso_SparseMatrix_saveMM(out->P,filename);
380     */
381    
382 artak 2765 time0=Paso_timer();
383 artak 2760 out->R=Paso_SparseMatrix_getRestriction(out->P);
384 artak 2765 time0=Paso_timer()-time0;
385 artak 2784 if (verbose) fprintf(stdout,"timing: getRestriction: %e\n",time0);
386 artak 2765
387 artak 2802
388     /*sprintf(filename,"R_%d",level);
389 artak 2760 Paso_SparseMatrix_saveMM(out->R,filename);
390     */
391    
392 gross 2551 }
393 artak 2686 if ( Paso_noError()) {
394 artak 2765
395     time0=Paso_timer();
396 artak 2784
397     Atemp=Paso_SparseMatrix_MatrixMatrix(A_p,out->P);
398     A_c=Paso_SparseMatrix_MatrixMatrix(out->R,Atemp);
399    
400     Paso_SparseMatrix_free(Atemp);
401    
402     /*A_c=Paso_Solver_getCoarseMatrix(A_p,out->R,out->P);*/
403 artak 2765 time0=Paso_timer()-time0;
404 artak 2784 if (verbose) fprintf(stdout,"timing: getCoarseMatrix: %e\n",time0);
405 artak 2765
406 artak 2784
407 artak 2760 /*Paso_Solver_getCoarseMatrix(A_c, A_p,out->R,out->P);*/
408 artak 2767
409 artak 2784
410     /*sprintf(filename,"A_C_%d",level);
411 artak 2760 Paso_SparseMatrix_saveMM(A_c,filename);
412 artak 2767 */
413    
414 artak 2760 out->AMG_of_Coarse=Paso_Solver_getAMG(A_c,level-1,options);
415 gross 2551 }
416 artak 2760
417 artak 2686 /* allocate work arrays for AMG application */
418     if (Paso_noError()) {
419 artak 2767 /*
420     out->x_F=MEMALLOC(n_block*out->n_F,double);
421 artak 2686 out->b_F=MEMALLOC(n_block*out->n_F,double);
422 artak 2767 */
423 artak 2686 out->x_C=MEMALLOC(n_block*out->n_C,double);
424     out->b_C=MEMALLOC(n_block*out->n_C,double);
425    
426 artak 2767 /*if (! (Paso_checkPtr(out->x_F) || Paso_checkPtr(out->b_F) || Paso_checkPtr(out->x_C) || Paso_checkPtr(out->b_C) ) ) {*/
427     if ( ! ( Paso_checkPtr(out->x_C) || Paso_checkPtr(out->b_C) ) ) {
428    
429     /*
430     #pragma omp parallel for private(i) schedule(static)
431 artak 2686 for (i = 0; i < out->n_F; ++i) {
432     out->x_F[i]=0.;
433     out->b_F[i]=0.;
434     }
435 artak 2767 */
436    
437 artak 2686 #pragma omp parallel for private(i) schedule(static)
438     for (i = 0; i < out->n_C; ++i) {
439     out->x_C[i]=0.;
440     out->b_C[i]=0.;
441     }
442     }
443     }
444 artak 2760 Paso_SparseMatrix_free(A_c);
445 artak 2686 }
446 jfenwick 1851 }
447     }
448     TMPMEMFREE(mis_marker);
449     TMPMEMFREE(counter);
450 artak 2686
451 jfenwick 1851 if (Paso_noError()) {
452 artak 2524 if (verbose && level>0 && !out->coarsest_level) {
453 gross 2551 printf("AMG: level: %d: %d unknowns eliminated. %d left.\n",level, out->n_F,out->n_C);
454 jfenwick 1851 }
455     return out;
456     } else {
457     Paso_Solver_AMG_free(out);
458     return NULL;
459     }
460     }
461    
462     /**************************************************************/
463    
464     /* apply AMG precondition b-> x
465    
466     in fact it solves
467    
468 artak 2381 [ I 0 ] [ A_FF 0 ] [ I invA_FF*A_FC ] [ x_F ] = [b_F]
469 jfenwick 1851 [ A_CF*invA_FF I ] [ 0 S ] [ 0 I ] [ x_C ] = [b_C]
470    
471     in the form
472    
473     b->[b_F,b_C]
474     x_F=invA_FF*b_F
475     b_C=b_C-A_CF*x_F
476     x_C=AMG(b_C)
477     b_F=b_F-A_FC*x_C
478     x_F=invA_FF*b_F
479     x<-[x_F,x_C]
480    
481     should be called within a parallel region
482     barrier synconization should be performed to make sure that the input vector available
483    
484     */
485    
486     void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b) {
487 artak 2107 dim_t i;
488 artak 2507 double time0=0;
489 gross 2551 double *r=NULL, *x0=NULL;
490 artak 2509 bool_t verbose=0;
491 artak 2784
492 artak 2803 dim_t post_sweeps=amg->post_sweeps;
493     dim_t pre_sweeps=amg->pre_sweeps;
494    
495 artak 2699 #ifdef UMFPACK
496     Paso_UMFPACK_Handler * ptr=NULL;
497 artak 2507 #endif
498 artak 2760
499 artak 2784
500 gross 2551 r=MEMALLOC(amg->n,double);
501     x0=MEMALLOC(amg->n,double);
502 artak 2507
503 artak 2524 if (amg->coarsest_level) {
504 artak 2507
505     time0=Paso_timer();
506 artak 2699 /*If all unknown are eliminated then Jacobi is the best preconditioner*/
507 artak 2784 /*Paso_Solver_solveJacobi(amg->GS,x,b);*/
508    
509 artak 2726 if (amg->n_F==0 || amg->n_F==amg->n) {
510 artak 2828 if(amg->Smoother->ID==PASO_JACOBI)
511     Paso_Solver_solveJacobi(amg->Smoother->Jacobi,x,b);
512     else if (amg->Smoother->ID==PASO_GS)
513     Paso_Solver_solveGS(amg->Smoother->GS,x,b);
514 artak 2699 }
515     else {
516 artak 2712 #ifdef MKL
517     Paso_MKL1(amg->AOffset1,x,b,verbose);
518     #else
519     #ifdef UMFPACK
520 gross 2551 ptr=(Paso_UMFPACK_Handler *)(amg->solver);
521 artak 2652 Paso_UMFPACK1(&ptr,amg->A,x,b,verbose);
522 gross 2551 amg->solver=(void*) ptr;
523 artak 2712 #else
524 artak 2828 if(amg->Smoother->ID==PASO_JACOBI)
525     Paso_Solver_solveJacobi(amg->Smoother->Jacobi,x,b);
526     else if (amg->Smoother->ID==PASO_GS)
527     Paso_Solver_solveGS(amg->Smoother->GS,x,b);
528 artak 2699 #endif
529 artak 2507 #endif
530 artak 2699 }
531 artak 2784
532 artak 2475 time0=Paso_timer()-time0;
533 artak 2784 if (verbose) fprintf(stdout,"timing: DIRECT SOLVER: %e\n",time0);
534 artak 2507
535 jfenwick 1851 } else {
536 artak 1902 /* presmoothing */
537 artak 2507 time0=Paso_timer();
538 artak 2828 if(amg->Smoother->ID==PASO_JACOBI)
539     Paso_Solver_solveJacobi(amg->Smoother->Jacobi,x,b);
540     else if (amg->Smoother->ID==PASO_GS)
541     Paso_Solver_solveGS(amg->Smoother->GS,x,b);
542 artak 2803
543     /***********/
544 artak 2816 if (pre_sweeps>1) {
545     #pragma omp parallel for private(i) schedule(static)
546     for (i=0;i<amg->n;++i) r[i]=b[i];
547     }
548 artak 2803
549     while(pre_sweeps>1) {
550     #pragma omp parallel for private(i) schedule(static)
551     for (i=0;i<amg->n;++i) r[i]+=b[i];
552    
553 artak 2816 /* Compute the residual r=r-Ax*/
554 artak 2803 Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
555     /* Go round again*/
556 artak 2828
557     if(amg->Smoother->ID==PASO_JACOBI)
558     Paso_Solver_solveJacobi(amg->Smoother->Jacobi,x,r);
559     else if (amg->Smoother->ID==PASO_GS)
560     Paso_Solver_solveGS(amg->Smoother->GS,x,r);
561    
562 artak 2803 pre_sweeps-=1;
563     }
564     /***********/
565    
566 artak 2507 time0=Paso_timer()-time0;
567 artak 2784 if (verbose) fprintf(stdout,"timing: Presmooting: %e\n",time0);
568 artak 2803 /* end of presmoothing */
569 artak 1939
570 artak 2507 time0=Paso_timer();
571 artak 1890 #pragma omp parallel for private(i) schedule(static)
572     for (i=0;i<amg->n;++i) r[i]=b[i];
573    
574     /*r=b-Ax*/
575     Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
576 artak 2760
577     /* b_c <- R*r */
578     Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(1.,amg->R,r,0.,amg->b_C);
579 artak 1954
580 artak 2507 time0=Paso_timer()-time0;
581 artak 2784 if (verbose) fprintf(stdout,"timing: Before next level: %e\n",time0);
582 artak 2507
583 jfenwick 1851 /* x_C=AMG(b_C) */
584 artak 2760 Paso_Solver_solveAMG(amg->AMG_of_Coarse,amg->x_C,amg->b_C);
585 artak 1890
586 artak 2507 time0=Paso_timer();
587 artak 2726
588 artak 2760 /* x_0 <- P*x_c */
589     Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(1.,amg->P,amg->x_C,0.,x0);
590    
591     /* x=x+x0 */
592 artak 1954 #pragma omp parallel for private(i) schedule(static)
593 artak 2760 for (i=0;i<amg->n;++i) x[i]+=x0[i];
594 artak 1954
595 artak 2767 /*postsmoothing*/
596 artak 2803
597 artak 2767 time0=Paso_timer();
598     #pragma omp parallel for private(i) schedule(static)
599     for (i=0;i<amg->n;++i) r[i]=b[i];
600    
601     /*r=b-Ax */
602     Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
603 artak 2828 if(amg->Smoother->ID==PASO_JACOBI)
604     Paso_Solver_solveJacobi(amg->Smoother->Jacobi,x0,r);
605     else if (amg->Smoother->ID==PASO_GS)
606     Paso_Solver_solveGS(amg->Smoother->GS,x0,r);
607 artak 2767
608    
609     #pragma omp parallel for private(i) schedule(static)
610     for (i=0;i<amg->n;++i) {
611     x[i]+=x0[i];
612     }
613 artak 2803 /***************/
614     while(post_sweeps>1) {
615    
616     #pragma omp parallel for private(i) schedule(static)
617     for (i=0;i<amg->n;++i) r[i]=b[i];
618    
619     Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
620 artak 2828
621     if(amg->Smoother->ID==PASO_JACOBI)
622     Paso_Solver_solveJacobi(amg->Smoother->Jacobi,x0,r);
623     else if (amg->Smoother->ID==PASO_GS)
624     Paso_Solver_solveGS(amg->Smoother->GS,x0,r);
625    
626 artak 2803 #pragma omp parallel for private(i) schedule(static)
627     for (i=0;i<amg->n;++i) {
628     x[i]+=x0[i];
629     }
630     post_sweeps-=1;
631     }
632     /**************/
633 artak 2767
634     time0=Paso_timer()-time0;
635 artak 2784 if (verbose) fprintf(stdout,"timing: Postsmoothing: %e\n",time0);
636 artak 2767
637     /*end of postsmoothing*/
638 artak 2107
639 artak 2760 }
640 artak 1890 MEMFREE(r);
641 artak 1954 MEMFREE(x0);
642 artak 2760
643 gross 2551 return;
644 jfenwick 1851 }

  ViewVC Help
Powered by ViewVC 1.1.26