~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to intern/opennl/superlu/heap_relax_snode.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * -- SuperLU routine (version 3.0) --
 
3
 * Univ. of California Berkeley, Xerox Palo Alto Research Center,
 
4
 * and Lawrence Berkeley National Lab.
 
5
 * October 15, 2003
 
6
 *
 
7
 */
 
8
/*
 
9
  Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
 
10
 
 
11
  THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
 
12
  EXPRESSED OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 
13
 
 
14
  Permission is hereby granted to use or copy this program for any
 
15
  purpose, provided the above notices are retained on all copies.
 
16
  Permission to modify the code and to distribute modified code is
 
17
  granted, provided the above notices are retained, and a notice that
 
18
  the code was modified is included with the above copyright notice.
 
19
*/
 
20
 
 
21
#include "ssp_defs.h"
 
22
 
 
23
void
 
24
heap_relax_snode (
 
25
             const     int n,
 
26
             int       *et,           /* column elimination tree */
 
27
             const int relax_columns, /* max no of columns allowed in a
 
28
                                         relaxed snode */
 
29
             int       *descendants,  /* no of descendants of each node
 
30
                                         in the etree */
 
31
             int       *relax_end     /* last column in a supernode */
 
32
             )
 
33
{
 
34
/*
 
35
 * Purpose
 
36
 * =======
 
37
 *    relax_snode() - Identify the initial relaxed supernodes, assuming that 
 
38
 *    the matrix has been reordered according to the postorder of the etree.
 
39
 *
 
40
 */ 
 
41
    register int i, j, k, l, parent;
 
42
    register int snode_start;   /* beginning of a snode */
 
43
    int *et_save, *post, *inv_post, *iwork;
 
44
    int nsuper_et = 0, nsuper_et_post = 0;
 
45
 
 
46
    /* The etree may not be postordered, but is heap ordered. */
 
47
 
 
48
    iwork = (int*) intMalloc(3*n+2); 
 
49
    if ( !iwork ) ABORT("SUPERLU_MALLOC fails for iwork[]");
 
50
    inv_post = iwork + n+1;
 
51
    et_save = inv_post + n+1;
 
52
 
 
53
    /* Post order etree */
 
54
    post = (int *) TreePostorder(n, et);
 
55
    for (i = 0; i < n+1; ++i) inv_post[post[i]] = i;
 
56
 
 
57
    /* Renumber etree in postorder */
 
58
    for (i = 0; i < n; ++i) {
 
59
        iwork[post[i]] = post[et[i]];
 
60
        et_save[i] = et[i]; /* Save the original etree */
 
61
    }
 
62
    for (i = 0; i < n; ++i) et[i] = iwork[i];
 
63
 
 
64
    /* Compute the number of descendants of each node in the etree */
 
65
    ifill (relax_end, n, EMPTY);
 
66
    for (j = 0; j < n; j++) descendants[j] = 0;
 
67
    for (j = 0; j < n; j++) {
 
68
        parent = et[j];
 
69
        if ( parent != n )  /* not the dummy root */
 
70
            descendants[parent] += descendants[j] + 1;
 
71
    }
 
72
 
 
73
    /* Identify the relaxed supernodes by postorder traversal of the etree. */
 
74
    for (j = 0; j < n; ) { 
 
75
        parent = et[j];
 
76
        snode_start = j;
 
77
        while ( parent != n && descendants[parent] < relax_columns ) {
 
78
            j = parent;
 
79
            parent = et[j];
 
80
        }
 
81
        /* Found a supernode in postordered etree; j is the last column. */
 
82
        ++nsuper_et_post;
 
83
        k = n;
 
84
        for (i = snode_start; i <= j; ++i)
 
85
            k = SUPERLU_MIN(k, inv_post[i]);
 
86
        l = inv_post[j];
 
87
        if ( (l - k) == (j - snode_start) ) {
 
88
            /* It's also a supernode in the original etree */
 
89
            relax_end[k] = l;           /* Last column is recorded */
 
90
            ++nsuper_et;
 
91
        } else {
 
92
            for (i = snode_start; i <= j; ++i) {
 
93
                l = inv_post[i];
 
94
                if ( descendants[i] == 0 ) relax_end[l] = l;
 
95
            }
 
96
        }
 
97
        j++;
 
98
        /* Search for a new leaf */
 
99
        while ( descendants[j] != 0 && j < n ) j++;
 
100
    }
 
101
 
 
102
#if ( PRNTlevel>=1 )
 
103
    printf(".. heap_snode_relax:\n"
 
104
           "\tNo of relaxed snodes in postordered etree:\t%d\n"
 
105
           "\tNo of relaxed snodes in original etree:\t%d\n",
 
106
           nsuper_et_post, nsuper_et);
 
107
#endif
 
108
 
 
109
    /* Recover the original etree */
 
110
    for (i = 0; i < n; ++i) et[i] = et_save[i];
 
111
 
 
112
    SUPERLU_FREE(post);
 
113
    SUPERLU_FREE(iwork);
 
114
}
 
115
 
 
116