/[escript]/trunk-mpi-branch/finley/src/ElementFile_createColoring.c
ViewVC logotype

Contents of /trunk-mpi-branch/finley/src/ElementFile_createColoring.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1224 - (show annotations)
Fri Aug 3 04:15:46 2007 UTC (12 years, 11 months ago) by gross
File MIME type: text/plain
File size: 5195 byte(s)
some renaming to calrify the fact that "distribution" is used for MPI only.


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: ElementFile_createColoring.c 1140 2007-05-15 03:23:17Z ksteube $ */
23
24 /**************************************************************/
25
26 #include "ElementFile.h"
27 #include "Util.h"
28
29 /**************************************************************/
30
31 void Finley_ElementFile_createColoring(Finley_ElementFile* in,dim_t numNodes, index_t* degreeOfFreedom) {
32 dim_t e,i,numUncoloredElements,n,len,NN;
33 index_t *maskDOF,*old_Color,color,min_id,max_id,old_maxColor,old_minColor;
34 bool_t independent;
35 Finley_resetError();
36
37 if (in==NULL) return;
38 NN=in->ReferenceElement->Type->numNodes;
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 }

  ViewVC Help
Powered by ViewVC 1.1.26