/[escript]/trunk/dudley/src/ElementFile_createColoring.c
ViewVC logotype

Diff of /trunk/dudley/src/ElementFile_createColoring.c

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

trunk/finley/src/ElementFile_createColoring.c revision 1388 by trankine, Fri Jan 11 07:45:58 2008 UTC trunk/dudley/src/ElementFile_createColoring.c revision 3259 by jfenwick, Mon Oct 11 01:48:14 2010 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2010 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14  /**************************************************************/  /**************************************************************/
15  /*                                                                                                         */  /*                                                                                                         */
16  /*   Finley: ElementFile                                                                                   */  /*   Dudley: ElementFile                                                                                   */
17  /*                                                                                                         */  /*                                                                                                         */
18  /*   This routine tries to reduce the number of colors used to color elements in the Finley_ElementFile in */  /*   This routine tries to reduce the number of colors used to color elements in the Dudley_ElementFile in */
19  /*                                                                                                         */  /*                                                                                                         */
20  /**************************************************************/  /**************************************************************/
21    
# Line 26  Line 24 
24    
25  /**************************************************************/  /**************************************************************/
26    
27  void Finley_ElementFile_createColoring(Finley_ElementFile* in,dim_t numNodes, index_t* degreeOfFreedom) {  void Dudley_ElementFile_createColoring(Dudley_ElementFile * in, dim_t numNodes, index_t * degreeOfFreedom)
28      dim_t e,i,numUncoloredElements,n,len,NN;  {
29      index_t *maskDOF,color,min_id,max_id;      dim_t e, i, numUncoloredElements, n, len, NN;
30        index_t *maskDOF, min_id, max_id;
31      bool_t independent;      bool_t independent;
32    
33      if (in==NULL) return;      if (in == NULL)
34      if (in->numElements<1) return;      return;
35      NN=in->numNodes;      if (in->numElements < 1)
36        return;
37      min_id=Finley_Util_getMinInt(1,numNodes,degreeOfFreedom);      NN = in->numNodes;
38      max_id=Finley_Util_getMaxInt(1,numNodes,degreeOfFreedom);  
39      len=max_id-min_id+1;      min_id = Dudley_Util_getMinInt(1, numNodes, degreeOfFreedom);
40      maskDOF=TMPMEMALLOC(len,index_t);      max_id = Dudley_Util_getMaxInt(1, numNodes, degreeOfFreedom);
41      if (! Finley_checkPtr(maskDOF) ) {      len = max_id - min_id + 1;
42           #pragma omp parallel for private(e) schedule(static)      maskDOF = TMPMEMALLOC(len, index_t);
43           for (e=0;e<in->numElements;e++) in->Color[e]=-1;      if (!Dudley_checkPtr(maskDOF))
44           numUncoloredElements=in->numElements;      {
45           in->minColor=0;  #pragma omp parallel for private(e) schedule(static)
46           in->maxColor=in->minColor-1;      for (e = 0; e < in->numElements; e++)
47           while (numUncoloredElements>0) {          in->Color[e] = -1;
48              /* initialize the mask marking nodes used by a color */      numUncoloredElements = in->numElements;
49              #pragma omp parallel for private(n) schedule(static)      in->minColor = 0;
50              for (n=0;n<len;n++) maskDOF[n]=-1;      in->maxColor = in->minColor - 1;
51              numUncoloredElements=0;      while (numUncoloredElements > 0)
52              /* OMP ?*/      {
53              for (e=0;e<in->numElements;e++) {          /* initialize the mask marking nodes used by a color */
54                    if (in->Color[e]<0) {  #pragma omp parallel for private(n) schedule(static)
55                       /* find out if element e is independend from the elements already colored: */          for (n = 0; n < len; n++)
56                       independent=TRUE;          maskDOF[n] = -1;
57                       for (i=0;i<NN;i++) {          numUncoloredElements = 0;
58            /* OMP ? */
59            for (e = 0; e < in->numElements; e++)
60            {
61            if (in->Color[e] < 0)
62            {
63                /* find out if element e is independend from the elements already colored: */
64                independent = TRUE;
65                for (i = 0; i < NN; i++)
66                {
67  #ifdef BOUNDS_CHECK  #ifdef BOUNDS_CHECK
68  if (in->Nodes[INDEX2(i,e,NN)] < 0 || in->Nodes[INDEX2(i,e,NN)] >= numNodes) { printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d in->Nodes[INDEX2...]=%d\n", __FILE__, __LINE__, i, e, NN, min_id, in->Nodes[INDEX2(i,e,NN)]); exit(1); }              if (in->Nodes[INDEX2(i, e, NN)] < 0 || in->Nodes[INDEX2(i, e, NN)] >= numNodes)
69  if ((degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id) >= len || (degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id) < 0) { printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d dof=%d\n", __FILE__, __LINE__, i, e, NN, min_id, degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id); exit(1); }              {
70                    printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d in->Nodes[INDEX2...]=%d\n", __FILE__,
71                       __LINE__, i, e, NN, min_id, in->Nodes[INDEX2(i, e, NN)]);
72                    exit(1);
73                }
74                if ((degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id) >= len
75                    || (degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id) < 0)
76                {
77                    printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d dof=%d\n", __FILE__, __LINE__, i, e,
78                       NN, min_id, degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id);
79                    exit(1);
80                }
81  #endif  #endif
82                  if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]>0) {              if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id] > 0)
83                               independent=FALSE;              {
84                               break;                  independent = FALSE;
85                          }                  break;
86               }              }
87                       /* if e is independend a new color is assigned and the nodes are marked as being used */              }
88                       if (independent) {              /* if e is independend a new color is assigned and the nodes are marked as being used */
89                             for (i=0;i<NN;i++) maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]=1;              if (independent)
90                             in->Color[e]=in->maxColor+1;              {
91                       } else {              for (i = 0; i < NN; i++)
92                               numUncoloredElements++;                  maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id] = 1;
93                       }              in->Color[e] = in->maxColor + 1;
94                    }              }
95                else
96              }              {
97              in->maxColor++;              numUncoloredElements++;
98           }  /* end of while loop */              }
99            }
100    
101            }
102            in->maxColor++;
103        }           /* end of while loop */
104      }      }
105      /* all done : */      /* all done : */
106      TMPMEMFREE(maskDOF);      TMPMEMFREE(maskDOF);

Legend:
Removed from v.1388  
changed lines
  Added in v.3259

  ViewVC Help
Powered by ViewVC 1.1.26