kusano 7d535a
kusano 7d535a
/*! @file zcopy_to_ucol.c
kusano 7d535a
 * \brief Copy a computed column of U to the compressed data structure
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
 * 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_zdefs.h"
kusano 7d535a
kusano 7d535a
int
kusano 7d535a
zcopy_to_ucol(
kusano 7d535a
	      int        jcol,	  /* in */
kusano 7d535a
	      int        nseg,	  /* in */
kusano 7d535a
	      int        *segrep,  /* in */
kusano 7d535a
	      int        *repfnz,  /* in */
kusano 7d535a
	      int        *perm_r,  /* in */
kusano 7d535a
	      doublecomplex     *dense,   /* modified - reset to zero on return */
kusano 7d535a
	      GlobalLU_t *Glu      /* modified */
kusano 7d535a
	      )
kusano 7d535a
{
kusano 7d535a
/* 
kusano 7d535a
 * Gather from SPA dense[*] to global ucol[*].
kusano 7d535a
 */
kusano 7d535a
    int ksub, krep, ksupno;
kusano 7d535a
    int i, k, kfnz, segsze;
kusano 7d535a
    int fsupc, isub, irow;
kusano 7d535a
    int jsupno, nextu;
kusano 7d535a
    int new_next, mem_error;
kusano 7d535a
    int       *xsup, *supno;
kusano 7d535a
    int       *lsub, *xlsub;
kusano 7d535a
    doublecomplex    *ucol;
kusano 7d535a
    int       *usub, *xusub;
kusano 7d535a
    int       nzumax;
kusano 7d535a
    doublecomplex zero = {0.0, 0.0};
kusano 7d535a
kusano 7d535a
    xsup    = Glu->xsup;
kusano 7d535a
    supno   = Glu->supno;
kusano 7d535a
    lsub    = Glu->lsub;
kusano 7d535a
    xlsub   = Glu->xlsub;
kusano 7d535a
    ucol    = Glu->ucol;
kusano 7d535a
    usub    = Glu->usub;
kusano 7d535a
    xusub   = Glu->xusub;
kusano 7d535a
    nzumax  = Glu->nzumax;
kusano 7d535a
    
kusano 7d535a
    jsupno = supno[jcol];
kusano 7d535a
    nextu  = xusub[jcol];
kusano 7d535a
    k = nseg - 1;
kusano 7d535a
    for (ksub = 0; ksub < nseg; ksub++) {
kusano 7d535a
	krep = segrep[k--];
kusano 7d535a
	ksupno = supno[krep];
kusano 7d535a
kusano 7d535a
	if ( ksupno != jsupno ) { /* Should go into ucol[] */
kusano 7d535a
	    kfnz = repfnz[krep];
kusano 7d535a
	    if ( kfnz != EMPTY ) {	/* Nonzero U-segment */
kusano 7d535a
kusano 7d535a
	    	fsupc = xsup[ksupno];
kusano 7d535a
	        isub = xlsub[fsupc] + kfnz - fsupc;
kusano 7d535a
	        segsze = krep - kfnz + 1;
kusano 7d535a
kusano 7d535a
		new_next = nextu + segsze;
kusano 7d535a
		while ( new_next > nzumax ) {
kusano 7d535a
		    if (mem_error = zLUMemXpand(jcol, nextu, UCOL, &nzumax, Glu))
kusano 7d535a
			return (mem_error);
kusano 7d535a
		    ucol = Glu->ucol;
kusano 7d535a
		    if (mem_error = zLUMemXpand(jcol, nextu, USUB, &nzumax, Glu))
kusano 7d535a
			return (mem_error);
kusano 7d535a
		    usub = Glu->usub;
kusano 7d535a
		    lsub = Glu->lsub;
kusano 7d535a
		}
kusano 7d535a
		
kusano 7d535a
		for (i = 0; i < segsze; i++) {
kusano 7d535a
		    irow = lsub[isub];
kusano 7d535a
		    usub[nextu] = perm_r[irow];
kusano 7d535a
		    ucol[nextu] = dense[irow];
kusano 7d535a
		    dense[irow] = zero;
kusano 7d535a
		    nextu++;
kusano 7d535a
		    isub++;
kusano 7d535a
		} 
kusano 7d535a
kusano 7d535a
	    }
kusano 7d535a
kusano 7d535a
	}
kusano 7d535a
kusano 7d535a
    } /* for each segment... */
kusano 7d535a
kusano 7d535a
    xusub[jcol + 1] = nextu;      /* Close U[*,jcol] */
kusano 7d535a
    return 0;
kusano 7d535a
}