/[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 3352 by gross, Tue Nov 16 03:58:09 2010 UTC revision 3445 by gross, Wed Jan 19 06:02:15 2011 UTC
# Line 14  Line 14 
14    
15  /**************************************************************/  /**************************************************************/
16    
17  /* Paso: AMG preconditioner                                  */  /* Paso: AMG preconditioner  (local version)                  */
18    
19  /**************************************************************/  /**************************************************************/
20    
# Line 35  Line 35 
35    
36  /* free all memory used by AMG                                */  /* free all memory used by AMG                                */
37    
38  void Paso_Preconditioner_LocalAMG_free(Paso_Preconditioner_LocalAMG * in) {  void Paso_Preconditioner_AMG_free(Paso_Preconditioner_AMG * in) {
39       if (in!=NULL) {       if (in!=NULL) {
40      Paso_Preconditioner_LocalSmoother_free(in->Smoother);      Paso_Preconditioner_Smoother_free(in->Smoother);
41      Paso_SparseMatrix_free(in->P);      Paso_SystemMatrix_free(in->P);
42      Paso_SparseMatrix_free(in->R);      Paso_SystemMatrix_free(in->R);
43      Paso_SparseMatrix_free(in->A_C);      Paso_SystemMatrix_free(in->A_C);
44      Paso_Preconditioner_LocalAMG_free(in->AMG_C);      Paso_Preconditioner_AMG_free(in->AMG_C);
45      MEMFREE(in->r);      MEMFREE(in->r);
46      MEMFREE(in->x_C);      MEMFREE(in->x_C);
47      MEMFREE(in->b_C);      MEMFREE(in->b_C);
48    
       
49      MEMFREE(in);      MEMFREE(in);
50       }       }
51  }  }
52    
53    index_t Paso_Preconditioner_AMG_getMaxLevel(const Paso_Preconditioner_AMG * in) {
54       if (in->AMG_C == NULL) {
55          return in->level;
56       } else {
57          return Paso_Preconditioner_AMG_getMaxLevel(in->AMG_C);
58       }
59    }
60    double Paso_Preconditioner_AMG_getCoarseLevelSparsity(const Paso_Preconditioner_AMG * in) {
61          if (in->AMG_C == NULL) {
62         if (in->A_C == NULL) {
63            return 1.;
64         } else {
65            return Paso_SystemMatrix_getSparsity(in->A_C);
66         }
67          } else {
68            return Paso_Preconditioner_AMG_getCoarseLevelSparsity(in->AMG_C);
69          }
70    }
71    dim_t Paso_Preconditioner_AMG_getNumCoarseUnknwons(const Paso_Preconditioner_AMG * in) {
72       if (in->AMG_C == NULL) {
73          if (in->A_C == NULL) {
74         return 0;
75          } else {
76         return Paso_SystemMatrix_getTotalNumRows(in->A_C);
77          }
78       } else {
79         return Paso_Preconditioner_AMG_getNumCoarseUnknwons(in->AMG_C);
80       }
81    }
82  /*****************************************************************  /*****************************************************************
83    
84     constructs AMG     constructs AMG
85        
86  ******************************************************************/  ******************************************************************/
87  Paso_Preconditioner_LocalAMG* Paso_Preconditioner_LocalAMG_alloc(Paso_SparseMatrix *A_p,dim_t level,Paso_Options* options) {  Paso_Preconditioner_AMG* Paso_Preconditioner_AMG_alloc(Paso_SystemMatrix *A_p,dim_t level,Paso_Options* options) {
88    
89    Paso_Preconditioner_LocalAMG* out=NULL;    Paso_Preconditioner_AMG* out=NULL;
90    bool_t verbose=options->verbose;    bool_t verbose=options->verbose;
91        Paso_SystemMatrix *Atemp=NULL, *A_C=NULL;
92    Paso_SparseMatrix *Atemp=NULL, *A_C=NULL;  
93    const dim_t n=A_p->numRows;    const dim_t my_n=Paso_SystemMatrix_getNumRows(A_p);
94      const dim_t overlap_n=Paso_SystemMatrix_getColOverlap(A_p);
95      const dim_t n = my_n + overlap_n;
96    
97    const dim_t n_block=A_p->row_block_size;    const dim_t n_block=A_p->row_block_size;
98    index_t* split_marker=NULL, *counter=NULL, *mask_C=NULL, *rows_in_F=NULL, *S=NULL, *degree=NULL;    index_t* F_marker=NULL, *counter=NULL, *mask_C=NULL, *rows_in_F=NULL;
99    dim_t n_F=0, n_C=0, i;    dim_t n_F=0, n_C=0, i;
100    double time0=0;    double time0=0;
101    const double theta = options->coarsening_threshold;    const double theta = options->coarsening_threshold;
102    const double tau = options->diagonal_dominance_threshold;    const double tau = options->diagonal_dominance_threshold;
103        const double sparsity=Paso_SystemMatrix_getSparsity(A_p);
104      const dim_t total_n=Paso_SystemMatrix_getGlobalTotalNumRows(A_p);
105    
106        
107    /*    /*
108        is the input matrix A suitable for coarsening        is the input matrix A suitable for coarsening
109                
110    */    */
111    if ( (A_p->pattern->len >= options->min_coarse_sparsity * n * n ) || (n <= options->min_coarse_matrix_size) || (level > options->level_max) ) {    if ( (sparsity >= options->min_coarse_sparsity) ||
112       if (verbose) printf("Paso_Solver: AMG level %d (limit = %d) stopped. sparsity = %e (limit = %e), unknowns = %d (limit = %d)\n",         (total_n <= options->min_coarse_matrix_size) ||
113      level,  options->level_max, A_p->pattern->len/(1.*n * n), options->min_coarse_sparsity, n, options->min_coarse_matrix_size  );           (level > options->level_max) ) {
114       return NULL;  
115    }          if (verbose) {
116       /* Start Coarsening : */            /*
117                  print stopping condition:
118                          - 'SPAR' = min_coarse_matrix_sparsity exceeded
119                          - 'SIZE' = min_coarse_matrix_size exceeded
120                          - 'LEVEL' = level_max exceeded
121              */
122              printf("Paso_Preconditioner: AMG: termination of coarsening by ");
123    
124              if (sparsity >= options->min_coarse_sparsity)
125                  printf("SPAR ");
126    
127              if (total_n <= options->min_coarse_matrix_size)
128                  printf("SIZE ");
129    
130              if (level > options->level_max)
131                  printf("LEVEL ");
132    
133              printf("\n");
134    
135            printf("Paso_Preconditioner: AMG level %d (limit = %d) stopped. sparsity = %e (limit = %e), unknowns = %d (limit = %d)\n",
136               level,  options->level_max, sparsity, options->min_coarse_sparsity, total_n, options->min_coarse_matrix_size);  
137    
138       split_marker=TMPMEMALLOC(n,index_t);         }
139    
140           return NULL;
141      }  else {
142          /* Start Coarsening : */
143          const dim_t len_S=A_p->mainBlock->pattern->len+A_p->col_coupleBlock->pattern->len;
144    
145         F_marker=TMPMEMALLOC(n,index_t);
146       counter=TMPMEMALLOC(n,index_t);       counter=TMPMEMALLOC(n,index_t);
147       degree=TMPMEMALLOC(n, dim_t);  
148       S=TMPMEMALLOC(A_p->pattern->len, index_t);       dim_t* degree_S=TMPMEMALLOC(my_n, dim_t);
149       if ( !( Esys_checkPtr(split_marker) || Esys_checkPtr(counter) || Esys_checkPtr(degree) || Esys_checkPtr(S) ) ) {       index_t *offset_S=TMPMEMALLOC(my_n, index_t);
150         index_t *S=TMPMEMALLOC(len_S, index_t);
151         if ( !( Esys_checkPtr(F_marker) || Esys_checkPtr(counter) || Esys_checkPtr(degree_S) || Esys_checkPtr(offset_S) || Esys_checkPtr(S) ) ) {
152       /*       /*
153            set splitting of unknows:            set splitting of unknows:
154                
155           */           */
156       time0=Esys_timer();       time0=Esys_timer();
157       if (n_block>1) {       if (n_block>1) {
158             Paso_Preconditioner_AMG_setStrongConnections_Block(A_p, degree, S, theta,tau);             Paso_Preconditioner_AMG_setStrongConnections_Block(A_p, degree_S, offset_S, S, theta,tau);
159       } else {       } else {
160             Paso_Preconditioner_AMG_setStrongConnections(A_p, degree, S, theta,tau);             Paso_Preconditioner_AMG_setStrongConnections(A_p, degree_S, offset_S, S, theta,tau);
161       }       }
162       Paso_Preconditioner_AMG_RungeStuebenSearch(n, A_p->pattern->ptr, degree, S, split_marker, options->usePanel);  
163       options->coarsening_selection_time=Esys_timer()-time0 + MAX(0, options->coarsening_selection_time);  /*MPI:
164         Paso_Preconditioner_AMG_RungeStuebenSearch(n, A_p->pattern->ptr, degree_S, S, F_marker, options->usePanel);
165    */
166            
167             /* in BoomerAMG interpolation is used FF connectiovity is required :*/
168    /*MPI:
169             if (options->interpolation_method == PASO_CLASSIC_INTERPOLATION_WITH_FF_COUPLING)
170                                 Paso_Preconditioner_AMG_enforceFFConnectivity(n, A_p->pattern->ptr, degree_S, S, F_marker);  
171    */
172    
173         options->coarsening_selection_time=Esys_timer()-time0 + MAX(0, options->coarsening_selection_time);
174    
175    #ifdef AAAAA
176       if (Esys_noError() ) {       if (Esys_noError() ) {
177          #pragma omp parallel for private(i) schedule(static)          #pragma omp parallel for private(i) schedule(static)
178          for (i = 0; i < n; ++i) split_marker[i]= (split_marker[i] == PASO_AMG_IN_F);          for (i = 0; i < n; ++i) F_marker[i]=(F_marker[i] ==  PASO_AMG_IN_F);
179            
180          /*          /*
181             count number of unkowns to be eliminated:             count number of unkowns to be eliminated:
182          */          */
183          n_F=Paso_Util_cumsum_maskedTrue(n,counter, split_marker);          n_F=Paso_Util_cumsum_maskedTrue(n,counter, F_marker);
184          n_C=n-n_F;          n_C=n-n_F;
185          if (verbose) printf("Paso_Solver: AMG level %d: %d unknowns are flagged for elimination. %d left.\n",level,n_F,n-n_F);          if (verbose) printf("Paso_Preconditioner: AMG level %d: %d unknowns are flagged for elimination. %d left.\n",level,n_F,n-n_F);
186            
187          if ( n_F == 0 ) {  /*  is a nasty case. a direct solver should be used, return NULL */          if ( n_F == 0 ) {  /*  is a nasty case. a direct solver should be used, return NULL */
188             out = NULL;             out = NULL;
189          } else {          } else {
190             out=MEMALLOC(1,Paso_Preconditioner_LocalAMG);             out=MEMALLOC(1,Paso_Preconditioner_AMG);
191             if (! Esys_checkPtr(out)) {             if (! Esys_checkPtr(out)) {
192            out->level = level;            out->level = level;
193            out->n = n;            out->n = n;
# Line 137  Paso_Preconditioner_LocalAMG* Paso_Preco Line 210  Paso_Preconditioner_LocalAMG* Paso_Preco
210             Esys_checkPtr(rows_in_F);             Esys_checkPtr(rows_in_F);
211             if ( Esys_noError() ) {             if ( Esys_noError() ) {
212    
213            out->Smoother = Paso_Preconditioner_LocalSmoother_alloc(A_p, (options->smoother == PASO_JACOBI), verbose);            out->Smoother = Paso_Preconditioner_Smoother_alloc(A_p, (options->smoother == PASO_JACOBI), verbose);
214                
215            if ( n_F < n ) { /* if nothing is been removed we have a diagonal dominant matrix and we just run a few steps of the smoother */            if (n_C != 0) {
216                   /* if nothing is been removed we have a diagonal dominant matrix and we just run a few steps of the smoother */
217        
218              /* allocate helpers :*/              /* allocate helpers :*/
219              out->x_C=MEMALLOC(n_block*n_C,double);              out->x_C=MEMALLOC(n_block*n_C,double);
# Line 156  Paso_Preconditioner_LocalAMG* Paso_Preco Line 230  Paso_Preconditioner_LocalAMG* Paso_Preco
230                 {                 {
231                    #pragma omp for schedule(static)                    #pragma omp for schedule(static)
232                    for (i = 0; i < n; ++i) {                    for (i = 0; i < n; ++i) {
233                   if  (split_marker[i]) rows_in_F[counter[i]]=i;                   if  (F_marker[i]) rows_in_F[counter[i]]=i;
234                    }                    }
235                 }                 }
236                 /*  create mask of C nodes with value >-1 gives new id */                 /*  create mask of C nodes with value >-1 gives new id */
237                 i=Paso_Util_cumsum_maskedFalse(n,counter, split_marker);                 i=Paso_Util_cumsum_maskedFalse(n,counter, F_marker);
238    
239                 #pragma omp parallel for private(i) schedule(static)                 #pragma omp parallel for private(i) schedule(static)
240                 for (i = 0; i < n; ++i) {                 for (i = 0; i < n; ++i) {
241                    if  (split_marker[i]) {                    if  (F_marker[i]) {
242                   mask_C[i]=-1;                   mask_C[i]=-1;
243                    } else {                    } else {
244                   mask_C[i]=counter[i];;                   mask_C[i]=counter[i];;
245                    }                    }
246                 }                 }
247                 /*                 /*
248                    get Restriction :                      get Prolongation :    
249                 */                                   */                  
250                 time0=Esys_timer();                 time0=Esys_timer();
251                 out->P=Paso_Preconditioner_AMG_getDirectProlongation(A_p,degree,S,n_C,mask_C);  /*MPI:
252                   out->P=Paso_Preconditioner_AMG_getProlongation(A_p,A_p->pattern->ptr, degree_S,S,n_C,mask_C, options->interpolation_method);
253    */
254                 if (SHOW_TIMING) printf("timing: level %d: getProlongation: %e\n",level, Esys_timer()-time0);                 if (SHOW_TIMING) printf("timing: level %d: getProlongation: %e\n",level, Esys_timer()-time0);
255              }              }
256              /*                    /*      
257                 construct Prolongation operator as transposed of restriction operator:                 construct Restriction operator as transposed of Prolongation operator:
258              */              */
259              if ( Esys_noError()) {              if ( Esys_noError()) {
260                 time0=Esys_timer();                 time0=Esys_timer();
261                 out->R=Paso_SparseMatrix_getTranspose(out->P);  /*MPI:
262                 if (SHOW_TIMING) printf("timing: level %d: Paso_SparseMatrix_getTranspose: %e\n",level,Esys_timer()-time0);                 out->R=Paso_SystemMatrix_getTranspose(out->P);
263    */
264                   if (SHOW_TIMING) printf("timing: level %d: Paso_SystemMatrix_getTranspose: %e\n",level,Esys_timer()-time0);
265              }                    }      
266              /*              /*
267              construct coarse level matrix:              construct coarse level matrix:
268              */              */
269              if ( Esys_noError()) {              if ( Esys_noError()) {
270                 time0=Esys_timer();                 time0=Esys_timer();
271                 Atemp=Paso_SparseMatrix_MatrixMatrix(A_p,out->P);  /*MPI:
272                 A_C=Paso_SparseMatrix_MatrixMatrix(out->R,Atemp);                 Atemp=Paso_SystemMatrix_MatrixMatrix(A_p,out->P);
273                 Paso_SparseMatrix_free(Atemp);                 A_C=Paso_SystemMatrix_MatrixMatrix(out->R,Atemp);
274                  
275                   Paso_SystemMatrix_free(Atemp);
276    */
277    
278                 if (SHOW_TIMING) printf("timing: level %d : construct coarse matrix: %e\n",level,Esys_timer()-time0);                             if (SHOW_TIMING) printf("timing: level %d : construct coarse matrix: %e\n",level,Esys_timer()-time0);            
279              }              }
280    
# Line 202  Paso_Preconditioner_LocalAMG* Paso_Preco Line 284  Paso_Preconditioner_LocalAMG* Paso_Preco
284                                
285              */              */
286              if ( Esys_noError()) {              if ( Esys_noError()) {
287                 out->AMG_C=Paso_Preconditioner_LocalAMG_alloc(A_C,level+1,options);                 out->AMG_C=Paso_Preconditioner_AMG_alloc(A_C,level+1,options);
288              }              }
289              if ( Esys_noError()) {              if ( Esys_noError()) {
290                 if ( out->AMG_C == NULL ) {                 if ( out->AMG_C == NULL ) {
# Line 210  Paso_Preconditioner_LocalAMG* Paso_Preco Line 292  Paso_Preconditioner_LocalAMG* Paso_Preco
292                    out->refinements = options->coarse_matrix_refinements;                    out->refinements = options->coarse_matrix_refinements;
293                    /* no coarse level matrix has been constructed. use direct solver */                    /* no coarse level matrix has been constructed. use direct solver */
294                    #ifdef MKL                    #ifdef MKL
295                      out->A_C=Paso_SparseMatrix_unroll(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_OFFSET1, A_C);                      out->A_C=Paso_SystemMatrix_unroll(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_OFFSET1, A_C);
296                      Paso_SparseMatrix_free(A_C);                      Paso_SystemMatrix_free(A_C);
297                      out->A_C->solver_package = PASO_MKL;                      out->A_C->solver_package = PASO_MKL;
298                      if (verbose) printf("Paso_Solver: AMG: use MKL direct solver on the coarsest level (number of unknowns = %d).\n",n_C);                      if (verbose) printf("Paso_Preconditioner: AMG: use MKL direct solver on the coarsest level (number of unknowns = %d).\n",n_C*n_block);
299                    #else                    #else
300                      #ifdef UMFPACK                      #ifdef UMFPACK
301                         out->A_C=Paso_SparseMatrix_unroll(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_CSC, A_C);                         out->A_C=Paso_SystemMatrix_unroll(MATRIX_FORMAT_BLK1 + MATRIX_FORMAT_CSC, A_C);
302                         Paso_SparseMatrix_free(A_C);                         Paso_SystemMatrix_free(A_C);
303                         out->A_C->solver_package = PASO_UMFPACK;                         out->A_C->solver_package = PASO_UMFPACK;
304                         if (verbose) printf("Paso_Solver: AMG: use UMFPACK direct solver on the coarsest level (number of unknowns = %d).\n",n_C);                         if (verbose) printf("Paso_Preconditioner: AMG: use UMFPACK direct solver on the coarsest level (number of unknowns = %d).\n",n_C*n_block);
305                      #else                      #else
306                         out->A_C=A_C;                         out->A_C=A_C;
307                         out->A_C->solver_p=Paso_Preconditioner_LocalSmoother_alloc(out->A_C, (options->smoother == PASO_JACOBI), verbose);                         out->A_C->solver_p=Paso_Preconditioner_Smoother_alloc(out->A_C, (options->smoother == PASO_JACOBI), verbose);
308                         out->A_C->solver_package = PASO_SMOOTHER;                         out->A_C->solver_package = PASO_SMOOTHER;
309                         if (verbose) printf("Paso_Solver: AMG: use smoother on the coarsest level (number of unknowns = %d).\n",n_C);                         if (verbose) printf("Paso_Preconditioner: AMG: use smoother on the coarsest level (number of unknowns = %d).\n",n_C*n_block);
310                      #endif                      #endif
311                    #endif                    #endif
312                 } else {                 } else {
# Line 238  Paso_Preconditioner_LocalAMG* Paso_Preco Line 320  Paso_Preconditioner_LocalAMG* Paso_Preco
320             TMPMEMFREE(rows_in_F);             TMPMEMFREE(rows_in_F);
321          }          }
322       }       }
323    #endif
324    
325    }    }
326    TMPMEMFREE(counter);    TMPMEMFREE(counter);
327    TMPMEMFREE(split_marker);    TMPMEMFREE(F_marker);
328    TMPMEMFREE(degree);    TMPMEMFREE(degree_S);
329      TMPMEMFREE(offset_S);
330    TMPMEMFREE(S);    TMPMEMFREE(S);
331      }
332    
333    if (Esys_noError()) {    if (Esys_noError()) {
334       return out;       return out;
335    } else  {    } else  {
336       Paso_Preconditioner_LocalAMG_free(out);       Paso_Preconditioner_AMG_free(out);
337       return NULL;       return NULL;
338    }    }
339  }  }
340    
341    
342  void Paso_Preconditioner_LocalAMG_solve(Paso_SparseMatrix* A, Paso_Preconditioner_LocalAMG * amg, double * x, double * b) {  void Paso_Preconditioner_AMG_solve(Paso_SystemMatrix* A, Paso_Preconditioner_AMG * amg, double * x, double * b) {
343       const dim_t n = amg->n * amg->n_block;       const dim_t n = amg->n * amg->n_block;
344       double time0=0;       double time0=0;
345       const dim_t post_sweeps=amg->post_sweeps;       const dim_t post_sweeps=amg->post_sweeps;
# Line 261  void Paso_Preconditioner_LocalAMG_solve( Line 347  void Paso_Preconditioner_LocalAMG_solve(
347    
348       /* presmoothing */       /* presmoothing */
349       time0=Esys_timer();       time0=Esys_timer();
350       Paso_Preconditioner_LocalSmoother_solve(A, amg->Smoother, x, b, pre_sweeps, FALSE);       Paso_Preconditioner_Smoother_solve(A, amg->Smoother, x, b, pre_sweeps, FALSE);
351       time0=Esys_timer()-time0;       time0=Esys_timer()-time0;
352       if (SHOW_TIMING) printf("timing: level %d: Presmooting: %e\n",amg->level, time0);       if (SHOW_TIMING) printf("timing: level %d: Presmooting: %e\n",amg->level, time0);
353       /* end of presmoothing */       /* end of presmoothing */
# Line 269  void Paso_Preconditioner_LocalAMG_solve( Line 355  void Paso_Preconditioner_LocalAMG_solve(
355       if (amg->n_F < amg->n) { /* is there work on the coarse level? */       if (amg->n_F < amg->n) { /* is there work on the coarse level? */
356           time0=Esys_timer();           time0=Esys_timer();
357       Paso_Copy(n, amg->r, b);                            /*  r <- b */       Paso_Copy(n, amg->r, b);                            /*  r <- b */
358       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0(-1.,A,x,1.,amg->r); /*r=r-Ax*/       Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(-1.,A,x,1.,amg->r); /*r=r-Ax*/
359       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0_DIAG(1.,amg->R,amg->r,0.,amg->b_C);  /* b_c = R*r  */       Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(1.,amg->R,amg->r,0.,amg->b_C);  /* b_c = R*r  */
360           time0=Esys_timer()-time0;           time0=Esys_timer()-time0;
361       /* coarse level solve */       /* coarse level solve */
362       if ( amg->AMG_C == NULL) {       if ( amg->AMG_C == NULL) {
363          time0=Esys_timer();          time0=Esys_timer();
364          /*  A_C is the coarsest level */          /*  A_C is the coarsest level */
365    #ifdef FIXME
366          switch (amg->A_C->solver_package) {          switch (amg->A_C->solver_package) {
367             case (PASO_MKL):             case (PASO_MKL):
368            Paso_MKL(amg->A_C, amg->x_C,amg->b_C, amg->reordering, amg->refinements, SHOW_TIMING);            Paso_MKL(amg->A_C, amg->x_C,amg->b_C, amg->reordering, amg->refinements, SHOW_TIMING);
# Line 284  void Paso_Preconditioner_LocalAMG_solve( Line 371  void Paso_Preconditioner_LocalAMG_solve(
371            Paso_UMFPACK(amg->A_C, amg->x_C,amg->b_C, amg->refinements, SHOW_TIMING);            Paso_UMFPACK(amg->A_C, amg->x_C,amg->b_C, amg->refinements, SHOW_TIMING);
372            break;            break;
373             case (PASO_SMOOTHER):             case (PASO_SMOOTHER):
374            Paso_Preconditioner_LocalSmoother_solve(amg->A_C, amg->Smoother,amg->x_C,amg->b_C,pre_sweeps, FALSE);            Paso_Preconditioner_Smoother_solve(amg->A_C, amg->A_C->solver_p,amg->x_C,amg->b_C,pre_sweeps+post_sweeps, FALSE);
375            break;            break;
376          }          }
377    #endif
378            Paso_Preconditioner_Smoother_solve(amg->A_C, amg->A_C->solver_p,amg->x_C,amg->b_C,pre_sweeps+post_sweeps, FALSE);
379          if (SHOW_TIMING) printf("timing: level %d: DIRECT SOLVER: %e\n",amg->level,Esys_timer()-time0);          if (SHOW_TIMING) printf("timing: level %d: DIRECT SOLVER: %e\n",amg->level,Esys_timer()-time0);
380       } else {       } else {
381          Paso_Preconditioner_LocalAMG_solve(amg->A_C, amg->AMG_C,amg->x_C,amg->b_C); /* x_C=AMG(b_C)     */          Paso_Preconditioner_AMG_solve(amg->A_C, amg->AMG_C,amg->x_C,amg->b_C); /* x_C=AMG(b_C)     */
382       }         }  
383       time0=time0+Esys_timer();       time0=time0+Esys_timer();
384       Paso_SparseMatrix_MatrixVector_CSR_OFFSET0_DIAG(1.,amg->P,amg->x_C,1.,x); /* x = x + P*x_c */           Paso_SystemMatrix_MatrixVector_CSR_OFFSET0(1.,amg->P,amg->x_C,1.,x); /* x = x + P*x_c */    
385            
386           /*postsmoothing*/           /*postsmoothing*/
387                
388          /*solve Ax=b with initial guess x */          /*solve Ax=b with initial guess x */
389          time0=Esys_timer();          time0=Esys_timer();
390          Paso_Preconditioner_LocalSmoother_solve(A, amg->Smoother, x, b, post_sweeps, TRUE);          Paso_Preconditioner_Smoother_solve(A, amg->Smoother, x, b, post_sweeps, TRUE);
391          time0=Esys_timer()-time0;          time0=Esys_timer()-time0;
392          if (SHOW_TIMING) printf("timing: level %d: Postsmoothing: %e\n",amg->level,time0);          if (SHOW_TIMING) printf("timing: level %d: Postsmoothing: %e\n",amg->level,time0);
393          /*end of postsmoothing*/          /*end of postsmoothing*/
# Line 315  void Paso_Preconditioner_LocalAMG_solve( Line 404  void Paso_Preconditioner_LocalAMG_solve(
404  in the sense that |A_{ij}| >= theta * max_k |A_{ik}|  in the sense that |A_{ij}| >= theta * max_k |A_{ik}|
405  */  */
406    
407  void Paso_Preconditioner_AMG_setStrongConnections(Paso_SparseMatrix* A,  void Paso_Preconditioner_AMG_setStrongConnections(Paso_SystemMatrix* A,
408                        dim_t *degree, index_t *S,                            dim_t *degree_S, index_t *offset_S, index_t *S,
409                        const double theta, const double tau)                        const double theta, const double tau)
410  {  {
411     const dim_t n=A->numRows;     const dim_t my_n=Paso_SystemMatrix_getNumRows(A);
412     index_t iptr, i,j;     index_t iptr, i;
    dim_t kdeg;  
    double max_offdiagonal, threshold, sum_row, main_row, fnorm;  
413    
414    
415        #pragma omp parallel for private(i,iptr,max_offdiagonal, threshold,j, kdeg, sum_row, main_row, fnorm) schedule(static)        #pragma omp parallel for private(i,iptr) schedule(static)
416        for (i=0;i<n;++i) {        for (i=0;i<my_n;++i) {        
417                   register double max_offdiagonal = 0.;
418       max_offdiagonal = 0.;       register double sum_row=0;
419       sum_row=0;       register double main_row=0;
      main_row=0;  
420       #pragma ivdep       #pragma ivdep
421       for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {       for (iptr=A->mainBlock->pattern->ptr[i];iptr<A->mainBlock->pattern->ptr[i+1]; ++iptr) {
422          j=A->pattern->index[iptr];          register index_t j=A->mainBlock->pattern->index[iptr];
423          fnorm=ABS(A->val[iptr]);          register double fnorm=ABS(A->mainBlock->val[iptr]);
424                    
425          if( j != i) {          if( j != i) {
426             max_offdiagonal = MAX(max_offdiagonal,fnorm);             max_offdiagonal = MAX(max_offdiagonal,fnorm);
# Line 342  void Paso_Preconditioner_AMG_setStrongCo Line 428  void Paso_Preconditioner_AMG_setStrongCo
428          } else {          } else {
429             main_row=fnorm;             main_row=fnorm;
430          }          }
431    
432         }
433         #pragma ivdep
434         for (iptr=A->col_coupleBlock->pattern->ptr[i];iptr<A->col_coupleBlock->pattern->ptr[i+1]; ++iptr) {
435            register index_t j=A->col_coupleBlock->pattern->index[iptr];
436            register double fnorm=ABS(A->col_coupleBlock->val[iptr]);
437            max_offdiagonal = MAX(max_offdiagonal,fnorm);
438            sum_row+=fnorm;
439       }       }
440       threshold = theta*max_offdiagonal;  
441       kdeg=0;  
442         const double threshold = theta*max_offdiagonal;
443         register dim_t kdeg=0;
444             register index_t koffset=A->mainBlock->pattern->ptr[i]+A->col_coupleBlock->pattern->ptr[i];
445       if (tau*main_row < sum_row) { /* no diagonal domainance */       if (tau*main_row < sum_row) { /* no diagonal domainance */
446          #pragma ivdep          #pragma ivdep
447          for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {          for (iptr=A->mainBlock->pattern->ptr[i];iptr<A->mainBlock->pattern->ptr[i+1]; ++iptr) {
448             j=A->pattern->index[iptr];             register index_t j=A->mainBlock->pattern->index[iptr];
449             if(ABS(A->val[iptr])>threshold && i!=j) {             if(ABS(A->mainBlock->val[iptr])>threshold && i!=j) {
450            S[A->pattern->ptr[i]+kdeg] = j;            S[koffset+kdeg] = j;
451            kdeg++;            kdeg++;
452             }             }
453          }          }
454       }          #pragma ivdep
455       degree[i]=kdeg;          for (iptr=A->col_coupleBlock->pattern->ptr[i];iptr<A->col_coupleBlock->pattern->ptr[i+1]; ++iptr) {
456               register index_t j=A->col_coupleBlock->pattern->index[iptr];
457               if(ABS(A->col_coupleBlock->val[iptr])>threshold) {
458              S[koffset+kdeg] = j + my_n;
459              kdeg++;
460               }
461            }
462             }
463             offset_S[i]=koffset;
464         degree_S[i]=kdeg;
465        }        }
   
466  }  }
467    
468  /* theta = threshold for strong connections */  /* theta = threshold for strong connections */
# Line 366  void Paso_Preconditioner_AMG_setStrongCo Line 471  void Paso_Preconditioner_AMG_setStrongCo
471    
472  in the sense that |A_{ij}|_F >= theta * max_k |A_{ik}|_F  in the sense that |A_{ij}|_F >= theta * max_k |A_{ik}|_F
473  */  */
474  void Paso_Preconditioner_AMG_setStrongConnections_Block(Paso_SparseMatrix* A,  void Paso_Preconditioner_AMG_setStrongConnections_Block(Paso_SystemMatrix* A,
475                              dim_t *degree, index_t *S,                              dim_t *degree_S, index_t *offset_S, index_t *S,
476                              const double theta, const double tau)                              const double theta, const double tau)
477    
478  {  {
479       const dim_t my_n=Paso_SystemMatrix_getNumRows(A);
480       index_t iptr, i, bi;
481     const dim_t n_block=A->row_block_size;     const dim_t n_block=A->row_block_size;
    const dim_t n=A->numRows;  
    index_t iptr, i,j, bi;  
    dim_t kdeg, max_deg;  
    register double max_offdiagonal, threshold, fnorm, sum_row, main_row;  
    double *rtmp;  
482        
483        
484        #pragma omp parallel private(i,iptr,max_offdiagonal, kdeg, threshold,j, max_deg, fnorm, sum_row, main_row, rtmp)        #pragma omp parallel private(i,iptr, bi)
485        {        {
486       max_deg=0;       dim_t max_deg=0;
487       #pragma omp for schedule(static)       #pragma omp for schedule(static)
488       for (i=0;i<n;++i) max_deg=MAX(max_deg, A->pattern->ptr[i+1]-A->pattern->ptr[i]);       for (i=0;i<my_n;++i) max_deg=MAX(max_deg, A->mainBlock->pattern->ptr[i+1]-A->mainBlock->pattern->ptr[i]
489                                                    +A->col_coupleBlock->pattern->ptr[i+1]-A->col_coupleBlock->pattern->ptr[i]);
490                
491       rtmp=TMPMEMALLOC(max_deg, double);       double *rtmp=TMPMEMALLOC(max_deg, double);
492                
493       #pragma omp for schedule(static)       #pragma omp for schedule(static)
494       for (i=0;i<n;++i) {       for (i=0;i<my_n;++i) {
495            
496          max_offdiagonal = 0.;          register double max_offdiagonal = 0.;
497          sum_row=0;          register double sum_row=0;
498          main_row=0;          register double main_row=0;
499          for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {              register index_t rtmp_offset=-A->mainBlock->pattern->ptr[i];
500             j=A->pattern->index[iptr];  
501             fnorm=0;          for (iptr=A->mainBlock->pattern->ptr[i];iptr<A->mainBlock->pattern->ptr[i+1]; ++iptr) {
502               register index_t j=A->mainBlock->pattern->index[iptr];
503               register double fnorm=0;
504             #pragma ivdep             #pragma ivdep
505             for(bi=0;bi<n_block*n_block;++bi) fnorm+=A->val[iptr*n_block*n_block+bi]*A->val[iptr*n_block*n_block+bi];             for(bi=0;bi<n_block*n_block;++bi) {
506                         register double rtmp2 = A->mainBlock->val[iptr*n_block*n_block+bi];
507                         fnorm+=rtmp2*rtmp2;
508                   }
509             fnorm=sqrt(fnorm);             fnorm=sqrt(fnorm);
510             rtmp[iptr-A->pattern->ptr[i]]=fnorm;  
511               rtmp[iptr+rtmp_offset]=fnorm;
512             if( j != i) {             if( j != i) {
513            max_offdiagonal = MAX(max_offdiagonal,fnorm);            max_offdiagonal = MAX(max_offdiagonal,fnorm);
514            sum_row+=fnorm;            sum_row+=fnorm;
# Line 407  void Paso_Preconditioner_AMG_setStrongCo Line 516  void Paso_Preconditioner_AMG_setStrongCo
516            main_row=fnorm;            main_row=fnorm;
517             }             }
518          }          }
519          threshold = theta*max_offdiagonal;              rtmp_offset=A->mainBlock->pattern->ptr[i+1]-A->mainBlock->pattern->ptr[i]-A->col_coupleBlock->pattern->ptr[i];
520                  for (iptr=A->col_coupleBlock->pattern->ptr[i];iptr<A->col_coupleBlock->pattern->ptr[i+1]; ++iptr) {
521          kdeg=0;             register index_t j=A->col_coupleBlock->pattern->index[iptr];
522               register double fnorm=0;
523               #pragma ivdep
524               for(bi=0;bi<n_block*n_block;++bi) {
525                         register double rtmp2 = A->col_coupleBlock->val[iptr*n_block*n_block+bi];
526                         fnorm+=rtmp2*rtmp2;
527                   }
528               fnorm=sqrt(fnorm);
529    
530               rtmp[iptr+rtmp_offset]=fnorm;
531               max_offdiagonal = MAX(max_offdiagonal,fnorm);
532               sum_row+=fnorm;
533            }
534                
535            const double threshold = theta*max_offdiagonal;
536            register dim_t kdeg=0;
537                register index_t koffset=A->mainBlock->pattern->ptr[i]+A->col_coupleBlock->pattern->ptr[i];
538    
539          if (tau*main_row < sum_row) { /* no diagonal domainance */          if (tau*main_row < sum_row) { /* no diagonal domainance */
540                   rtmp_offset=-A->mainBlock->pattern->ptr[i];
541             #pragma ivdep             #pragma ivdep
542             for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {             for (iptr=A->mainBlock->pattern->ptr[i];iptr<A->mainBlock->pattern->ptr[i+1]; ++iptr) {
543            j=A->pattern->index[iptr];            register index_t j=A->mainBlock->pattern->index[iptr];
544            if(rtmp[iptr-A->pattern->ptr[i]] > threshold && i!=j) {            if(rtmp[iptr+rtmp_offset] > threshold && i!=j) {
545               S[A->pattern->ptr[i]+kdeg] = j;               S[koffset+kdeg] = j;
546               kdeg++;               kdeg++;
547            }            }
548             }             }
549                   rtmp_offset=A->mainBlock->pattern->ptr[i+1]-A->mainBlock->pattern->ptr[i]-A->col_coupleBlock->pattern->ptr[i];
550               #pragma ivdep
551               for (iptr=A->col_coupleBlock->pattern->index[iptr]; iptr<A->col_coupleBlock->pattern->ptr[i+1]; ++iptr) {
552              register index_t j=A->col_coupleBlock->pattern->index[iptr];
553              if(rtmp[iptr+rtmp_offset] > threshold) {
554                 S[koffset+kdeg] = j + my_n;
555                 kdeg++;
556              }
557               }
558                  
559          }          }
560          degree[i]=kdeg;          degree_S[i]=kdeg;
561                offset_S[i]=koffset;
562       }             }      
563       TMPMEMFREE(rtmp);       TMPMEMFREE(rtmp);
564        } /* end of parallel region */        } /* end of parallel region */
565    
566  }    }  
567    
568    #ifdef AAAAA
569  /* the runge stueben coarsening algorithm: */  /* the runge stueben coarsening algorithm: */
570  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_S,
571                          const dim_t* degree, const index_t* S,                          const dim_t* degree_S, const index_t* S,
572                          index_t*split_marker, const bool_t usePanel)                          index_t*split_marker, const bool_t usePanel)
573  {  {
574        
575     index_t *lambda=NULL, *ST=NULL, *notInPanel=NULL, *panel=NULL, lambda_max, lambda_k;     index_t *lambda=NULL, *ST=NULL, *notInPanel=NULL, *panel=NULL, lambda_max, lambda_k;
576     dim_t i,k, p, q, *degreeT=NULL, len_panel, len_panel_new;     dim_t i,k, p, q, *degree_ST=NULL, len_panel, len_panel_new;
577     register index_t j, itmp;     register index_t j, itmp;
578        
579     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 */
580        
581     lambda=TMPMEMALLOC(n, index_t); Esys_checkPtr(lambda);     lambda=TMPMEMALLOC(n, index_t); Esys_checkPtr(lambda);
582     degreeT=TMPMEMALLOC(n, dim_t); Esys_checkPtr(degreeT);     degree_ST=TMPMEMALLOC(n, dim_t); Esys_checkPtr(degree_ST);
583     ST=TMPMEMALLOC(offset[n], index_t);  Esys_checkPtr(ST);     ST=TMPMEMALLOC(offset_S[n], index_t);  Esys_checkPtr(ST);
584     if (usePanel) {     if (usePanel) {
585        notInPanel=TMPMEMALLOC(n, bool_t); Esys_checkPtr(notInPanel);        notInPanel=TMPMEMALLOC(n, bool_t); Esys_checkPtr(notInPanel);
586        panel=TMPMEMALLOC(n, index_t); Esys_checkPtr(panel);        panel=TMPMEMALLOC(n, index_t); Esys_checkPtr(panel);
# Line 454  void Paso_Preconditioner_AMG_RungeStuebe Line 593  void Paso_Preconditioner_AMG_RungeStuebe
593        /* 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 */
594        #pragma omp parallel for private(i) schedule(static)        #pragma omp parallel for private(i) schedule(static)
595        for (i=0;i<n;++i) {        for (i=0;i<n;++i) {
596       degreeT[i]=0;       degree_ST[i]=0;
597       if (degree[i]>0) {       if (degree_S[i]>0) {
598          lambda[i]=0;          lambda[i]=0;
599          split_marker[i]=PASO_AMG_UNDECIDED;          split_marker[i]=PASO_AMG_UNDECIDED;
600       } else {       } else {
# Line 465  void Paso_Preconditioner_AMG_RungeStuebe Line 604  void Paso_Preconditioner_AMG_RungeStuebe
604        }        }
605        /* create transpose :*/        /* create transpose :*/
606        for (i=0;i<n;++i) {        for (i=0;i<n;++i) {
607          for (p=0; p<degree[i]; ++p) {          for (p=0; p<degree_S[i]; ++p) {
608             j=S[offset[i]+p];             j=S[offset_S[i]+p];
609             ST[offset[j]+degreeT[j]]=i;             ST[offset_S[j]+degree_ST[j]]=i;
610             degreeT[j]++;             degree_ST[j]++;
611          }          }
612        }        }
613        /* lambda[i] = |undecided k in ST[i]| + 2 * |F-unknown in ST[i]| */        /* lambda[i] = |undecided k in ST[i]| + 2 * |F-unknown in ST[i]| */
# Line 476  void Paso_Preconditioner_AMG_RungeStuebe Line 615  void Paso_Preconditioner_AMG_RungeStuebe
615        for (i=0;i<n;++i) {        for (i=0;i<n;++i) {
616       if (split_marker[i]==PASO_AMG_UNDECIDED) {       if (split_marker[i]==PASO_AMG_UNDECIDED) {
617          itmp=lambda[i];          itmp=lambda[i];
618          for (p=0; p<degreeT[i]; ++p) {          for (p=0; p<degree_ST[i]; ++p) {
619             j=ST[offset[i]+p];             j=ST[offset_S[i]+p];
620             if (split_marker[j]==PASO_AMG_UNDECIDED) {             if (split_marker[j]==PASO_AMG_UNDECIDED) {
621            itmp++;            itmp++;
622             } else {  /* at this point there are no C points */             } else {  /* at this point there are no C points */
# Line 503  void Paso_Preconditioner_AMG_RungeStuebe Line 642  void Paso_Preconditioner_AMG_RungeStuebe
642             lambda[i]=-1;  /* lambda from unavailable unknowns is set to -1 */             lambda[i]=-1;  /* lambda from unavailable unknowns is set to -1 */
643                        
644             /* all undecided unknown strongly coupled to i are moved to F */             /* all undecided unknown strongly coupled to i are moved to F */
645             for (p=0; p<degreeT[i]; ++p) {             for (p=0; p<degree_ST[i]; ++p) {
646            j=ST[offset[i]+p];            j=ST[offset_S[i]+p];
647                        
648            if (split_marker[j]==PASO_AMG_UNDECIDED) {            if (split_marker[j]==PASO_AMG_UNDECIDED) {
649                            
650               split_marker[j]=PASO_AMG_IN_F;               split_marker[j]=PASO_AMG_IN_F;
651               lambda[j]=-1;               lambda[j]=-1;
652                            
653               for (q=0; q<degreeT[j]; ++q) {               for (q=0; q<degree_ST[j]; ++q) {
654              k=ST[offset[j]+q];              k=ST[offset_S[j]+q];
655              if (split_marker[k]==PASO_AMG_UNDECIDED) {              if (split_marker[k]==PASO_AMG_UNDECIDED) {
656                 lambda[k]++;                 lambda[k]++;
657                 if (notInPanel[k]) {                 if (notInPanel[k]) {
# Line 528  void Paso_Preconditioner_AMG_RungeStuebe Line 667  void Paso_Preconditioner_AMG_RungeStuebe
667                            
668            }            }
669             }             }
670             for (p=0; p<degree[i]; ++p) {             for (p=0; p<degree_S[i]; ++p) {
671            j=S[offset[i]+p];            j=S[offset_S[i]+p];
672            if (split_marker[j]==PASO_AMG_UNDECIDED) {            if (split_marker[j]==PASO_AMG_UNDECIDED) {
673               lambda[j]--;               lambda[j]--;
674               if (notInPanel[j]) {               if (notInPanel[j]) {
# Line 568  void Paso_Preconditioner_AMG_RungeStuebe Line 707  void Paso_Preconditioner_AMG_RungeStuebe
707          lambda[i]=-1;  /* lambda from unavailable unknowns is set to -1 */          lambda[i]=-1;  /* lambda from unavailable unknowns is set to -1 */
708                    
709          /* all undecided unknown strongly coupled to i are moved to F */          /* all undecided unknown strongly coupled to i are moved to F */
710          for (p=0; p<degreeT[i]; ++p) {          for (p=0; p<degree_ST[i]; ++p) {
711             j=ST[offset[i]+p];             j=ST[offset_S[i]+p];
712             if (split_marker[j]==PASO_AMG_UNDECIDED) {             if (split_marker[j]==PASO_AMG_UNDECIDED) {
713                    
714            split_marker[j]=PASO_AMG_IN_F;            split_marker[j]=PASO_AMG_IN_F;
715            lambda[j]=-1;            lambda[j]=-1;
716                    
717            for (q=0; q<degreeT[j]; ++q) {            for (q=0; q<degree_ST[j]; ++q) {
718               k=ST[offset[j]+q];               k=ST[offset_S[j]+q];
719               if (split_marker[k]==PASO_AMG_UNDECIDED) lambda[k]++;               if (split_marker[k]==PASO_AMG_UNDECIDED) lambda[k]++;
720            }            }
721    
722             }             }
723          }          }
724          for (p=0; p<degree[i]; ++p) {          for (p=0; p<degree_S[i]; ++p) {
725             j=S[offset[i]+p];             j=S[offset_S[i]+p];
726             if(split_marker[j]==PASO_AMG_UNDECIDED) lambda[j]--;             if(split_marker[j]==PASO_AMG_UNDECIDED) lambda[j]--;
727          }          }
728                    
729       }       }
730       i=Paso_Util_arg_max(n,lambda);       i=Paso_Util_arg_max(n,lambda);
731        }        }
732              
733     }     }
734     TMPMEMFREE(lambda);     TMPMEMFREE(lambda);
735     TMPMEMFREE(ST);     TMPMEMFREE(ST);
736     TMPMEMFREE(degreeT);     TMPMEMFREE(degree_ST);
737     TMPMEMFREE(panel);     TMPMEMFREE(panel);
738     TMPMEMFREE(notInPanel);     TMPMEMFREE(notInPanel);
739  }  }
740    /* ensures that two F nodes are connected via a C node :*/
741    void Paso_Preconditioner_AMG_enforceFFConnectivity(const dim_t n, const index_t* offset_S,
742                            const dim_t* degree_S, const index_t* S,
743                            index_t*split_marker)
744    {
745          dim_t i, p, q;
746    
747          /* now we make sure that two (strongly) connected F nodes are (strongly) connected via a C node. */
748          for (i=0;i<n;++i) {
749                if ( (split_marker[i]==PASO_AMG_IN_F) && (degree_S[i]>0) ) {
750               for (p=0; p<degree_S[i]; ++p) {
751                      register index_t j=S[offset_S[i]+p];
752                      if ( (split_marker[j]==PASO_AMG_IN_F)  && (degree_S[j]>0) )  {
753                          /* i and j are now two F nodes which are strongly connected */
754                          /* is there a C node they share ? */
755                          register index_t sharing=-1;
756                      for (q=0; q<degree_S[i]; ++q) {
757                             index_t k=S[offset_S[i]+q];
758                             if (split_marker[k]==PASO_AMG_IN_C) {
759                                register index_t* where_k=(index_t*)bsearch(&k, &(S[offset_S[j]]), degree_S[j], sizeof(index_t), Paso_comparIndex);
760                                if (where_k != NULL) {
761                                   sharing=k;
762                                   break;
763                                }
764                             }
765                          }
766                          if (sharing<0) {
767                               if (i<j) {
768                                  split_marker[j]=PASO_AMG_IN_C;
769                               } else {
770                                  split_marker[i]=PASO_AMG_IN_C;
771                                  break;  /* no point to look any further as i is now a C node */
772                               }
773                          }
774                      }
775                   }
776                }
777           }
778    }
779    #endif
780    
781    #ifdef DFG
782    void Paso_Preconditioner_AMG_CIJPCoarsening( )
783    {
784    
785      
786      const dim_t my_n;
787      const dim_t overlap_n;
788      const dim_t n= my_n + overlap_n;
789       /* set local lambda + overlap */
790       #pragma omp parallel for private(i)
791       for (i=0; i<n ++i) {
792           w[i]=degree_ST[i];
793       }
794       for (i=0; i<my_n; i++) {
795          w2[i]=random;
796       }
797    
798    
799       /* add noise to w */
800       Paso_Coupler_add(n, w, 1., w2, col_coupler);
801    
802       /*  */
803       global_n_C=0;
804       global_n_F=..;
805      
806       while (global_n_C + global_n_F < global_n) {
807    
808          
809          is_in_D[i]=FALSE;
810          /*  test  local connectivit*/
811          /* w2[i] = max(w[k] | k in S_i or k in S^T_i */
812          #pragma omp parallel for private(i)
813          for (i=0; i<n; ++i) w2[i]=0;
814                
815          for (i=0; i<my_n; ++i) {
816             for( iPtr =0 ; iPtr < degree_S[i]; ++iPtr) {
817                 k=S[offset_S[i]+iPtr];
818                 w2[i]=MAX(w2[i],w[k]);
819                 w2[k]=MAX(w2[k],w[i]);
820             }
821          }
822          /* adjust overlaps by MAX */
823          Paso_Coupler_max(n, w2, col_coupler);
824    
825          /* points with w[i]>w2[i] become C nodes */
826       }
827      
828    }
829    #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26