/[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 1953 by artak, Tue Oct 28 03:50:01 2008 UTC revision 1954 by artak, Fri Oct 31 03:22:34 2008 UTC
# Line 102  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 102  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
102    out->b_C=NULL;    out->b_C=NULL;
103    out->A=Paso_SparseMatrix_getReference(A_p);    out->A=Paso_SparseMatrix_getReference(A_p);
104    out->GS=Paso_Solver_getGS(A_p,verbose);    out->GS=Paso_Solver_getGS(A_p,verbose);
105    out->GS->sweeps=2;    out->GS->sweeps=4;
106    out->level=level;    out->level=level;
107        
108    if ( !(Paso_checkPtr(mis_marker) || Paso_checkPtr(out) || Paso_checkPtr(counter) ) ) {    if ( !(Paso_checkPtr(mis_marker) || Paso_checkPtr(out) || Paso_checkPtr(counter) ) ) {
# Line 110  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 110  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
110       time0=Paso_timer();       time0=Paso_timer();
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,1/n);       /*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 146  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 147  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
147                   out->inv_A_FF[i]+=A_p->val[iPtr];                   out->inv_A_FF[i]+=A_p->val[iPtr];
148                  }                  }
149                }                }
150                  
151    /*          for (i=0;i<out->n_F;++i) {
152              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));
153              }
154              fprintf(stderr,"END\n");
155    */
156                #pragma omp for private(i, where_p,iPtr,index) schedule(static)                #pragma omp for private(i, where_p,iPtr,index) schedule(static)
157                for (i = 0; i < out->n_F; i++) {                for (i = 0; i < out->n_F; i++) {
158                  /* find main diagonal */                  /* find main diagonal */
# Line 166  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 172  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
172                        if (ABS(A_p->val[iPtr])>0.) {                        if (ABS(A_p->val[iPtr])>0.) {
173                              if(ABS(S)>0.)                              if(ABS(S)>0.)
174                                 out->inv_A_FF[i]=1./S;                                 out->inv_A_FF[i]=1./S;
175  /*                            else                              else
176                              {                              {
177                                 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]);
178                                 S=0;                                 S=0;
179                                 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) {
180                                 if(A_p->val[iPtr]!=0) {                                 if(A_p->val[iPtr]!=0) {
# Line 178  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 184  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
184                                }                                }
185                                fprintf(stderr,"\n SUMMMMMMM %f\n",S);                                fprintf(stderr,"\n SUMMMMMMM %f\n",S);
186                              }                              }
187  */                      } else {                        } else {
188                              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.");
189                        }                        }
190                  }                  }
# Line 188  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 194  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
194             if( Paso_noError()) {             if( Paso_noError()) {
195                /* 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 */
196                out->n_C=n-out->n_F;                out->n_C=n-out->n_F;
197                /*if (level>0) {*/                if (level<2) {
198                 if (out->n_C>10) {                /*if (out->n_C>10) {*/
199                     out->rows_in_C=MEMALLOC(out->n_C,index_t);                     out->rows_in_C=MEMALLOC(out->n_C,index_t);
200                     out->mask_C=MEMALLOC(n,index_t);                     out->mask_C=MEMALLOC(n,index_t);
201                     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 296  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
296    if (Paso_noError()) {    if (Paso_noError()) {
297        if (verbose) {        if (verbose) {
298           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);
299           if (out->n_C>0) {           if (out->n_C>10) {
300              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);
301           } else {           } else {
302              printf("timing: AMG: MIS: %e\n",time2);              printf("timing: AMG: MIS: %e\n",time2);
# Line 328  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 334  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
334  */  */
335    
336  void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b) {  void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b) {
337       dim_t i,k,oldsweeps;       dim_t i,k,oldsweeps,j;
      dim_t n_block=amg->n_block;  
338       double *r=MEMALLOC(amg->n,double);       double *r=MEMALLOC(amg->n,double);
339       /*Paso_Solver_GS* GS=NULL;*/       /*Paso_Solver_GS* GS=NULL;*/
340       double *bold=MEMALLOC(amg->n*amg->n_block,double);       double *bold=MEMALLOC(amg->n,double);
341       double *bnew=MEMALLOC(amg->n*amg->n_block,double);       double *bnew=MEMALLOC(amg->n,double);
342         double *x0=MEMALLOC(amg->n,double);
343         index_t iPtr;
344    
345       /*if (amg->level==0) {*/       if (amg->level==2) {
346       if (amg->n_C<=10) {       /*if (amg->n_C<=10) {*/
347          Paso_UMFPACK1(amg->A,x,b,0);          Paso_UMFPACK1(amg->A,x,b,0);
348       } else {       } else {
349        
350          /* presmoothing */          /* presmoothing */
351           Paso_Solver_solveGS(amg->GS,x,b);           Paso_Solver_solveGS(amg->GS,x,b);
352           oldsweeps=amg->GS->sweeps;           oldsweeps=amg->GS->sweeps;
353           if (amg->GS->sweeps>1) {           if (amg->GS->sweeps>1) {
354                        
355             #pragma omp parallel for private(i) schedule(static)             #pragma omp parallel for private(i) schedule(static)
356             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];
357                        
358             while(amg->GS->sweeps>1) {             while(amg->GS->sweeps>1) {
359                 #pragma omp parallel for private(i) schedule(static)                 #pragma omp parallel for private(i) schedule(static)
360                 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];
361                  /* Compute the residual b=b-Ax*/                  /* 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);
363                 /* Go round again*/                 /* Go round again*/
364                 Paso_Solver_solveGS(amg->GS,x,bnew);                 Paso_Solver_solveGS(amg->GS,x,bnew);
365                 #pragma omp parallel for private(i) schedule(static)                 #pragma omp parallel for private(i) schedule(static)
366                 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];
367                 amg->GS->sweeps=amg->GS->sweeps-1;                 amg->GS->sweeps=amg->GS->sweeps-1;
368             }             }
369             }             }
# 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];       /*for (i=0;i<amg->n;++i) fprintf(stderr,"%lf %lf %d %d %d BBB\n",r[i],x[i],amg->n,amg->A->numCols, amg->level);*/
416                  
417             while(amg->GS->sweeps>1) {       /*
418                 #pragma omp parallel for private(i) schedule(static)       for (i = 0; i < amg->A->numRows; ++i) {
419                 for (i=0;i<amg->GS->n*amg->GS->n_block;++i) bnew[i]=bold[i]+b[i];            for (iPtr=amg->A->pattern->ptr[i];iPtr<amg->A->pattern->ptr[i + 1]; ++iPtr) {
420                  /* Compute the residual b=b-Ax*/                j=amg->A->pattern->index[iPtr];
421                 Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(DBLE(-1), amg->A, x, DBLE(1), bnew);                fprintf(stderr,"A[%d,%d]=%lf ",i,j,amg->A->val[iPtr]);
422                 /* Go round again*/            }
423                 Paso_Solver_solveGS1(amg->GS,x,bnew);            fprintf(stderr,"\n");
424                 #pragma omp parallel for private(i) schedule(static)       }*/
425                 for (i=0;i<amg->GS->n*amg->GS->n_block;++i) bold[i]=bnew[i];      
426                 amg->GS->sweeps=amg->GS->sweeps-1;       /*r=b-Ax*/
427             }       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,amg->A,x,1.,r);
428             }       Paso_Solver_solveGS(amg->GS,x0,r);
429        
430         #pragma omp parallel for private(i) schedule(static)
431         for (i=0;i<amg->n;++i) {
432          /*fprintf(stderr,"%lf %lf %lf\n",x[i],x0[i],x[i]+x0[i]);*/
433          x[i]+=x0[i];
434         }
435        
436       /*end of postsmoothing*/       /*end of postsmoothing*/
437            
438       /*Paso_Solver_GS_free(GS);*/       /*Paso_Solver_GS_free(amg->GS);*/
439       }       }
440       MEMFREE(r);       MEMFREE(r);
441       MEMFREE(bold);       MEMFREE(bold);
442       MEMFREE(bnew);       MEMFREE(bnew);
443         MEMFREE(x0);
444      return;      return;
445  }  }
446    

Legend:
Removed from v.1953  
changed lines
  Added in v.1954

  ViewVC Help
Powered by ViewVC 1.1.26