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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (hide annotations)
Tue Oct 26 06:53:54 2004 UTC (15 years, 4 months ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/ElementFile_improveColoring.c
File MIME type: text/plain
File size: 4038 byte(s)
Initial revision

1 jgs 82 /* $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,maybelong numNodes, maybelong* degreeOfFreedom) {
23     if (in==NULL) return;
24     maybelong NN=in->ReferenceElement->Type->numNodes;
25     maybelong old_numColors,*maskDOF,*old_Color,e,i,numUncoloredElements,n,color,independent;
26     Finley_ErrorCode=NO_ERROR;
27     int min_id,max_id;
28     maybelong len;
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=(maybelong*)TMPMEMALLOC(len*sizeof(maybelong));
36     old_Color=(maybelong*)TMPMEMALLOC(in->numElements*sizeof(maybelong));
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_numColors=in->numColors;
45     in->numColors=0;
46     numUncoloredElements=in->numElements;
47     while (numUncoloredElements>0) {
48     #pragma omp parallel private(color)
49     {
50     /* initialize the mask marking nodes used by a color */
51     #pragma omp 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     #pragma omp master
55     numUncoloredElements=0;
56     for (color=0;color<old_numColors;color++) {
57     #pragma omp 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->numColors;
68     } else {
69     numUncoloredElements++;
70     }
71     }
72     }
73     } /* end of color loop */
74     }
75     in->numColors++;
76     } /* end of while loop */
77     }
78    
79     /* all done : */
80    
81     TMPMEMFREE(maskDOF);
82     TMPMEMFREE(old_Color);
83     }
84     /*
85     * $Log$
86     * Revision 1.1 2004/10/26 06:53:57 jgs
87     * Initial revision
88     *
89     * Revision 1.2 2004/07/02 04:21:13 gross
90     * Finley C code has been included
91     *
92     * Revision 1.1.1.1 2004/06/24 04:00:40 johng
93     * Initial version of eys using boost-python.
94     *
95     *
96     */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26