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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1326 - (show annotations)
Mon Oct 1 08:10:41 2007 UTC (12 years, 6 months ago) by ksteube
File MIME type: text/plain
File size: 3459 byte(s)
Implemented domain.print_mesh_info() so we can see the distribution of elements & nodes.
Implemented -DBOUNDS_CHECK to catch an error with periodicN=True.

1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 /**************************************************************/
17 /* */
18 /* Finley: ElementFile */
19 /* */
20 /* This routine tries to reduce the number of colors used to color elements in the Finley_ElementFile in */
21 /* */
22 /**************************************************************/
23
24 #include "ElementFile.h"
25 #include "Util.h"
26
27 /**************************************************************/
28
29 void Finley_ElementFile_createColoring(Finley_ElementFile* in,dim_t numNodes, index_t* degreeOfFreedom) {
30 dim_t e,i,numUncoloredElements,n,len,NN;
31 index_t *maskDOF,color,min_id,max_id;
32 bool_t independent;
33
34 if (in==NULL) return;
35 if (in->numElements<1) return;
36 NN=in->numNodes;
37
38 min_id=Finley_Util_getMinInt(1,numNodes,degreeOfFreedom);
39 max_id=Finley_Util_getMaxInt(1,numNodes,degreeOfFreedom);
40 len=max_id-min_id+1;
41 maskDOF=TMPMEMALLOC(len,index_t);
42 if (! Finley_checkPtr(maskDOF) ) {
43 #pragma omp parallel for private(e) schedule(static)
44 for (e=0;e<in->numElements;e++) in->Color[e]=-1;
45 numUncoloredElements=in->numElements;
46 while (numUncoloredElements>0) {
47 /* initialize the mask marking nodes used by a color */
48 #pragma omp parallel for private(n) schedule(static)
49 for (n=0;n<len;n++) maskDOF[n]=-1;
50 numUncoloredElements=0;
51 /* OMP ?*/
52 for (e=0;e<in->numElements;e++) {
53 if (in->Color[e]<0) {
54 /* find out if element e is independend from the elements already colored: */
55 independent=TRUE;
56 for (i=0;i<NN;i++) {
57 #ifdef BOUNDS_CHECK
58 if ((degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id) >= len || (degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id) < 0) { printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d dof=%d\n", __FILE__, __LINE__, i, e, NN, min_id, degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id); exit(1); }
59 #endif
60 if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]>0) independent=FALSE;
61 }
62 /* if e is independend a new color is assigned and the nodes are marked as being used */
63 if (independent) {
64 for (i=0;i<NN;i++) maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]=1;
65 in->Color[e]=in->maxColor+1;
66 } else {
67 numUncoloredElements++;
68 }
69 }
70 }
71 in->maxColor++;
72 } /* end of while loop */
73 }
74 /* all done : */
75 TMPMEMFREE(maskDOF);
76 }

  ViewVC Help
Powered by ViewVC 1.1.26