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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4286 - (show annotations)
Thu Mar 7 04:28:11 2013 UTC (6 years, 5 months ago) by caltinay
File MIME type: text/plain
File size: 3840 byte(s)
Assorted spelling fixes.

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

  ViewVC Help
Powered by ViewVC 1.1.26