/[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 1939 by artak, Tue Oct 28 03:47:08 2008 UTC revision 1975 by artak, Thu Nov 6 03:07:02 2008 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,j0;    dim_t i,k,j,j0;
82    Paso_SparseMatrix * schur=NULL;    Paso_SparseMatrix * schur=NULL;
83    Paso_SparseMatrix * schur_withFillIn=NULL;    Paso_SparseMatrix * schur_withFillIn=NULL;
84    double time0,time1,time2,S;    double time0=0,time1=0,time2=0,S;
85        
86    /* identify independend set of rows/columns */    /* identify independend set of rows/columns */
87    mis_marker=TMPMEMALLOC(n,index_t);    mis_marker=TMPMEMALLOC(n,index_t);
# Line 111  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 111  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
111       #pragma omp parallel for private(i) schedule(static)       #pragma omp parallel for private(i) schedule(static)
112       for (i=0;i<n;++i) mis_marker[i]=-1;       for (i=0;i<n;++i) mis_marker[i]=-1;
113       /*Paso_Pattern_RS(A_p,mis_marker,0.25);*/       /*Paso_Pattern_RS(A_p,mis_marker,0.25);*/
114       Paso_Pattern_coup(A_p,mis_marker,1/n);       /*Paso_Pattern_Aggregiation(A_p,mis_marker,0.5);*/
115         Paso_Pattern_coup(A_p,mis_marker,0.05);
116       time2=Paso_timer()-time0;       time2=Paso_timer()-time0;
117       if (Paso_noError()) {       if (Paso_noError()) {
118          #pragma omp parallel for private(i) schedule(static)          #pragma omp parallel for private(i) schedule(static)
# Line 143  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 144  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
144                for (i = 0; i < out->n_F; ++i) {                for (i = 0; i < out->n_F; ++i) {
145                  out->inv_A_FF[i]=0;                  out->inv_A_FF[i]=0;
146                  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) {
147                   out->inv_A_FF[i]+=A_p->val[iPtr];                   j=A_p->pattern->index[iPtr];
148                     if (mis_marker[j])
149                         out->inv_A_FF[i]+=A_p->val[iPtr];
150                  }                  }
151                }                }
152                  
153    /*          for (i=0;i<out->n_F;++i) {
154              fprintf(stderr,"GET INV_A_FF %g %d of %d (%d)\n",out->inv_A_FF[i],i,out->rows_in_F[i],(out->inv_A_FF[i]==0));
155              }
156              fprintf(stderr,"END\n");
157    */
158                #pragma omp for private(i, where_p,iPtr,index) schedule(static)                #pragma omp for private(i, where_p,iPtr,index) schedule(static)
159                for (i = 0; i < out->n_F; i++) {                for (i = 0; i < out->n_F; i++) {
160                  /* find main diagonal */                  /* find main diagonal */
# Line 166  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 174  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
174                        if (ABS(A_p->val[iPtr])>0.) {                        if (ABS(A_p->val[iPtr])>0.) {
175                              if(ABS(S)>0.)                              if(ABS(S)>0.)
176                                 out->inv_A_FF[i]=1./S;                                 out->inv_A_FF[i]=1./S;
177  /*                            else                              else
178                              {                              {
179                                 fprintf(stderr,"ROWSUM OF ROW %d is 0\n",out->rows_in_F[i]);                                 fprintf(stderr,"ROWSUM OF ROW %d->%d is 0\n",i,out->rows_in_F[i]);
180                                 S=0;                                 S=0;
181                                 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) {
182                                 if(A_p->val[iPtr]!=0) {                                 if(A_p->val[iPtr]!=0) {
# Line 178  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 186  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
186                                }                                }
187                                fprintf(stderr,"\n SUMMMMMMM %f\n",S);                                fprintf(stderr,"\n SUMMMMMMM %f\n",S);
188                              }                              }
189  */                      } else {                        } else {
190                              Paso_setError(ZERO_DIVISION_ERROR, "Paso_Solver_getAMG: Break-down in AMG decomposition: non-regular main diagonal block.");                              Paso_setError(ZERO_DIVISION_ERROR, "Paso_Solver_getAMG: Break-down in AMG decomposition: non-regular main diagonal block.");
191                        }                        }
192                  }                  }
# Line 188  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 196  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
196             if( Paso_noError()) {             if( Paso_noError()) {
197                /* 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 */
198                out->n_C=n-out->n_F;                out->n_C=n-out->n_F;
199                /*if (level>0) {*/                if (level<3) {
200                 if (out->n_C>10) {                 /*if (out->n_C>10) {*/
201                     out->rows_in_C=MEMALLOC(out->n_C,index_t);                     out->rows_in_C=MEMALLOC(out->n_C,index_t);
202                     out->mask_C=MEMALLOC(n,index_t);                     out->mask_C=MEMALLOC(n,index_t);
203                     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 290  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 298  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
298    if (Paso_noError()) {    if (Paso_noError()) {
299        if (verbose) {        if (verbose) {
300           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);
301           if (out->n_C>0) {           if (level<3) {
302              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);
303           } else {           } else {
304              printf("timing: AMG: MIS: %e\n",time2);              printf("timing: AMG: MIS: %e\n",time2);
# Line 328  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 336  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
336  */  */
337    
338  void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b) {  void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b) {
339       dim_t i,k,oldsweeps;       dim_t i,oldsweeps;
      dim_t n_block=amg->n_block;  
340       double *r=MEMALLOC(amg->n,double);       double *r=MEMALLOC(amg->n,double);
341       /*Paso_Solver_GS* GS=NULL;*/       /*Paso_Solver_GS* GS=NULL;*/
342       double *bold=MEMALLOC(amg->n*amg->n_block,double);       double *bold=MEMALLOC(amg->n,double);
343       double *bnew=MEMALLOC(amg->n*amg->n_block,double);       double *bnew=MEMALLOC(amg->n,double);
344         double *x0=MEMALLOC(amg->n,double);
345    
346       /*if (amg->level==0) {*/       if (amg->level==3) {
347       if (amg->n_C<=10) {       /*if (amg->n_C<=10) {*/
348          Paso_UMFPACK1(amg->A,x,b,0);          Paso_UMFPACK1(amg->A,x,b,0);
349       } else {       } else {
350        
351          /* presmoothing */          /* presmoothing */
352           Paso_Solver_solveGS(amg->GS,x,b);           Paso_Solver_solveGS(amg->GS,x,b);
353           oldsweeps=amg->GS->sweeps;            oldsweeps=amg->GS->sweeps;
354           if (amg->GS->sweeps>1) {           if (amg->GS->sweeps>1) {
355                        
356             #pragma omp parallel for private(i) schedule(static)             #pragma omp parallel for private(i) schedule(static)
357             for (i=0;i<amg->GS->n*amg->GS->n_block;++i) bold[i]=b[i];             for (i=0;i<amg->GS->n;++i) bold[i]=b[i];
358                        
359             while(amg->GS->sweeps>1) {             while(amg->GS->sweeps>1) {
360                 #pragma omp parallel for private(i) schedule(static)                 #pragma omp parallel for private(i) schedule(static)
361                 for (i=0;i<amg->GS->n*amg->GS->n_block;++i) bnew[i]=bold[i]+b[i];                 for (i=0;i<amg->GS->n;++i) bnew[i]=bold[i]+b[i];
                 /* Compute the residual b=b-Ax*/  
362                 Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(DBLE(-1), amg->A, x, DBLE(1), bnew);                 Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(DBLE(-1), amg->A, x, DBLE(1), bnew);
                /* Go round again*/  
363                 Paso_Solver_solveGS(amg->GS,x,bnew);                 Paso_Solver_solveGS(amg->GS,x,bnew);
364                 #pragma omp parallel for private(i) schedule(static)                 #pragma omp parallel for private(i) schedule(static)
365                 for (i=0;i<amg->GS->n*amg->GS->n_block;++i) bold[i]=bnew[i];                 for (i=0;i<amg->GS->n;++i) bold[i]=bnew[i];
366                 amg->GS->sweeps=amg->GS->sweeps-1;                 amg->GS->sweeps=amg->GS->sweeps-1;
367             }             }
368             }             }
369             amg->GS->sweeps=oldsweeps;             amg->GS->sweeps=oldsweeps;
370              
371          /* end of presmoothing */          /* end of presmoothing */
372                    
373           #pragma omp parallel for private(i) schedule(static)           #pragma omp parallel for private(i) schedule(static)
# Line 367  void Paso_Solver_solveAMG(Paso_Solver_AM Line 375  void Paso_Solver_solveAMG(Paso_Solver_AM
375                    
376           /*r=b-Ax*/           /*r=b-Ax*/
377           Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);           Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
378          
379          /* b->[b_F,b_C]     */          /* b->[b_F,b_C]     */
380          if (n_block==1) {          #pragma omp parallel for private(i) schedule(static)
381             #pragma omp parallel for private(i) schedule(static)          for (i=0;i<amg->n_F;++i) amg->b_F[i]=r[amg->rows_in_F[i]];
382             for (i=0;i<amg->n_F;++i) amg->b_F[i]=r[amg->rows_in_F[i]];            
383            #pragma omp parallel for private(i) schedule(static)          #pragma omp parallel for private(i) schedule(static)
384             for (i=0;i<amg->n_C;++i) amg->b_C[i]=r[amg->rows_in_C[i]];          for (i=0;i<amg->n_C;++i) amg->b_C[i]=r[amg->rows_in_C[i]];
         } else {  
            #pragma omp parallel for private(i,k) schedule(static)  
            for (i=0;i<amg->n_F;++i)  
                  for (k=0;k<n_block;k++) amg->b_F[amg->n_block*i+k]=r[n_block*amg->rows_in_F[i]+k];  
            #pragma omp parallel for private(i,k) schedule(static)  
            for (i=0;i<amg->n_C;++i)  
                  for (k=0;k<n_block;k++) amg->b_C[amg->n_block*i+k]=r[n_block*amg->rows_in_C[i]+k];  
         }  
385    
386          /* x_F=invA_FF*b_F  */          /* x_F=invA_FF*b_F  */
387          Paso_Solver_applyBlockDiagonalMatrix(n_block,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);
388                    
389          /* b_C=b_C-A_CF*x_F */          /* b_C=b_C-A_CF*x_F */
390          Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A_CF,amg->x_F,1.,amg->b_C);          Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A_CF,amg->x_F,1.,amg->b_C);
# Line 395  void Paso_Solver_solveAMG(Paso_Solver_AM Line 395  void Paso_Solver_solveAMG(Paso_Solver_AM
395          /* b_F=b_F-A_FC*x_C */          /* b_F=b_F-A_FC*x_C */
396          Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A_FC,amg->x_C,1.,amg->b_F);          Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A_FC,amg->x_C,1.,amg->b_F);
397          /* x_F=invA_FF*b_F  */          /* x_F=invA_FF*b_F  */
398          Paso_Solver_applyBlockDiagonalMatrix(n_block,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);
399          /* x<-[x_F,x_C]     */          /* x<-[x_F,x_C]     */
400                    
401          if (n_block==1) {          #pragma omp parallel for private(i) schedule(static)
402             #pragma omp parallel for private(i) schedule(static)          for (i=0;i<amg->n;++i) {
403             for (i=0;i<amg->n;++i) {              if (amg->mask_C[i]>-1) {
404                if (amg->mask_C[i]>-1) {                   x[i]+=amg->x_C[amg->mask_C[i]];
405                    x[i]+=amg->x_C[amg->mask_C[i]];              } else {
406                } else {                   x[i]+=amg->x_F[amg->mask_F[i]];
407                    x[i]+=amg->x_F[amg->mask_F[i]];              }
               }  
            }  
         } else {  
            #pragma omp parallel for private(i,k) schedule(static)  
            for (i=0;i<amg->n;++i) {  
                  if (amg->mask_C[i]>-1) {  
                      for (k=0;k<n_block;k++) x[n_block*i+k]+=amg->x_C[n_block*amg->mask_C[i]+k];  
                  } else {  
                      for (k=0;k<n_block;k++) x[n_block*i+k]+=amg->x_F[n_block*amg->mask_F[i]+k];  
                  }  
            }  
408          }          }
409            
410    
411       /*postsmoothing*/       /*postsmoothing*/
412       Paso_Solver_solveGS1(amg->GS,x,b);       #pragma omp parallel for private(i) schedule(static)
413       if (amg->GS->sweeps>1) {       for (i=0;i<amg->n;++i) r[i]=b[i];
414             #pragma omp parallel for private(i) schedule(static)  
415             for (i=0;i<amg->GS->n*amg->GS->n_block;++i) bold[i]=b[i];       /*r=b-Ax*/
416                   Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
417             while(amg->GS->sweeps>1) {       Paso_Solver_solveGS(amg->GS,x0,r);
418                 #pragma omp parallel for private(i) schedule(static)      
419                 for (i=0;i<amg->GS->n*amg->GS->n_block;++i) bnew[i]=bold[i]+b[i];       #pragma omp parallel for private(i) schedule(static)
420                  /* Compute the residual b=b-Ax*/       for (i=0;i<amg->n;++i) {
421                 Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(DBLE(-1), amg->A, x, DBLE(1), bnew);        x[i]+=x0[i];
422                 /* Go round again*/       }
423                 Paso_Solver_solveGS1(amg->GS,x,bnew);      
                #pragma omp parallel for private(i) schedule(static)  
                for (i=0;i<amg->GS->n*amg->GS->n_block;++i) bold[i]=bnew[i];  
                amg->GS->sweeps=amg->GS->sweeps-1;  
            }  
            }  
424       /*end of postsmoothing*/       /*end of postsmoothing*/
425            
426       /*Paso_Solver_GS_free(GS);*/       /*Paso_Solver_GS_free(amg->GS);*/
427       }       }
428       MEMFREE(r);       MEMFREE(r);
429       MEMFREE(bold);       MEMFREE(bold);
430       MEMFREE(bnew);       MEMFREE(bnew);
431         MEMFREE(x0);
432      return;      return;
433  }  }
434    

Legend:
Removed from v.1939  
changed lines
  Added in v.1975

  ViewVC Help
Powered by ViewVC 1.1.26