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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 201 - (show annotations)
Wed Nov 23 04:10:21 2005 UTC (13 years, 10 months ago) by jgs
File MIME type: text/plain
File size: 6344 byte(s)
copy finleyC and CPPAdapter to finley and finley/CPPAdapter to
facilitate scons builds

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26