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

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

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

revision 3323 by gross, Thu Oct 28 09:53:46 2010 UTC revision 3352 by gross, Tue Nov 16 03:58:09 2010 UTC
# Line 97  Paso_Preconditioner_LocalAMG* Paso_Preco Line 97  Paso_Preconditioner_LocalAMG* Paso_Preco
97       } else {       } else {
98             Paso_Preconditioner_AMG_setStrongConnections(A_p, degree, S, theta,tau);             Paso_Preconditioner_AMG_setStrongConnections(A_p, degree, S, theta,tau);
99       }       }
100       Paso_Preconditioner_AMG_RungeStuebenSearch(n, A_p->pattern->ptr, degree, S, split_marker);       Paso_Preconditioner_AMG_RungeStuebenSearch(n, A_p->pattern->ptr, degree, S, split_marker, options->usePanel);
101       options->coarsening_selection_time=Esys_timer()-time0 + MAX(0, options->coarsening_selection_time);       options->coarsening_selection_time=Esys_timer()-time0 + MAX(0, options->coarsening_selection_time);
102            
103       if (Esys_noError() ) {       if (Esys_noError() ) {
# Line 429  void Paso_Preconditioner_AMG_setStrongCo Line 429  void Paso_Preconditioner_AMG_setStrongCo
429    
430  /* the runge stueben coarsening algorithm: */  /* the runge stueben coarsening algorithm: */
431  void Paso_Preconditioner_AMG_RungeStuebenSearch(const dim_t n, const index_t* offset,  void Paso_Preconditioner_AMG_RungeStuebenSearch(const dim_t n, const index_t* offset,
432                           const dim_t* degree, const index_t* S,                          const dim_t* degree, const index_t* S,
433                           index_t*split_marker)                          index_t*split_marker, const bool_t usePanel)
434  {  {
435     index_t *lambda=NULL, j, *ST=NULL;    
436     dim_t i,k, p, q, *degreeT=NULL, itmp;     index_t *lambda=NULL, *ST=NULL, *notInPanel=NULL, *panel=NULL, lambda_max, lambda_k;
437     double time0=0;     dim_t i,k, p, q, *degreeT=NULL, len_panel, len_panel_new;
438       register index_t j, itmp;
439        
440     if (n<=0) return; /* make sure that the return of Paso_Util_arg_max is not pointing to nirvana */     if (n<=0) return; /* make sure that the return of Paso_Util_arg_max is not pointing to nirvana */
441        
442     lambda=TMPMEMALLOC(n, index_t);     lambda=TMPMEMALLOC(n, index_t); Esys_checkPtr(lambda);
443     degreeT=TMPMEMALLOC(n, dim_t);     degreeT=TMPMEMALLOC(n, dim_t); Esys_checkPtr(degreeT);
444     ST=TMPMEMALLOC(offset[n], index_t);     ST=TMPMEMALLOC(offset[n], index_t);  Esys_checkPtr(ST);
445       if (usePanel) {
446          notInPanel=TMPMEMALLOC(n, bool_t); Esys_checkPtr(notInPanel);
447          panel=TMPMEMALLOC(n, index_t); Esys_checkPtr(panel);
448       }
449        
450     if (! ( Esys_checkPtr(lambda) || Esys_checkPtr(degreeT) || Esys_checkPtr(ST) ) ) {    
451  time0=Esys_timer();    
452       if (Esys_noError() ) {
453        /* initialize  split_marker and split_marker :*/        /* initialize  split_marker and split_marker :*/
454        /* those unknows which are not influenced go into F, the rest is available for F or C */        /* those unknows which are not influenced go into F, the rest is available for F or C */
455        #pragma omp parallel for private(i) schedule(static)        #pragma omp parallel for private(i) schedule(static)
# Line 482  time0=Esys_timer(); Line 487  time0=Esys_timer();
487          lambda[i]=itmp;          lambda[i]=itmp;
488       }       }
489        }        }
490        /* printf("timing: %e\n",Esys_timer()-time0); */        if (usePanel) {
491        time0=Esys_timer();       #pragma omp parallel for private(i) schedule(static)
492         for (i=0;i<n;++i) notInPanel[i]=TRUE;
493          }
494        /* start search :*/        /* start search :*/
495        i=Paso_Util_arg_max(n,lambda);        i=Paso_Util_arg_max(n,lambda);
496        while (lambda[i]>-1) { /* is there any undecided unknowns? */        while (lambda[i]>-1) { /* is there any undecided unknown? */
497        
498       /* the unknown i is moved to C */       if (usePanel) {
499       split_marker[i]=PASO_AMG_IN_C;          len_panel=0;
500       lambda[i]=-1;  /* lambda fro unavailable unknowns is set to -1 */          do {
501                   /* the unknown i is moved to C */
502       /* all undecided unknown strongly coupled to i are moved to F */             split_marker[i]=PASO_AMG_IN_C;
503       for (p=0; p<degreeT[i]; ++p) {             lambda[i]=-1;  /* lambda from unavailable unknowns is set to -1 */
504          j=ST[offset[i]+p];            
505                   /* all undecided unknown strongly coupled to i are moved to F */
506          if (split_marker[j]==PASO_AMG_UNDECIDED) {             for (p=0; p<degreeT[i]; ++p) {
507                    j=ST[offset[i]+p];
508             split_marker[j]=PASO_AMG_IN_F;            
509             lambda[j]=-1;            if (split_marker[j]==PASO_AMG_UNDECIDED) {
510                      
511             for (q=0; q<degreeT[j]; ++q) {               split_marker[j]=PASO_AMG_IN_F;
512            k=ST[offset[j]+q];               lambda[j]=-1;
513            if (split_marker[k]==PASO_AMG_UNDECIDED) lambda[k]++;              
514                 for (q=0; q<degreeT[j]; ++q) {
515                k=ST[offset[j]+q];
516                if (split_marker[k]==PASO_AMG_UNDECIDED) {
517                   lambda[k]++;
518                   if (notInPanel[k]) {
519                      notInPanel[k]=FALSE;
520                      panel[len_panel]=k;
521                      len_panel++;
522                   }
523    
524                }    /* the unknown i is moved to C */
525                split_marker[i]=PASO_AMG_IN_C;
526                lambda[i]=-1;  /* lambda from unavailable unknowns is set to -1 */
527                 }
528                
529              }
530               }
531               for (p=0; p<degree[i]; ++p) {
532              j=S[offset[i]+p];
533              if (split_marker[j]==PASO_AMG_UNDECIDED) {
534                 lambda[j]--;
535                 if (notInPanel[j]) {
536                notInPanel[j]=FALSE;
537                panel[len_panel]=j;
538                len_panel++;
539                 }
540              }
541             }             }
542    
543               /* consolidate panel */
544               /* remove lambda[q]=-1 */
545               lambda_max=-1;
546               i=-1;
547               len_panel_new=0;
548               for (q=0; q<len_panel; q++) {
549                 k=panel[q];
550                 lambda_k=lambda[k];
551                 if (split_marker[k]==PASO_AMG_UNDECIDED) {
552                panel[len_panel_new]=k;
553                len_panel_new++;
554    
555                if (lambda_max == lambda_k) {
556                   if (k<i) i=k;
557                } else if (lambda_max < lambda_k) {
558                   lambda_max =lambda_k;
559                   i=k;
560                }
561                 }
562               }
563               len_panel=len_panel_new;
564            } while (len_panel>0);    
565         } else {
566            /* the unknown i is moved to C */
567            split_marker[i]=PASO_AMG_IN_C;
568            lambda[i]=-1;  /* lambda from unavailable unknowns is set to -1 */
569            
570            /* all undecided unknown strongly coupled to i are moved to F */
571            for (p=0; p<degreeT[i]; ++p) {
572               j=ST[offset[i]+p];
573               if (split_marker[j]==PASO_AMG_UNDECIDED) {
574            
575              split_marker[j]=PASO_AMG_IN_F;
576              lambda[j]=-1;
577            
578              for (q=0; q<degreeT[j]; ++q) {
579                 k=ST[offset[j]+q];
580                 if (split_marker[k]==PASO_AMG_UNDECIDED) lambda[k]++;
581              }
582    
583               }
584          }          }
585            for (p=0; p<degree[i]; ++p) {
586               j=S[offset[i]+p];
587               if(split_marker[j]==PASO_AMG_UNDECIDED) lambda[j]--;
588            }
589            
590       }       }
      for (p=0; p<degree[i]; ++p) {  
         j=S[offset[i]+p];  
         if(split_marker[j]==PASO_AMG_UNDECIDED) lambda[j]--;  
      }  
       
591       i=Paso_Util_arg_max(n,lambda);       i=Paso_Util_arg_max(n,lambda);
592        }        }
593     }     }
    /* printf("timing: %e\n",Esys_timer()-time0); */  
594     TMPMEMFREE(lambda);     TMPMEMFREE(lambda);
595     TMPMEMFREE(ST);     TMPMEMFREE(ST);
596     TMPMEMFREE(degreeT);     TMPMEMFREE(degreeT);
597       TMPMEMFREE(panel);
598       TMPMEMFREE(notInPanel);
599  }  }

Legend:
Removed from v.3323  
changed lines
  Added in v.3352

  ViewVC Help
Powered by ViewVC 1.1.26