/[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 616 - (show annotations)
Wed Mar 22 02:46:56 2006 UTC (13 years, 7 months ago) by elspeth
File MIME type: text/plain
File size: 6022 byte(s)
Copyright added to more source files.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26