Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
klu2_free_numeric.hpp
1 /* ========================================================================== */
2 /* === KLU_free_numeric ===================================================== */
3 /* ========================================================================== */
4 // @HEADER
5 // ***********************************************************************
6 //
7 // KLU2: A Direct Linear Solver package
8 // Copyright 2011 Sandia Corporation
9 //
10 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
11 // U.S. Government retains certain rights in this software.
12 //
13 // This library is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as
15 // published by the Free Software Foundation; either version 2.1 of the
16 // License, or (at your option) any later version.
17 //
18 // This library is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
26 // USA
27 // Questions? Contact Mike A. Heroux (maherou@sandia.gov)
28 //
29 // KLU2 is derived work from KLU, licensed under LGPL, and copyrighted by
30 // University of Florida. The Authors of KLU are Timothy A. Davis and
31 // Eka Palamadai. See Doc/KLU_README.txt for the licensing and copyright
32 // information for KLU.
33 //
34 // ***********************************************************************
35 // @HEADER
36 
37 /* Free the KLU Numeric object. */
38 
39 #ifndef KLU2_FREE_NUMERIC_HPP
40 #define KLU2_FREE_NUMERIC_HPP
41 
42 #include "klu2_internal.h"
43 #include "klu2_memory.hpp"
44 
45 template <typename Entry, typename Int>
46 Int KLU_free_numeric
47 (
48  KLU_numeric<Entry, Int> **NumericHandle,
49  KLU_common<Entry, Int> *Common
50 )
51 {
52  KLU_numeric<Entry, Int> *Numeric ;
53  Unit **LUbx ;
54  size_t *LUsize ;
55  Int block, n, nzoff, nblocks ;
56 
57  if (Common == NULL)
58  {
59  return (FALSE) ;
60  }
61  if (NumericHandle == NULL || *NumericHandle == NULL)
62  {
63  return (TRUE) ;
64  }
65 
66  Numeric = *NumericHandle ;
67 
68  n = Numeric->n ;
69  nzoff = Numeric->nzoff ;
70  nblocks = Numeric->nblocks ;
71  LUsize = Numeric->LUsize ;
72 
73  LUbx = (Unit **) Numeric->LUbx ;
74  if (LUbx != NULL)
75  {
76  for (block = 0 ; block < nblocks ; block++)
77  {
78  KLU_free (LUbx [block], LUsize ? LUsize [block] : 0,
79  sizeof (Unit), Common) ;
80  }
81  }
82 
83  KLU_free (Numeric->Pnum, n, sizeof (Int), Common) ;
84  KLU_free (Numeric->Offp, n+1, sizeof (Int), Common) ;
85  KLU_free (Numeric->Offi, nzoff+1, sizeof (Int), Common) ;
86  KLU_free (Numeric->Offx, nzoff+1, sizeof (Entry), Common) ;
87 
88  KLU_free (Numeric->Lip, n, sizeof (Int), Common) ;
89  KLU_free (Numeric->Llen, n, sizeof (Int), Common) ;
90  KLU_free (Numeric->Uip, n, sizeof (Int), Common) ;
91  KLU_free (Numeric->Ulen, n, sizeof (Int), Common) ;
92 
93  KLU_free (Numeric->LUsize, nblocks, sizeof (size_t), Common) ;
94 
95  KLU_free (Numeric->LUbx, nblocks, sizeof (Unit *), Common) ;
96 
97  KLU_free (Numeric->Udiag, n, sizeof (Entry), Common) ;
98 
99  KLU_free (Numeric->Rs, n, sizeof (double), Common) ;
100  KLU_free (Numeric->Pinv, n, sizeof (Int), Common) ;
101 
102  KLU_free (Numeric->Work, Numeric->worksize, 1, Common) ;
103 
104  KLU_free (Numeric, 1, sizeof (KLU_numeric<Entry, Int>), Common) ;
105 
106  *NumericHandle = NULL ;
107  return (TRUE) ;
108 }
109 
110 #endif