Blame view

fvn_sparse/UMFPACK/Source/umf_mem_alloc_element.c 2.52 KB
422234dc3   daniau   git-svn-id: https...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  /* ========================================================================== */
  /* === UMF_mem_alloc_element ================================================ */
  /* ========================================================================== */
  
  /* -------------------------------------------------------------------------- */
  /* UMFPACK Copyright (c) Timothy A. Davis, CISE,                              */
  /* Univ. of Florida.  All Rights Reserved.  See ../Doc/License for License.   */
  /* web: http://www.cise.ufl.edu/research/sparse/umfpack                       */
  /* -------------------------------------------------------------------------- */
  
  /* The UMF_mem_* routines manage the Numeric->Memory memory space. */
  
  /* Allocate a nrows-by-ncols element, and initialize it. */
  /* Returns the index into Numeric->Memory if successful, or 0 on failure. */
  
  #include "umf_internal.h"
  #include "umf_mem_alloc_tail_block.h"
  
  GLOBAL Int UMF_mem_alloc_element
  (
      NumericType *Numeric,
      Int nrows,
      Int ncols,
      Int **Rows,
      Int **Cols,
      Entry **C,
      Int *size,
      Element **epout
  )
  {
  
      Element *ep ;
      Unit *p ;
      Int i ;
  
      ASSERT (Numeric != (NumericType *) NULL) ;
      ASSERT (Numeric->Memory != (Unit *) NULL) ;
  
      *size = GET_ELEMENT_SIZE (nrows, ncols) ;
      if (INT_OVERFLOW (DGET_ELEMENT_SIZE (nrows, ncols) + 1))
      {
  	/* :: allocate element, int overflow :: */
  	return (0) ;	/* problem is too large */
      }
  
      i = UMF_mem_alloc_tail_block (Numeric, *size) ;
      (*size)++ ;
      if (!i)
      {
  	DEBUG0 (("alloc element failed - out of memory
  ")) ;
  	return (0) ;	/* out of memory */
      }
      p = Numeric->Memory + i ;
  
      ep = (Element *) p ;
  
      DEBUG2 (("alloc_element done ("ID" x "ID"): p: "ID" i "ID"
  ",
  	nrows, ncols, (Int) (p-Numeric->Memory), i)) ;
  
      /* Element data structure, in order: */
      p += UNITS (Element, 1) ;		/* (1) Element header */
      *Cols = (Int *) p ;			/* (2) col [0..ncols-1] indices */
      *Rows = *Cols + ncols ;		/* (3) row [0..nrows-1] indices */
      p += UNITS (Int, ncols + nrows) ;
      *C = (Entry *) p ;			/* (4) C [0..nrows-1, 0..ncols-1] */
  
      ep->nrows = nrows ;		/* initialize the header information */
      ep->ncols = ncols ;
      ep->nrowsleft = nrows ;
      ep->ncolsleft = ncols ;
      ep->cdeg = 0 ;
      ep->rdeg = 0 ;
      ep->next = EMPTY ;
  
      DEBUG2 (("new block size: "ID" ", GET_BLOCK_SIZE (Numeric->Memory + i))) ;
      DEBUG2 (("Element size needed "ID"
  ", GET_ELEMENT_SIZE (nrows, ncols))) ;
  
      *epout = ep ;
  
      /* return the offset into Numeric->Memory */
      return (i) ;
  }