/[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 2360 by artak, Thu Apr 2 04:12:12 2009 UTC revision 2442 by artak, Fri May 29 00:39:44 2009 UTC
# Line 81  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 81  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
81    dim_t i,k,j;    dim_t i,k,j;
82    Paso_SparseMatrix * schur=NULL;    Paso_SparseMatrix * schur=NULL;
83    Paso_SparseMatrix * schur_withFillIn=NULL;    Paso_SparseMatrix * schur_withFillIn=NULL;
84    double time0=0,time1=0,time2=0,S=0;    double S=0;
85    /*Paso_Pattern* test;*/    
86      /*Make sure we have block sizes 1*/
87      A_p->pattern->input_block_size=A_p->col_block_size;
88      A_p->pattern->output_block_size=A_p->row_block_size;
89      A_p->pattern->block_size=A_p->block_size;
90        
91    /* identify independend set of rows/columns */    /* identify independend set of rows/columns */
92    mis_marker=TMPMEMALLOC(n,index_t);    mis_marker=TMPMEMALLOC(n,index_t);
# Line 107  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 111  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
111    out->GS=Paso_Solver_getJacobi(A_p);    out->GS=Paso_Solver_getJacobi(A_p);
112    /*out->GS->sweeps=2;*/    /*out->GS->sweeps=2;*/
113    out->level=level;    out->level=level;
114      
115    if ( !(Paso_checkPtr(mis_marker) || Paso_checkPtr(out) || Paso_checkPtr(counter) ) ) {    if ( !(Paso_checkPtr(mis_marker) || Paso_checkPtr(out) || Paso_checkPtr(counter) || level==0 ) ) {
116       /* identify independend set of rows/columns */       /* identify independend set of rows/columns */
117       #pragma omp parallel for private(i) schedule(static)       #pragma omp parallel for private(i) schedule(static)
118       for (i=0;i<n;++i) mis_marker[i]=-1;       for (i=0;i<n;++i) mis_marker[i]=-1;
119       Paso_Pattern_coup(A_p,mis_marker,couplingParam);       Paso_Pattern_coup(A_p,mis_marker,couplingParam);
120        /*Paso_Pattern_RS(A_p,mis_marker,couplingParam);*/
121         /*Paso_Pattern_Aggregiation(A_p,mis_marker,couplingParam);*/
122       if (Paso_noError()) {       if (Paso_noError()) {
123          #pragma omp parallel for private(i) schedule(static)          #pragma omp parallel for private(i) schedule(static)
124          for (i = 0; i < n; ++i) counter[i]=mis_marker[i];          for (i = 0; i < n; ++i) counter[i]=mis_marker[i];
# Line 146  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 152  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
152                   if (mis_marker[j])                   if (mis_marker[j])
153                       S+=A_p->val[iPtr];                       S+=A_p->val[iPtr];
154                  }                  }
155                     out->inv_A_FF[i]=1./S;                  out->inv_A_FF[i]=1./S;
156                }                }
157    
158             if( Paso_noError()) {             if( Paso_noError()) {
159                /* 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 */
160                out->n_C=n-out->n_F;                out->n_C=n-out->n_F;
161                if (level>0 && out->n_F>500) {                if (level>0 && out->n_C>500) {
162                 /*if (out->n_F>500) {*/                 /*if (out->n_F>500) {*/
163                     out->rows_in_C=MEMALLOC(out->n_C,index_t);                     out->rows_in_C=MEMALLOC(out->n_C,index_t);
164                     out->mask_C=MEMALLOC(n,index_t);                     out->mask_C=MEMALLOC(n,index_t);
# Line 192  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 198  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
198                                for (iPtr=schur_withFillIn->pattern->ptr[i];iPtr<schur_withFillIn->pattern->ptr[i + 1]; ++iPtr) {                                for (iPtr=schur_withFillIn->pattern->ptr[i];iPtr<schur_withFillIn->pattern->ptr[i + 1]; ++iPtr) {
199                                  j=schur_withFillIn->pattern->index[iPtr];                                  j=schur_withFillIn->pattern->index[iPtr];
200                                  iPtr_s=schur->pattern->ptr[i];                                  iPtr_s=schur->pattern->ptr[i];
201                                  schur_withFillIn->val[iPtr]=0.;                                  /*schur_withFillIn->val[iPtr]=0.;*/
202                                  index=&(schur->pattern->index[iPtr_s]);                                  index=&(schur->pattern->index[iPtr_s]);
203                                  where_p=(index_t*)bsearch(&j,                                  where_p=(index_t*)bsearch(&j,
204                                          index,                                          index,
# Line 245  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 251  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
251    TMPMEMFREE(mis_marker);    TMPMEMFREE(mis_marker);
252    TMPMEMFREE(counter);    TMPMEMFREE(counter);
253    if (Paso_noError()) {    if (Paso_noError()) {
254        if (verbose) {        if (verbose && level>0) {
255           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,out->n_C);
256           if (level>0 && out->n_F>500) {           /*if (level>0 && out->n_F>500) {*/
257          /* if (out->n_F<500) {*/          /* if (out->n_F<500) {*/
258              printf("timing: AMG: MIS/reordering/elemination : %e/%e/%e\n",time2,time0,time1);          /*   printf("timing: AMG: MIS/reordering/elemination : %e/%e\n",time0,time1);
259           } else {           } else {
260              printf("timing: AMG: MIS: %e\n",time2);              printf("timing: AMG: MIS: %e\n",time2);
261           }           }*/
262       }       }
263       return out;       return out;
264    } else  {    } else  {
# Line 267  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 273  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
273    
274       in fact it solves       in fact it solves
275    
276    [      I         0  ]  [ A_FF 0 ] [ I    invA_FF*A_FF ]  [ x_F ]  = [b_F]    [      I         0  ]  [ A_FF 0 ] [ I    invA_FF*A_FC ]  [ x_F ]  = [b_F]
277    [ A_CF*invA_FF   I  ]  [   0  S ] [ 0          I      ]  [ x_C ]  = [b_C]    [ A_CF*invA_FF   I  ]  [   0  S ] [ 0          I      ]  [ x_C ]  = [b_C]
278    
279   in the form   in the form
# Line 288  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 294  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
294  void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b) {  void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b) {
295       dim_t i;       dim_t i;
296       double *r=MEMALLOC(amg->n,double);       double *r=MEMALLOC(amg->n,double);
      /*Paso_Solver_GS* GS=NULL;*/  
297       double *x0=MEMALLOC(amg->n,double);       double *x0=MEMALLOC(amg->n,double);
298       double time0=0;       /*double time0=0;*/
299            
300       if (amg->level==0  || amg->n_F<=500) {       if (amg->level==0  || amg->n_C<=500) {
301       /*if (amg->n_F<=500) {*/       /*if (amg->n_F<=500) {*/
302        time0=Paso_timer();        /*time0=Paso_timer();*/
303                    
304          Paso_Solver_solveJacobi(amg->GS,x,b);          Paso_Solver_solveJacobi(amg->GS,x,b);
305                    
# Line 308  void Paso_Solver_solveAMG(Paso_Solver_AM Line 313  void Paso_Solver_solveAMG(Paso_Solver_AM
313          }          }
314          */          */
315          /*Paso_UMFPACK1(amg->A,x,b,0);*/          /*Paso_UMFPACK1(amg->A,x,b,0);*/
316            
317         time0=Paso_timer()-time0;         /*time0=Paso_timer()-time0;
318         /*fprintf(stderr,"timing: DIRECT SOLVER: %e/\n",time0);*/         fprintf(stderr,"timing: DIRECT SOLVER: %e/\n",time0);*/
319       } else {       } else {
       
320          /* presmoothing */          /* presmoothing */
321           Paso_Solver_solveJacobi(amg->GS,x,b);           Paso_Solver_solveJacobi(amg->GS,x,b);
322           /*           /*
# Line 371  void Paso_Solver_solveAMG(Paso_Solver_AM Line 375  void Paso_Solver_solveAMG(Paso_Solver_AM
375       #pragma omp parallel for private(i) schedule(static)       #pragma omp parallel for private(i) schedule(static)
376       for (i=0;i<amg->n;++i) r[i]=b[i];       for (i=0;i<amg->n;++i) r[i]=b[i];
377            
378       /*r=b-Ax*/       /*r=b-Ax */
379       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
380       Paso_Solver_solveJacobi(amg->GS,x0,r);       Paso_Solver_solveJacobi(amg->GS,x0,r);
381            
# Line 383  void Paso_Solver_solveAMG(Paso_Solver_AM Line 387  void Paso_Solver_solveAMG(Paso_Solver_AM
387       for (i=0;i<amg->n;++i) r[i]=b[i];       for (i=0;i<amg->n;++i) r[i]=b[i];
388    
389       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
390       Paso_Solver_solveGS(amg->GS,x0,r);       Paso_Solver_solveJacobi(amg->GS,x0,r);
391            
392       #pragma omp parallel for private(i) schedule(static)       #pragma omp parallel for private(i) schedule(static)
393       for (i=0;i<amg->n;++i) {       for (i=0;i<amg->n;++i) {
394        x[i]+=x0[i];        x[i]+=x0[i];
395       }       }*/
396       */      
397       /*end of postsmoothing*/       /*end of postsmoothing*/
398            
399       }       }

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

  ViewVC Help
Powered by ViewVC 1.1.26