~vcs-imports/escript-finley/trunk

« back to all changes in this revision

Viewing changes to dudley/src/ElementFile_createColoring.c

  • Committer: jfenwick
  • Date: 2010-10-11 01:48:14 UTC
  • Revision ID: svn-v4:77569008-7704-0410-b7a0-a92fef0b09fd:trunk:3259
Merging dudley and scons updates from branches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*******************************************************
 
3
*
 
4
* Copyright (c) 2003-2010 by University of Queensland
 
5
* Earth Systems Science Computational Center (ESSCC)
 
6
* http://www.uq.edu.au/esscc
 
7
*
 
8
* Primary Business: Queensland, Australia
 
9
* Licensed under the Open Software License version 3.0
 
10
* http://www.opensource.org/licenses/osl-3.0.php
 
11
*
 
12
*******************************************************/
 
13
 
 
14
/**************************************************************/
 
15
/*                                                                                                         */
 
16
/*   Dudley: ElementFile                                                                                   */
 
17
/*                                                                                                         */
 
18
/*   This routine tries to reduce the number of colors used to color elements in the Dudley_ElementFile in */
 
19
/*                                                                                                         */
 
20
/**************************************************************/
 
21
 
 
22
#include "ElementFile.h"
 
23
#include "Util.h"
 
24
 
 
25
/**************************************************************/
 
26
 
 
27
void Dudley_ElementFile_createColoring(Dudley_ElementFile * in, dim_t numNodes, index_t * degreeOfFreedom)
 
28
{
 
29
    dim_t e, i, numUncoloredElements, n, len, NN;
 
30
    index_t *maskDOF, min_id, max_id;
 
31
    bool_t independent;
 
32
 
 
33
    if (in == NULL)
 
34
        return;
 
35
    if (in->numElements < 1)
 
36
        return;
 
37
    NN = in->numNodes;
 
38
 
 
39
    min_id = Dudley_Util_getMinInt(1, numNodes, degreeOfFreedom);
 
40
    max_id = Dudley_Util_getMaxInt(1, numNodes, degreeOfFreedom);
 
41
    len = max_id - min_id + 1;
 
42
    maskDOF = TMPMEMALLOC(len, index_t);
 
43
    if (!Dudley_checkPtr(maskDOF))
 
44
    {
 
45
#pragma omp parallel for private(e) schedule(static)
 
46
        for (e = 0; e < in->numElements; e++)
 
47
            in->Color[e] = -1;
 
48
        numUncoloredElements = in->numElements;
 
49
        in->minColor = 0;
 
50
        in->maxColor = in->minColor - 1;
 
51
        while (numUncoloredElements > 0)
 
52
        {
 
53
            /* initialize the mask marking nodes used by a color */
 
54
#pragma omp parallel for private(n) schedule(static)
 
55
            for (n = 0; n < len; n++)
 
56
                maskDOF[n] = -1;
 
57
            numUncoloredElements = 0;
 
58
            /* OMP ? */
 
59
            for (e = 0; e < in->numElements; e++)
 
60
            {
 
61
                if (in->Color[e] < 0)
 
62
                {
 
63
                    /* find out if element e is independend from the elements already colored: */
 
64
                    independent = TRUE;
 
65
                    for (i = 0; i < NN; i++)
 
66
                    {
 
67
#ifdef BOUNDS_CHECK
 
68
                        if (in->Nodes[INDEX2(i, e, NN)] < 0 || in->Nodes[INDEX2(i, e, NN)] >= numNodes)
 
69
                        {
 
70
                            printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d in->Nodes[INDEX2...]=%d\n", __FILE__,
 
71
                                   __LINE__, i, e, NN, min_id, in->Nodes[INDEX2(i, e, NN)]);
 
72
                            exit(1);
 
73
                        }
 
74
                        if ((degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id) >= len
 
75
                            || (degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id) < 0)
 
76
                        {
 
77
                            printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d dof=%d\n", __FILE__, __LINE__, i, e,
 
78
                                   NN, min_id, degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id);
 
79
                            exit(1);
 
80
                        }
 
81
#endif
 
82
                        if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id] > 0)
 
83
                        {
 
84
                            independent = FALSE;
 
85
                            break;
 
86
                        }
 
87
                    }
 
88
                    /* if e is independend a new color is assigned and the nodes are marked as being used */
 
89
                    if (independent)
 
90
                    {
 
91
                        for (i = 0; i < NN; i++)
 
92
                            maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id] = 1;
 
93
                        in->Color[e] = in->maxColor + 1;
 
94
                    }
 
95
                    else
 
96
                    {
 
97
                        numUncoloredElements++;
 
98
                    }
 
99
                }
 
100
 
 
101
            }
 
102
            in->maxColor++;
 
103
        }                       /* end of while loop */
 
104
    }
 
105
    /* all done : */
 
106
    TMPMEMFREE(maskDOF);
 
107
}