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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2107 by artak, Fri Nov 28 04:39:07 2008 UTC revision 2360 by artak, Thu Apr 2 04:12:12 2009 UTC
# Line 35  Line 35 
35  void Paso_Solver_AMG_free(Paso_Solver_AMG * in) {  void Paso_Solver_AMG_free(Paso_Solver_AMG * in) {
36       if (in!=NULL) {       if (in!=NULL) {
37          Paso_Solver_AMG_free(in->AMG_of_Schur);          Paso_Solver_AMG_free(in->AMG_of_Schur);
38          Paso_Solver_ILU_free(in->GS);          Paso_Solver_Jacobi_free(in->GS);
39          MEMFREE(in->inv_A_FF);          MEMFREE(in->inv_A_FF);
40          MEMFREE(in->A_FF_pivot);          MEMFREE(in->A_FF_pivot);
41          Paso_SparseMatrix_free(in->A_FC);          Paso_SparseMatrix_free(in->A_FC);
# Line 71  to Line 71  to
71     then AMG is applied to S again until S becomes empty     then AMG is applied to S again until S becomes empty
72    
73  */  */
74  Paso_Solver_AMG* Paso_Solver_getAMG(Paso_SparseMatrix *A_p,bool_t verbose,dim_t level) {  Paso_Solver_AMG* Paso_Solver_getAMG(Paso_SparseMatrix *A_p,bool_t verbose,dim_t level, double couplingParam) {
75    Paso_Solver_AMG* out=NULL;    Paso_Solver_AMG* out=NULL;
76    dim_t n=A_p->numRows;    dim_t n=A_p->numRows;
77    dim_t n_block=A_p->row_block_size;    dim_t n_block=A_p->row_block_size;
# Line 103  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 103  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
103    out->b_C=NULL;    out->b_C=NULL;
104    out->GS=NULL;    out->GS=NULL;
105    out->A=Paso_SparseMatrix_getReference(A_p);    out->A=Paso_SparseMatrix_getReference(A_p);
106    out->GS=Paso_Solver_getILU(A_p,verbose);    /*out->GS=Paso_Solver_getGS(A_p,verbose);*/
107    /*out->GS=Paso_Solver_getJacobi(A_p);*/    out->GS=Paso_Solver_getJacobi(A_p);
108    /*out->GS->sweeps=2;*/    /*out->GS->sweeps=2;*/
109    out->level=level;    out->level=level;
110        
# Line 112  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 112  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
112       /* identify independend set of rows/columns */       /* identify independend set of rows/columns */
113       #pragma omp parallel for private(i) schedule(static)       #pragma omp parallel for private(i) schedule(static)
114       for (i=0;i<n;++i) mis_marker[i]=-1;       for (i=0;i<n;++i) mis_marker[i]=-1;
115       /*Paso_Pattern_RS(A_p,mis_marker,0.25);*/       Paso_Pattern_coup(A_p,mis_marker,couplingParam);
      /*Paso_Pattern_Aggregiation(A_p,mis_marker,0.5);*/  
      Paso_Pattern_coup(A_p,mis_marker,0.05);  
116       if (Paso_noError()) {       if (Paso_noError()) {
117          #pragma omp parallel for private(i) schedule(static)          #pragma omp parallel for private(i) schedule(static)
118          for (i = 0; i < n; ++i) counter[i]=mis_marker[i];          for (i = 0; i < n; ++i) counter[i]=mis_marker[i];
# Line 140  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 138  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
138                }                }
139                                
140                /* Compute row-sum for getting rs(A_FF)^-1*/                /* Compute row-sum for getting rs(A_FF)^-1*/
141                #pragma omp parallel for private(i,iPtr,j) schedule(static)                #pragma omp parallel for private(i,iPtr,j,S) schedule(static)
142                for (i = 0; i < out->n_F; ++i) {                for (i = 0; i < out->n_F; ++i) {
143                  S=0;                  S=0;
144                  for (iPtr=A_p->pattern->ptr[out->rows_in_F[i]];iPtr<A_p->pattern->ptr[out->rows_in_F[i] + 1]; ++iPtr) {                  for (iPtr=A_p->pattern->ptr[out->rows_in_F[i]];iPtr<A_p->pattern->ptr[out->rows_in_F[i] + 1]; ++iPtr) {
# Line 148  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 146  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
146                   if (mis_marker[j])                   if (mis_marker[j])
147                       S+=A_p->val[iPtr];                       S+=A_p->val[iPtr];
148                  }                  }
                 if (ABS(S)>0)  
149                     out->inv_A_FF[i]=1./S;                     out->inv_A_FF[i]=1./S;
150                }                }
151    
152             if( Paso_noError()) {             if( Paso_noError()) {
153                /* if there are no nodes in the coarse level there is no more work to do */                /* if there are no nodes in the coarse level there is no more work to do */
154                out->n_C=n-out->n_F;                out->n_C=n-out->n_F;
155                /*if (level<5) {*/                if (level>0 && out->n_F>500) {
156                 if (out->n_F>50) {                 /*if (out->n_F>500) {*/
157                     out->rows_in_C=MEMALLOC(out->n_C,index_t);                     out->rows_in_C=MEMALLOC(out->n_C,index_t);
158                     out->mask_C=MEMALLOC(n,index_t);                     out->mask_C=MEMALLOC(n,index_t);
159                     if (! (Paso_checkPtr(out->mask_C) || Paso_checkPtr(out->rows_in_C) ) ) {                     if (! (Paso_checkPtr(out->mask_C) || Paso_checkPtr(out->rows_in_C) ) ) {
# Line 184  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 181  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
181                           if (Paso_noError()) {                           if (Paso_noError()) {
182                              schur=Paso_SparseMatrix_getSubmatrix(A_p,out->n_C,out->n_C,out->rows_in_C,out->mask_C);                              schur=Paso_SparseMatrix_getSubmatrix(A_p,out->n_C,out->n_C,out->rows_in_C,out->mask_C);
183                              /*find the pattern of the schur complement with fill in*/                              /*find the pattern of the schur complement with fill in*/
184                                
185                              schur_withFillIn=Paso_SparseMatrix_alloc(A_p->type,Paso_Pattern_binop(PATTERN_FORMAT_DEFAULT, schur->pattern, Paso_Pattern_multiply(PATTERN_FORMAT_DEFAULT,out->A_CF->pattern,out->A_FC->pattern)),1,1);                              schur_withFillIn=Paso_SparseMatrix_alloc(A_p->type,Paso_Pattern_binop(PATTERN_FORMAT_DEFAULT, schur->pattern, Paso_Pattern_multiply(PATTERN_FORMAT_DEFAULT,out->A_CF->pattern,out->A_FC->pattern)),1,1);
186                                                            
187                              fprintf(stderr,"Sparsity of Schure: %dx%d LEN %d Percentage %f\n",schur_withFillIn->pattern->numOutput,schur_withFillIn->pattern->numInput,schur_withFillIn->len,schur_withFillIn->len/(1.*schur_withFillIn->pattern->numOutput*schur_withFillIn->pattern->numInput));                              /*fprintf(stderr,"Sparsity of Schure: %dx%d LEN %d Percentage %f\n",schur_withFillIn->pattern->numOutput,schur_withFillIn->pattern->numInput,schur_withFillIn->len,schur_withFillIn->len/(1.*schur_withFillIn->pattern->numOutput*schur_withFillIn->pattern->numInput));*/
188                                                            
189                              /* copy values over*/                              /* copy values over*/
190                              #pragma omp parallel for private(i,iPtr,j,iPtr_s,index,where_p) schedule(static)                              #pragma omp parallel for private(i,iPtr,j,iPtr_s,index,where_p) schedule(static)
# Line 210  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 207  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
207                                                                    
208                              if (Paso_noError()) {                              if (Paso_noError()) {
209                                  Paso_Solver_updateIncompleteSchurComplement(schur_withFillIn,out->A_CF,out->inv_A_FF,out->A_FF_pivot,out->A_FC);                                  Paso_Solver_updateIncompleteSchurComplement(schur_withFillIn,out->A_CF,out->inv_A_FF,out->A_FF_pivot,out->A_FC);
210                                  out->AMG_of_Schur=Paso_Solver_getAMG(schur_withFillIn,verbose,level+1);                                  out->AMG_of_Schur=Paso_Solver_getAMG(schur_withFillIn,verbose,level-1,couplingParam);
211                                  Paso_SparseMatrix_free(schur);                                  Paso_SparseMatrix_free(schur);
212                              }                              }
213                              /* allocate work arrays for AMG application */                              /* allocate work arrays for AMG application */
# Line 250  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 247  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
247    if (Paso_noError()) {    if (Paso_noError()) {
248        if (verbose) {        if (verbose) {
249           printf("AMG: %d unknowns eliminated. %d left.\n",out->n_F,n-out->n_F);           printf("AMG: %d unknowns eliminated. %d left.\n",out->n_F,n-out->n_F);
250           /*if (level<5) {*/           if (level>0 && out->n_F>500) {
251           if (out->n_F<50) {          /* if (out->n_F<500) {*/
252              printf("timing: AMG: MIS/reordering/elemination : %e/%e/%e\n",time2,time0,time1);              printf("timing: AMG: MIS/reordering/elemination : %e/%e/%e\n",time2,time0,time1);
253           } else {           } else {
254              printf("timing: AMG: MIS: %e\n",time2);              printf("timing: AMG: MIS: %e\n",time2);
# Line 295  void Paso_Solver_solveAMG(Paso_Solver_AM Line 292  void Paso_Solver_solveAMG(Paso_Solver_AM
292       double *x0=MEMALLOC(amg->n,double);       double *x0=MEMALLOC(amg->n,double);
293       double time0=0;       double time0=0;
294            
295       /*if (amg->level==5) {*/       if (amg->level==0  || amg->n_F<=500) {
296       if (amg->n_F<=50) {       /*if (amg->n_F<=500) {*/
297        time0=Paso_timer();        time0=Paso_timer();
298                    
299          /*Paso_Solver_solveJacobi(amg->GS,x,b);*/          Paso_Solver_solveJacobi(amg->GS,x,b);
300                    
301          /* #pragma omp parallel for private(i) schedule(static)          /* #pragma omp parallel for private(i) schedule(static)
302          for (i=0;i<amg->n;++i) r[i]=b[i];          for (i=0;i<amg->n;++i) r[i]=b[i];
# Line 310  void Paso_Solver_solveAMG(Paso_Solver_AM Line 307  void Paso_Solver_solveAMG(Paso_Solver_AM
307           x[i]+=x0[i];           x[i]+=x0[i];
308          }          }
309          */          */
310          Paso_UMFPACK1(amg->A,x,b,0);          /*Paso_UMFPACK1(amg->A,x,b,0);*/
311    
312         time0=Paso_timer()-time0;         time0=Paso_timer()-time0;
313         /*fprintf(stderr,"timing: DIRECT SOLVER: %e/\n",time0);*/         /*fprintf(stderr,"timing: DIRECT SOLVER: %e/\n",time0);*/
314       } else {       } else {
315            
316          /* presmoothing */          /* presmoothing */
317           Paso_Solver_solveILU(amg->GS,x,b);           Paso_Solver_solveJacobi(amg->GS,x,b);
318           /*           /*
319           #pragma omp parallel for private(i) schedule(static)           #pragma omp parallel for private(i) schedule(static)
320           for (i=0;i<amg->n;++i) r[i]=b[i];           for (i=0;i<amg->n;++i) r[i]=b[i];
# Line 359  void Paso_Solver_solveAMG(Paso_Solver_AM Line 356  void Paso_Solver_solveAMG(Paso_Solver_AM
356          /* x_F=invA_FF*b_F  */          /* x_F=invA_FF*b_F  */
357          Paso_Solver_applyBlockDiagonalMatrix(1,amg->n_F,amg->inv_A_FF,amg->A_FF_pivot,amg->x_F,amg->b_F);          Paso_Solver_applyBlockDiagonalMatrix(1,amg->n_F,amg->inv_A_FF,amg->A_FF_pivot,amg->x_F,amg->b_F);
358          /* x<-[x_F,x_C]     */          /* x<-[x_F,x_C]     */
359            
360          #pragma omp parallel for private(i) schedule(static)          #pragma omp parallel for private(i) schedule(static)
361          for (i=0;i<amg->n;++i) {          for (i=0;i<amg->n;++i) {
362              if (amg->mask_C[i]>-1) {              if (amg->mask_C[i]>-1) {
# Line 369  void Paso_Solver_solveAMG(Paso_Solver_AM Line 366  void Paso_Solver_solveAMG(Paso_Solver_AM
366              }              }
367          }          }
368                    
   
369       /*postsmoothing*/       /*postsmoothing*/
370    
371       #pragma omp parallel for private(i) schedule(static)       #pragma omp parallel for private(i) schedule(static)
# Line 377  void Paso_Solver_solveAMG(Paso_Solver_AM Line 373  void Paso_Solver_solveAMG(Paso_Solver_AM
373            
374       /*r=b-Ax*/       /*r=b-Ax*/
375       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
376       Paso_Solver_solveILU(amg->GS,x0,r);       Paso_Solver_solveJacobi(amg->GS,x0,r);
377            
378       #pragma omp parallel for private(i) schedule(static)       #pragma omp parallel for private(i) schedule(static)
379       for (i=0;i<amg->n;++i) x[i]+=x0[i];       for (i=0;i<amg->n;++i) x[i]+=x0[i];
# Line 396  void Paso_Solver_solveAMG(Paso_Solver_AM Line 392  void Paso_Solver_solveAMG(Paso_Solver_AM
392       */       */
393       /*end of postsmoothing*/       /*end of postsmoothing*/
394            
   
395       }       }
   
396       MEMFREE(r);       MEMFREE(r);
397       MEMFREE(x0);       MEMFREE(x0);
398      return;      return;

Legend:
Removed from v.2107  
changed lines
  Added in v.2360

  ViewVC Help
Powered by ViewVC 1.1.26