kusano 7d535a
/*! @file relax_snode.c
kusano 7d535a
 * \brief Identify initial relaxed supernodes
kusano 7d535a
 *
kusano 7d535a
 * 
kusano 7d535a
 * -- SuperLU routine (version 2.0) --
kusano 7d535a
 * Univ. of California Berkeley, Xerox Palo Alto Research Center,
kusano 7d535a
 * and Lawrence Berkeley National Lab.
kusano 7d535a
 * November 15, 1997
kusano 7d535a
 *
kusano 7d535a
 * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
kusano 7d535a
 *
kusano 7d535a
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
kusano 7d535a
 * EXPRESSED OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
kusano 7d535a
 *
kusano 7d535a
 * Permission is hereby granted to use or copy this program for any
kusano 7d535a
 * purpose, provided the above notices are retained on all copies.
kusano 7d535a
 * Permission to modify the code and to distribute modified code is
kusano 7d535a
 * granted, provided the above notices are retained, and a notice that
kusano 7d535a
 * the code was modified is included with the above copyright notice.
kusano 7d535a
 * 
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#include "slu_ddefs.h"
kusano 7d535a
/*! \brief
kusano 7d535a
 *
kusano 7d535a
 * 
kusano 7d535a
 * Purpose
kusano 7d535a
 * =======
kusano 7d535a
 *    relax_snode() - Identify the initial relaxed supernodes, assuming that 
kusano 7d535a
 *    the matrix has been reordered according to the postorder of the etree.
kusano 7d535a
 * 
kusano 7d535a
 */ 
kusano 7d535a
void
kusano 7d535a
relax_snode (
kusano 7d535a
	     const     int n,
kusano 7d535a
	     int       *et,           /* column elimination tree */
kusano 7d535a
	     const int relax_columns, /* max no of columns allowed in a
kusano 7d535a
					 relaxed snode */
kusano 7d535a
	     int       *descendants,  /* no of descendants of each node
kusano 7d535a
					 in the etree */
kusano 7d535a
	     int       *relax_end     /* last column in a supernode */
kusano 7d535a
	     )
kusano 7d535a
{
kusano 7d535a
kusano 7d535a
    register int j, parent;
kusano 7d535a
    register int snode_start;	/* beginning of a snode */
kusano 7d535a
    
kusano 7d535a
    ifill (relax_end, n, EMPTY);
kusano 7d535a
    for (j = 0; j < n; j++) descendants[j] = 0;
kusano 7d535a
kusano 7d535a
    /* Compute the number of descendants of each node in the etree */
kusano 7d535a
    for (j = 0; j < n; j++) {
kusano 7d535a
	parent = et[j];
kusano 7d535a
	if ( parent != n )  /* not the dummy root */
kusano 7d535a
	    descendants[parent] += descendants[j] + 1;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    /* Identify the relaxed supernodes by postorder traversal of the etree. */
kusano 7d535a
    for (j = 0; j < n; ) { 
kusano 7d535a
     	parent = et[j];
kusano 7d535a
        snode_start = j;
kusano 7d535a
 	while ( parent != n && descendants[parent] < relax_columns ) {
kusano 7d535a
	    j = parent;
kusano 7d535a
	    parent = et[j];
kusano 7d535a
	}
kusano 7d535a
	/* Found a supernode with j being the last column. */
kusano 7d535a
	relax_end[snode_start] = j;		/* Last column is recorded */
kusano 7d535a
	j++;
kusano 7d535a
	/* Search for a new leaf */
kusano 7d535a
	while ( descendants[j] != 0 && j < n ) j++;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    /*printf("No of relaxed snodes: %d; relaxed columns: %d\n", 
kusano 7d535a
		nsuper, no_relaxed_col); */
kusano 7d535a
}