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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (hide annotations)
Mon Oct 11 01:48:14 2010 UTC (9 years, 4 months ago) by jfenwick
File MIME type: text/plain
File size: 3655 byte(s)
Merging dudley and scons updates from branches

1 ksteube 1315
2     /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 ksteube 1315
14     /**************************************************************/
15     /* */
16 jfenwick 3086 /* Dudley: ElementFile */
17 ksteube 1315 /* */
18 jfenwick 3086 /* This routine tries to reduce the number of colors used to color elements in the Dudley_ElementFile in */
19 ksteube 1315 /* */
20     /**************************************************************/
21    
22     #include "ElementFile.h"
23     #include "Util.h"
24    
25     /**************************************************************/
26    
27 jfenwick 3224 void Dudley_ElementFile_createColoring(Dudley_ElementFile * in, dim_t numNodes, index_t * degreeOfFreedom)
28     {
29     dim_t e, i, numUncoloredElements, n, len, NN;
30     index_t *maskDOF, min_id, max_id;
31 ksteube 1315 bool_t independent;
32    
33 jfenwick 3224 if (in == NULL)
34     return;
35     if (in->numElements < 1)
36     return;
37     NN = in->numNodes;
38 ksteube 1315
39 jfenwick 3224 min_id = Dudley_Util_getMinInt(1, numNodes, degreeOfFreedom);
40     max_id = Dudley_Util_getMaxInt(1, numNodes, degreeOfFreedom);
41     len = max_id - min_id + 1;
42     maskDOF = TMPMEMALLOC(len, index_t);
43     if (!Dudley_checkPtr(maskDOF))
44     {
45     #pragma omp parallel for private(e) schedule(static)
46     for (e = 0; e < in->numElements; e++)
47     in->Color[e] = -1;
48     numUncoloredElements = in->numElements;
49     in->minColor = 0;
50     in->maxColor = in->minColor - 1;
51     while (numUncoloredElements > 0)
52     {
53     /* initialize the mask marking nodes used by a color */
54     #pragma omp parallel for private(n) schedule(static)
55     for (n = 0; n < len; n++)
56     maskDOF[n] = -1;
57     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 ksteube 1326 #ifdef BOUNDS_CHECK
68 jfenwick 3224 if (in->Nodes[INDEX2(i, e, NN)] < 0 || in->Nodes[INDEX2(i, e, NN)] >= numNodes)
69     {
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 ksteube 1326 #endif
82 jfenwick 3224 if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id] > 0)
83     {
84     independent = FALSE;
85     break;
86     }
87     }
88     /* if e is independend a new color is assigned and the nodes are marked as being used */
89     if (independent)
90     {
91     for (i = 0; i < NN; i++)
92     maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id] = 1;
93     in->Color[e] = in->maxColor + 1;
94     }
95     else
96     {
97     numUncoloredElements++;
98     }
99     }
100 gross 1358
101 jfenwick 3224 }
102     in->maxColor++;
103     } /* end of while loop */
104 ksteube 1315 }
105     /* all done : */
106     TMPMEMFREE(maskDOF);
107     }

  ViewVC Help
Powered by ViewVC 1.1.26