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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 123 - (show annotations)
Fri Jul 8 04:08:13 2005 UTC (14 years, 7 months ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/ElementFile_improveColoring.c
File MIME type: text/plain
File size: 4257 byte(s)
Merge of development branch back to main trunk on 2005-07-08

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 #pragma omp parallel private(color)
51 {
52 /* initialize the mask marking nodes used by a color */
53 #pragma omp for private(n) schedule(static)
54 for (n=0;n<len;n++) maskDOF[n]=-1;
55 /* the existing coloring is used to make sure that the new coloring can be done in parallel */
56 #pragma omp master
57 numUncoloredElements=0;
58 for (color=old_minColor;color<=old_maxColor;color++) {
59 #pragma omp for private(i,e,independent) schedule(static) reduction(+:numUncoloredElements)
60 for (e=0;e<in->numElements;e++) {
61 if (old_Color[e]==color) {
62 /* find out if element e is independend from the elements already colored: */
63 independent=TRUE;
64 for (i=0;i<NN;i++) if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]>0) independent=FALSE;
65 /* if e is independend a new color is assigned and the nodes are marked as being used */
66 if (independent) {
67 for (i=0;i<NN;i++) maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]=1;
68 old_Color[e]=-1;
69 in->Color[e]=in->maxColor+1;
70 } else {
71 numUncoloredElements++;
72 }
73 }
74 }
75 } /* end of color loop */
76 }
77 in->maxColor++;
78 } /* end of while loop */
79 }
80
81 /* all done : */
82
83 TMPMEMFREE(maskDOF);
84 TMPMEMFREE(old_Color);
85 }
86 /*
87 * $Log$
88 * Revision 1.5 2005/07/08 04:07:49 jgs
89 * Merge of development branch back to main trunk on 2005-07-08
90 *
91 * Revision 1.4 2004/12/15 07:08:32 jgs
92 * *** empty log message ***
93 * Revision 1.1.1.1.2.2 2005/06/29 02:34:49 gross
94 * some changes towards 64 integers in finley
95 *
96 * Revision 1.1.1.1.2.1 2004/11/24 01:37:13 gross
97 * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now
98 *
99 *
100 *
101 */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26