Amesos2 - Direct Sparse Solver Interfaces Version of the Day
klu2_free_numeric.hpp
1/* ========================================================================== */
2/* === KLU_free_numeric ===================================================== */
3/* ========================================================================== */
4// @HEADER
5// *****************************************************************************
6// KLU2: A Direct Linear Solver package
7//
8// Copyright 2011 NTESS and the KLU2 contributors.
9// SPDX-License-Identifier: LGPL-2.1-or-later
10// *****************************************************************************
11// @HEADER
12
13/* Free the KLU Numeric object. */
14
15#ifndef KLU2_FREE_NUMERIC_HPP
16#define KLU2_FREE_NUMERIC_HPP
17
18#include "klu2_internal.h"
19#include "klu2_memory.hpp"
20
21template <typename Entry, typename Int>
22Int KLU_free_numeric
23(
24 KLU_numeric<Entry, Int> **NumericHandle,
25 KLU_common<Entry, Int> *Common
26)
27{
28 KLU_numeric<Entry, Int> *Numeric ;
29 Unit **LUbx ;
30 size_t *LUsize ;
31 Int block, n, nzoff, nblocks ;
32
33 if (Common == NULL)
34 {
35 return (FALSE) ;
36 }
37 if (NumericHandle == NULL || *NumericHandle == NULL)
38 {
39 return (TRUE) ;
40 }
41
42 Numeric = *NumericHandle ;
43
44 n = Numeric->n ;
45 nzoff = Numeric->nzoff ;
46 nblocks = Numeric->nblocks ;
47 LUsize = Numeric->LUsize ;
48
49 LUbx = (Unit **) Numeric->LUbx ;
50 if (LUbx != NULL)
51 {
52 for (block = 0 ; block < nblocks ; block++)
53 {
54 KLU_free (LUbx [block], LUsize ? LUsize [block] : 0,
55 sizeof (Unit), Common) ;
56 }
57 }
58
59 KLU_free (Numeric->Pnum, n, sizeof (Int), Common) ;
60 KLU_free (Numeric->Offp, n+1, sizeof (Int), Common) ;
61 KLU_free (Numeric->Offi, nzoff+1, sizeof (Int), Common) ;
62 KLU_free (Numeric->Offx, nzoff+1, sizeof (Entry), Common) ;
63
64 KLU_free (Numeric->Lip, n, sizeof (Int), Common) ;
65 KLU_free (Numeric->Llen, n, sizeof (Int), Common) ;
66 KLU_free (Numeric->Uip, n, sizeof (Int), Common) ;
67 KLU_free (Numeric->Ulen, n, sizeof (Int), Common) ;
68
69 KLU_free (Numeric->LUsize, nblocks, sizeof (size_t), Common) ;
70
71 KLU_free (Numeric->LUbx, nblocks, sizeof (Unit *), Common) ;
72
73 KLU_free (Numeric->Udiag, n, sizeof (Entry), Common) ;
74
75 KLU_free (Numeric->Rs, n, sizeof (double), Common) ;
76 KLU_free (Numeric->Pinv, n, sizeof (Int), Common) ;
77
78 KLU_free (Numeric->Work, Numeric->worksize, 1, Common) ;
79
80 KLU_free (Numeric, 1, sizeof (KLU_numeric<Entry, Int>), Common) ;
81
82 *NumericHandle = NULL ;
83 return (TRUE) ;
84}
85
86#endif