/[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 2767 by artak, Mon Nov 23 06:00:37 2009 UTC revision 2784 by artak, Thu Nov 26 05:09:14 2009 UTC
# Line 58  void Paso_Solver_AMG_free(Paso_Solver_AM Line 58  void Paso_Solver_AMG_free(Paso_Solver_AM
58          Paso_SparseMatrix_free(in->A_CF);          Paso_SparseMatrix_free(in->A_CF);
59          Paso_SparseMatrix_free(in->P);          Paso_SparseMatrix_free(in->P);
60          Paso_SparseMatrix_free(in->R);          Paso_SparseMatrix_free(in->R);
           
61          Paso_SparseMatrix_free(in->A);          Paso_SparseMatrix_free(in->A);
62          if(in->coarsest_level==TRUE) {          if(in->coarsest_level==TRUE) {
63          #ifdef MKL          #ifdef MKL
# Line 119  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 118  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
118    dim_t i;    dim_t i;
119    Paso_SparseMatrix * A_c=NULL;    Paso_SparseMatrix * A_c=NULL;
120    double time0=0;    double time0=0;
121      Paso_SparseMatrix * Atemp=NULL;
122      double sparsity=0;
123        
124    /*    /*
125    double *temp,*temp_1;    double *temp,*temp_1;
126    double S;    double S;
127    index_t iptr;    index_t iptr;
128    */    */
129        verbose=1;
130    /*char filename[8];*/    /*char filename[8];*/
131    /*sprintf(filename,"AMGLevel%d",level);    /*sprintf(filename,"AMGLevel%d",level);
132        
# Line 171  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 172  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
172       out->n_F=n+1;       out->n_F=n+1;
173       out->n_block=n_block;       out->n_block=n_block;
174            
175         sparsity=(A_p->len*1.)/(1.*A_p->numRows*A_p->numCols);
176        
177         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);
178        
179        if(sparsity>0.01) {
180          level=0;
181         }
182        
183        
184       if (level==0 || n<=options->min_coarse_matrix_size) {       if (level==0 || n<=options->min_coarse_matrix_size) {
185           out->coarsest_level=TRUE;           out->coarsest_level=TRUE;
186             /*out->GS=Paso_Solver_getJacobi(A_p);*/
187            
188           #ifdef MKL           #ifdef MKL
189                    out->AOffset1=Paso_SparseMatrix_alloc(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_OFFSET1, out->A->pattern,1,1, FALSE);                    out->AOffset1=Paso_SparseMatrix_alloc(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_OFFSET1, out->A->pattern,1,1, FALSE);
190                    #pragma omp parallel for private(i) schedule(static)                    #pragma omp parallel for private(i) schedule(static)
# Line 185  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 197  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
197                  out->GS=Paso_Solver_getJacobi(A_p);                  out->GS=Paso_Solver_getJacobi(A_p);
198              #endif              #endif
199           #endif           #endif
200            
201       } else {       } else {
202           out->coarsest_level=FALSE;           out->coarsest_level=FALSE;
203           out->GS=Paso_Solver_getJacobi(A_p);           out->GS=Paso_Solver_getJacobi(A_p);
# Line 214  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 227  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
227                            
228          }          }
229                    
230          if (verbose) fprintf(stderr,"timing: Profilining for level %d:\n",level);          if (verbose) fprintf(stdout,"timing: Profilining for level %d:\n",level);
231                    
232          time0=Paso_timer()-time0;          time0=Paso_timer()-time0;
233          if (verbose) fprintf(stderr,"timing: Coarsening: %e\n",time0);          if (verbose) fprintf(stdout,"timing: Coarsening: %e\n",time0);
234    
235          #pragma omp parallel for private(i) schedule(static)          #pragma omp parallel for private(i) schedule(static)
236          for (i = 0; i < n; ++i) counter[i]=mis_marker[i];          for (i = 0; i < n; ++i) counter[i]=mis_marker[i];
# Line 314  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 327  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
327                        /*sprintf(filename,"W_FCbefore_%d",level);                        /*sprintf(filename,"W_FCbefore_%d",level);
328                        Paso_SparseMatrix_saveMM(out->W_FC,filename);                        Paso_SparseMatrix_saveMM(out->W_FC,filename);
329                        */                        */
330                                                                      
331                        time0=Paso_timer();                        time0=Paso_timer();
332                        Paso_SparseMatrix_updateWeights(A_p,out->W_FC,mis_marker);                        Paso_SparseMatrix_updateWeights(A_p,out->W_FC,mis_marker);
333                        time0=Paso_timer()-time0;                        time0=Paso_timer()-time0;
334                        if (verbose) fprintf(stderr,"timing: updateWeights: %e\n",time0);                        if (verbose) fprintf(stdout,"timing: updateWeights: %e\n",time0);
335                    
336                        /*                        /*
337                         printf("GOT W_FC, but n=%d,n_F=%d,n_C=%d\n",out->n,out->n_F,out->n_C);                         printf("GOT W_FC, but n=%d,n_F=%d,n_C=%d\n",out->n,out->n_F,out->n_C);
# Line 330  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 343  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
343                        time0=Paso_timer();                        time0=Paso_timer();
344                        out->P=Paso_SparseMatrix_getProlongation(out->W_FC,mis_marker);                        out->P=Paso_SparseMatrix_getProlongation(out->W_FC,mis_marker);
345                        time0=Paso_timer()-time0;                        time0=Paso_timer()-time0;
346                        if (verbose) fprintf(stderr,"timing: getProlongation: %e\n",time0);                        if (verbose) fprintf(stdout,"timing: getProlongation: %e\n",time0);
347                                                
348                        /*                        /*
349                         printf("GOT Prolongation P->nxc %dx%d\n",out->P->numRows,out->P->numCols);                         printf("GOT Prolongation P->nxc %dx%d\n",out->P->numRows,out->P->numCols);
# Line 341  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 354  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
354                        time0=Paso_timer();                        time0=Paso_timer();
355                        out->R=Paso_SparseMatrix_getRestriction(out->P);                        out->R=Paso_SparseMatrix_getRestriction(out->P);
356                        time0=Paso_timer()-time0;                        time0=Paso_timer()-time0;
357                        if (verbose) fprintf(stderr,"timing: getRestriction: %e\n",time0);                        if (verbose) fprintf(stdout,"timing: getRestriction: %e\n",time0);
358                                                
359                        /*                        /*
360                        printf("GOT Restriction->cxn %dx%d\n",out->R->numRows,out->R->numCols);                        printf("GOT Restriction->cxn %dx%d\n",out->R->numRows,out->R->numCols);
# Line 353  Paso_Solver_AMG* Paso_Solver_getAMG(Paso Line 366  Paso_Solver_AMG* Paso_Solver_getAMG(Paso
366                if ( Paso_noError()) {                if ( Paso_noError()) {
367                                            
368                      time0=Paso_timer();                      time0=Paso_timer();
369                      A_c=Paso_Solver_getCoarseMatrix(A_p,out->R,out->P);                      
370                        Atemp=Paso_SparseMatrix_MatrixMatrix(A_p,out->P);
371                        A_c=Paso_SparseMatrix_MatrixMatrix(out->R,Atemp);
372                        
373                        Paso_SparseMatrix_free(Atemp);
374                        
375                        /*A_c=Paso_Solver_getCoarseMatrix(A_p,out->R,out->P);*/
376                      time0=Paso_timer()-time0;                      time0=Paso_timer()-time0;
377                      if (verbose) fprintf(stderr,"timing: getCoarseMatrix: %e\n",time0);                      if (verbose) fprintf(stdout,"timing: getCoarseMatrix: %e\n",time0);
378                                            
379                                            
380                      /*Paso_Solver_getCoarseMatrix(A_c, A_p,out->R,out->P);*/                      /*Paso_Solver_getCoarseMatrix(A_c, A_p,out->R,out->P);*/
381                                            
382                      /*                      
383                      sprintf(filename,"A_C_%d",level);                      /*sprintf(filename,"A_C_%d",level);
384                      Paso_SparseMatrix_saveMM(A_c,filename);                      Paso_SparseMatrix_saveMM(A_c,filename);
385                      */                      */
386                                            
# Line 441  void Paso_Solver_solveAMG(Paso_Solver_AM Line 461  void Paso_Solver_solveAMG(Paso_Solver_AM
461       double time0=0;       double time0=0;
462       double *r=NULL, *x0=NULL;       double *r=NULL, *x0=NULL;
463       bool_t verbose=0;       bool_t verbose=0;
464        
465       #ifdef UMFPACK       #ifdef UMFPACK
466            Paso_UMFPACK_Handler * ptr=NULL;            Paso_UMFPACK_Handler * ptr=NULL;
467       #endif       #endif
468            
469              
470       r=MEMALLOC(amg->n,double);       r=MEMALLOC(amg->n,double);
471       x0=MEMALLOC(amg->n,double);       x0=MEMALLOC(amg->n,double);
472            
# Line 452  void Paso_Solver_solveAMG(Paso_Solver_AM Line 474  void Paso_Solver_solveAMG(Paso_Solver_AM
474                
475        time0=Paso_timer();        time0=Paso_timer();
476        /*If all unknown are eliminated then Jacobi is the best preconditioner*/        /*If all unknown are eliminated then Jacobi is the best preconditioner*/
477          /*Paso_Solver_solveJacobi(amg->GS,x,b);*/
478          
479        if (amg->n_F==0 || amg->n_F==amg->n) {        if (amg->n_F==0 || amg->n_F==amg->n) {
480          Paso_Solver_solveJacobi(amg->GS,x,b);          Paso_Solver_solveJacobi(amg->GS,x,b);
481        }        }
# Line 468  void Paso_Solver_solveAMG(Paso_Solver_AM Line 492  void Paso_Solver_solveAMG(Paso_Solver_AM
492           #endif           #endif
493         #endif         #endif
494         }         }
495          
496         time0=Paso_timer()-time0;         time0=Paso_timer()-time0;
497         if (verbose) fprintf(stderr,"timing: DIRECT SOLVER: %e\n",time0);         if (verbose) fprintf(stdout,"timing: DIRECT SOLVER: %e\n",time0);
498                
499       } else {       } else {
500          /* presmoothing */          /* presmoothing */
501           time0=Paso_timer();           time0=Paso_timer();
502           Paso_Solver_solveJacobi(amg->GS,x,b);           Paso_Solver_solveJacobi(amg->GS,x,b);
503           time0=Paso_timer()-time0;           time0=Paso_timer()-time0;
504           if (verbose) fprintf(stderr,"timing: Presmooting: %e\n",time0);           if (verbose) fprintf(stdout,"timing: Presmooting: %e\n",time0);
505          /* end of presmoothing */          /* end of presmoothing */
506                    
507                    
# Line 492  void Paso_Solver_solveAMG(Paso_Solver_AM Line 517  void Paso_Solver_solveAMG(Paso_Solver_AM
517           Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(1.,amg->R,r,0.,amg->b_C);           Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(1.,amg->R,r,0.,amg->b_C);
518                    
519          time0=Paso_timer()-time0;          time0=Paso_timer()-time0;
520          if (verbose) fprintf(stderr,"timing: Before next level: %e\n",time0);          if (verbose) fprintf(stdout,"timing: Before next level: %e\n",time0);
521                    
522          /* x_C=AMG(b_C)     */          /* x_C=AMG(b_C)     */
523          Paso_Solver_solveAMG(amg->AMG_of_Coarse,amg->x_C,amg->b_C);          Paso_Solver_solveAMG(amg->AMG_of_Coarse,amg->x_C,amg->b_C);
# Line 523  void Paso_Solver_solveAMG(Paso_Solver_AM Line 548  void Paso_Solver_solveAMG(Paso_Solver_AM
548        }        }
549                
550        time0=Paso_timer()-time0;        time0=Paso_timer()-time0;
551        if (verbose) fprintf(stderr,"timing: Postsmoothing: %e\n",time0);        if (verbose) fprintf(stdout,"timing: Postsmoothing: %e\n",time0);
552    
553        /*end of postsmoothing*/        /*end of postsmoothing*/
554            

Legend:
Removed from v.2767  
changed lines
  Added in v.2784

  ViewVC Help
Powered by ViewVC 1.1.26