/[escript]/trunk/esys2/finley/src/finleyC/ElementFile_improveColoring.c
ViewVC logotype

Contents of /trunk/esys2/finley/src/finleyC/ElementFile_improveColoring.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations)
Fri Jul 22 03:53:08 2005 UTC (13 years, 9 months ago) by jgs
File MIME type: text/plain
File size: 5311 byte(s)
Merge of development branch back to main trunk on 2005-07-22

1 /* $Id$ */
2 /**************************************************************/
3 /* */
4 /* Finley: ElementFile */
5 /* */
6 /* This routine tries to reduce the number of colors used to color elements in the Finley_ElementFile in */
7 /* */
8 /**************************************************************/
9
10 /* Copyrights by ACcESS Australia 2003/04 */
11 /* Author: gross@access.edu.au */
12 /* Version: $Id$ */
13
14 /**************************************************************/
15
16 #include "Finley.h"
17 #include "ElementFile.h"
18 #include "Util.h"
19
20 /**************************************************************/
21
22 void Finley_ElementFile_improveColoring(Finley_ElementFile* in,dim_t numNodes, index_t* degreeOfFreedom) {
23 if (in==NULL) return;
24 dim_t NN=in->ReferenceElement->Type->numNodes;
25 dim_t e,i,numUncoloredElements,n,len;
26 index_t *maskDOF,*old_Color,color,min_id,max_id,old_maxColor,old_minColor;
27 bool_t independent;
28 Finley_ErrorCode=NO_ERROR;
29
30 if (in->numElements<1) return;
31
32 min_id=Finley_Util_getMinInt(1,numNodes,degreeOfFreedom);
33 max_id=Finley_Util_getMaxInt(1,numNodes,degreeOfFreedom);
34 len=max_id-min_id+1;
35 maskDOF=TMPMEMALLOC(len,index_t);
36 old_Color=TMPMEMALLOC(in->numElements,index_t);
37
38 if (! (Finley_checkPtr(maskDOF) || Finley_checkPtr(old_Color) ) ) {
39 #pragma omp parallel for private(e) schedule(static)
40 for (e=0;e<in->numElements;e++) {
41 old_Color[e]=in->Color[e];
42 in->Color[e]=-1;
43 }
44 old_maxColor=in->maxColor;
45 old_minColor=in->minColor;
46 in->maxColor=-1;
47 in->minColor=0;
48 numUncoloredElements=in->numElements;
49 while (numUncoloredElements>0) {
50 /* initialize the mask marking nodes used by a color */
51 #pragma omp parallel for private(n) schedule(static)
52 for (n=0;n<len;n++) maskDOF[n]=-1;
53 /* the existing coloring is used to make sure that the new coloring can be done in parallel */
54 numUncoloredElements=0;
55 if ((old_maxColor-old_minColor+1)*NN<in->numElements) {
56 for (color=old_minColor;color<=old_maxColor;color++) {
57 #pragma omp parallel for private(i,e,independent) schedule(static) reduction(+:numUncoloredElements)
58 for (e=0;e<in->numElements;e++) {
59 if (old_Color[e]==color) {
60 /* find out if element e is independend from the elements already colored: */
61 independent=TRUE;
62 for (i=0;i<NN;i++) if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]>0) independent=FALSE;
63 /* if e is independend a new color is assigned and the nodes are marked as being used */
64 if (independent) {
65 for (i=0;i<NN;i++) maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]=1;
66 old_Color[e]=-1;
67 in->Color[e]=in->maxColor+1;
68 } else {
69 numUncoloredElements++;
70 }
71 }
72 }
73 } /* end of color loop */
74 } else {
75 for (e=0;e<in->numElements;e++) {
76 if (old_Color[e]!=-1) {
77 /* find out if element e is independend from the elements already colored: */
78 independent=TRUE;
79 for (i=0;i<NN;i++) if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]>0) independent=FALSE;
80 /* if e is independend a new color is assigned and the nodes are marked as being used */
81 if (independent) {
82 for (i=0;i<NN;i++) maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]=1;
83 old_Color[e]=-1;
84 in->Color[e]=in->maxColor+1;
85 } else {
86 numUncoloredElements++;
87 }
88 }
89 }
90 }
91 in->maxColor++;
92 } /* end of while loop */
93 }
94
95 /* all done : */
96
97 TMPMEMFREE(maskDOF);
98 TMPMEMFREE(old_Color);
99 }
100 /*
101 * $Log$
102 * Revision 1.6 2005/07/22 03:53:07 jgs
103 * Merge of development branch back to main trunk on 2005-07-22
104 *
105 * Revision 1.5 2005/07/08 04:07:49 jgs
106 * Merge of development branch back to main trunk on 2005-07-08
107 *
108 * Revision 1.4 2004/12/15 07:08:32 jgs
109 * *** empty log message ***
110 * Revision 1.1.1.1.2.3 2005/07/18 10:34:54 gross
111 * some informance improvements when reading meshes
112 *
113 * Revision 1.1.1.1.2.2 2005/06/29 02:34:49 gross
114 * some changes towards 64 integers in finley
115 *
116 * Revision 1.1.1.1.2.1 2004/11/24 01:37:13 gross
117 * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now
118 *
119 *
120 *
121 */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26