Diff of /trunk/esys2/finley/src/finleyC/Solvers/Solver_coloring.c

revision 96 by jgs, Tue Oct 26 06:53:54 2004 UTC revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC
# Line 2  Line 2
2
3  /**********************************************************************/  /**********************************************************************/
4
5  /* Finley: Solver: set the pointer of the main diagonal in A_p->value */  /* Finley: Solver: set the pointer of the main diagonal in pattern_p->value */
6
7  /**********************************************************************/  /**********************************************************************/
8
# Line 28  static double Finley_Solver_coloring_see Line 28  static double Finley_Solver_coloring_see
28
29  /* inverse preconditioner setup */  /* inverse preconditioner setup */
30
31  void Finley_Solver_coloring(Finley_SystemMatrix* A_p,maybelong* numColors, maybelong* color) {  void Finley_Solver_coloring(Finley_SystemMatrixPattern* pattern_p,maybelong* numColors, maybelong* color) {
32  #if ITERATIVE_SOLVER == NO_LIB  #if ITERATIVE_SOLVER == NO_LIB
33    int irow,iptr,currentColor,naib;    int i,iptr,currentColor,naib;
34    maybelong n=A_p->num_rows;    maybelong n=pattern_p->n_ptr;
35    double *value=(double*) TMPMEMALLOC(n*sizeof(double));    double *value=TMPMEMALLOC(n,double);
36    if (!Finley_checkPtr(value)) {    if (!Finley_checkPtr(value)) {
37         /* no colors used yet */         /* no colors used yet */
38         currentColor=0;         currentColor=0;
39         /* initialize color */         /* initialize color */
40         #pragma omp parallel for private(irow) schedule(static)         #pragma omp parallel for private(i) schedule(static)
41         for (irow=0;irow<n;irow++) color[irow]=CONNECTED_TO_CURRENT_COLOR;         for (i=0;i<n;i++) color[i]=CONNECTED_TO_CURRENT_COLOR;
42
43         while (Finley_Util_isAny(n,color,CONNECTED_TO_CURRENT_COLOR)) {         while (Finley_Util_isAny(n,color,CONNECTED_TO_CURRENT_COLOR)) {
44            /* all rows which are not colored yet (color[irow]<0) are indicated            /* all rows which are not colored yet (color[i]<0) are indicated
45                 to be free for the next color assigment*/                 to be free for the next color assigment*/
46            #pragma omp parallel for private(irow) schedule(static)            #pragma omp parallel for private(i) schedule(static)
47            for (irow=0;irow<n;irow++) if (color[irow]==CONNECTED_TO_CURRENT_COLOR) color[irow]=MAYBE_COLORED_NOW;            for (i=0;i<n;i++) if (color[i]==CONNECTED_TO_CURRENT_COLOR) color[i]=MAYBE_COLORED_NOW;
48            /* find rows marked with MAYBE_COLORED_NOW which are not connected to the colored rows but could be connected */            /* find rows marked with MAYBE_COLORED_NOW which are not connected to the colored rows but could be connected */
49            /* to CONNECTED_TO_CURRENT_COLOR rows which are the rows connected to colored rows */            /* to CONNECTED_TO_CURRENT_COLOR rows which are the rows connected to colored rows */
50            /* the following while loop finds MAYBE_COLORED_NOW rows which could be linked to CONNECTED_TO_CURRENT_COLOR rows but */            /* the following while loop finds MAYBE_COLORED_NOW rows which could be linked to CONNECTED_TO_CURRENT_COLOR rows but */
# Line 55  void Finley_Solver_coloring(Finley_Syste Line 55  void Finley_Solver_coloring(Finley_Syste
55                  /* assign a random number to all MAYBE_COLORED_NOW or currentColor colored row: */                  /* assign a random number to all MAYBE_COLORED_NOW or currentColor colored row: */
56                  /* non-MAYBE_COLORED_NOW rows get value 2. which is bigger than all other values */                  /* non-MAYBE_COLORED_NOW rows get value 2. which is bigger than all other values */
57                  /* which means that they have no effect when checking for minimum values in the naigbourhood */                  /* which means that they have no effect when checking for minimum values in the naigbourhood */
58                  #pragma omp for private(irow) schedule(static)                  #pragma omp for private(i) schedule(static)
59                  for (irow=0;irow<n;irow++) {                  for (i=0;i<n;i++) {
60                     if (color[irow]==MAYBE_COLORED_NOW) {                     if (color[i]==MAYBE_COLORED_NOW) {
61                         value[irow]=fmod(Finley_Solver_coloring_seed*(irow+1),1.);                         value[i]=fmod(Finley_Solver_coloring_seed*(i+1),1.);
62                     } else {                     } else {
63                         value[irow]=2.;                         value[i]=2.;
64                     }                     }
65                  }                  }
66                  /* update the seed */                  /* update the seed */
# Line 70  void Finley_Solver_coloring(Finley_Syste Line 70  void Finley_Solver_coloring(Finley_Syste
70                  /* the row is independent from the un-colored rows */                  /* the row is independent from the un-colored rows */
71                  /* otherwise the row is connected to another row and the row is marked as NOT_COLORED_NOW */                  /* otherwise the row is connected to another row and the row is marked as NOT_COLORED_NOW */
72                  /* i.e. it may use in the next choice for value if it is not marked as CONNECTED_TO_CURRENT_COLOR */                  /* i.e. it may use in the next choice for value if it is not marked as CONNECTED_TO_CURRENT_COLOR */
73                  #pragma omp for private(naib,irow,iptr) schedule(static)                  #pragma omp for private(naib,i,iptr) schedule(static)
74                  for (irow=0;irow<n;irow++) {                  for (i=0;i<n;i++) {
75                     if (color[irow]==MAYBE_COLORED_NOW) {                     if (color[i]==MAYBE_COLORED_NOW) {
76                       for (iptr=A_p->ptr[irow];iptr<A_p->ptr[irow+1]; iptr++) {                       for (iptr=pattern_p->ptr[i];iptr<pattern_p->ptr[i+1]; iptr++) {
77                            naib=A_p->index[iptr];                            naib=pattern_p->index[iptr];
78                            if (naib!=irow && value[naib]<=value[irow]) {                            if (naib!=i && value[naib]<=value[i]) {
79                                 color[irow]=NOT_COLORED_NOW;                                 color[i]=NOT_COLORED_NOW;
80                                 break;                                 break;
81                            }                            }
82                       }                       }
# Line 84  void Finley_Solver_coloring(Finley_Syste Line 84  void Finley_Solver_coloring(Finley_Syste
84                  }                  }
85                  /* all naigbours of MAYBE_COLORED_NOW row which are not colored yet are marked as CONNECTED_TO_CURRENT_COLOR */                  /* all naigbours of MAYBE_COLORED_NOW row which are not colored yet are marked as CONNECTED_TO_CURRENT_COLOR */
86                  /* They cannot be used for this coloring round */                  /* They cannot be used for this coloring round */
87                  #pragma omp for private(naib,iptr,irow) schedule(static)                  #pragma omp for private(naib,iptr,i) schedule(static)
88                  for (irow=0;irow<n;irow++) {                  for (i=0;i<n;i++) {
89                     if (color[irow]==MAYBE_COLORED_NOW) {                     if (color[i]==MAYBE_COLORED_NOW) {
90                       for (iptr=A_p->ptr[irow];iptr<A_p->ptr[irow+1]; iptr++) {                       for (iptr=pattern_p->ptr[i];iptr<pattern_p->ptr[i+1]; iptr++) {
91                            naib=A_p->index[iptr];                            naib=pattern_p->index[iptr];
92                            if (naib!=irow && color[naib]<0) color[naib]=CONNECTED_TO_CURRENT_COLOR;                            if (naib!=i && color[naib]<0) color[naib]=CONNECTED_TO_CURRENT_COLOR;
93                       }                       }
94                       color[irow]=currentColor;                       color[i]=currentColor;
95                     } else if (color[irow]==NOT_COLORED_NOW) {                     } else if (color[i]==NOT_COLORED_NOW) {
96                       color[irow]=MAYBE_COLORED_NOW;                       color[i]=MAYBE_COLORED_NOW;
97                     }                     }
98                  }                  }
99              }              }
# Line 116  void Finley_Solver_coloring(Finley_Syste Line 116  void Finley_Solver_coloring(Finley_Syste
116
117  /*  /*
118   * \$Log\$   * \$Log\$
119   * Revision 1.1  2004/10/26 06:53:58  jgs   * Revision 1.2  2004/12/14 05:39:32  jgs
120   * Initial revision   * *** empty log message ***
121     *
122     * Revision 1.1.1.1.2.2  2004/11/24 01:37:17  gross
123     * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now
124     *
125     * Revision 1.1.1.1.2.1  2004/11/12 06:58:21  gross
126     * a lot of changes to get the linearPDE class running: most important change is that there is no matrix format exposed to the user anymore. the format is chosen by the Domain according to the solver and symmetry
127     *
128     * Revision 1.1.1.1  2004/10/26 06:53:58  jgs
129     * initial import of project esys2
130   *   *
131   * Revision 1.1  2004/07/02 04:21:14  gross   * Revision 1.1  2004/07/02 04:21:14  gross
132   * Finley C code has been included   * Finley C code has been included

Legend:
 Removed from v.96 changed lines Added in v.97