Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Cholmod_FunctionMap.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
44 
55 #ifndef AMESOS2_CHOLMOD_FUNCTIONMAP_HPP
56 #define AMESOS2_CHOLMOD_FUNCTIONMAP_HPP
57 
58 #ifdef HAVE_TEUCHOS_COMPLEX
59 #include <complex>
60 #endif
61 
62 #include "Amesos2_FunctionMap.hpp"
64 
65 #include "cholmod.h"
66 
67 namespace Amesos2 {
68 
69  template <>
70  struct FunctionMap<Cholmod,double>
71  {
72 
73  static void cholmod_init_sparse(size_t nrow, size_t ncol, size_t nzmax,
74  int sorted, void *p, void *x, void *i,
75  cholmod_sparse *sparse, int cholmod_itype)
76  {
77  sparse->nrow = nrow;
78  sparse->ncol = ncol;
79  sparse->nzmax = nzmax;
80  sparse->stype = 1;
81  sparse->itype = cholmod_itype;
82  sparse->sorted = 0;
83  sparse->packed = 1;
84  sparse->xtype = CHOLMOD_REAL;
85  sparse->dtype = CHOLMOD_DOUBLE;
86  sparse->x = x;
87  sparse->p = p;
88  sparse->i = i;
89  }
90 
91  static void cholmod_init_dense(int nrow, int ncol, int d, void *x,
92  cholmod_dense *dense)
93  {
94  dense->nrow = nrow;
95  dense->ncol = ncol;
96  dense->d = d;
97  dense->xtype = CHOLMOD_REAL;
98  dense->dtype = CHOLMOD_DOUBLE;
99  dense->x = x;
100  dense->nzmax = 0;
101  dense->z = NULL;
102  }
103  };
104 
105  template <>
106  struct FunctionMap<Cholmod,float> // Cholmod does not support float yet
107  {
108  static void cholmod_init_sparse(size_t nrow, size_t ncol, size_t nzmax,
109  int sorted, void *p, void *x, void*i,
110  cholmod_sparse* sparse, int cholmod_itype)
111  {
112  sparse->nrow = nrow;
113  sparse->ncol = ncol;
114  sparse->nzmax = nzmax;
115  sparse->stype = 1;
116  sparse->itype = cholmod_itype;
117  sparse->sorted = 0;
118  sparse->packed = 1;
119  sparse->xtype = CHOLMOD_REAL;
120  sparse->dtype = CHOLMOD_SINGLE;
121  sparse->x = x;
122  sparse->p = p;
123  sparse->i = i;
124  }
125 
126 
127  static void cholmod_init_dense(int nrow, int ncol, int d, void *x,
128  cholmod_dense *dense)
129  {
130  dense->nrow = nrow;
131  dense->ncol = ncol;
132  dense->d = d;
133  dense->xtype = CHOLMOD_REAL;
134  dense->dtype = CHOLMOD_SINGLE;
135  dense->x = x;
136  dense->nzmax = 0;
137  dense->z = NULL;
138  }
139  };
140 
141 #ifdef HAVE_TEUCHOS_COMPLEX
142  template <>
143  struct FunctionMap<Cholmod,Kokkos::complex<double>>
144  {
145 
146  static void cholmod_init_sparse(size_t nrow, size_t ncol, size_t nzmax,
147  int sorted, void *p, void *x, void *i,
148  cholmod_sparse* sparse, int cholmod_itype)
149  {
150  sparse->nrow = nrow;
151  sparse->ncol = ncol;
152  sparse->nzmax = nzmax;
153  sparse->stype = 1;
154  sparse->itype = cholmod_itype;
155  sparse->sorted = 0;
156  sparse->packed = 1;
157  sparse->xtype = CHOLMOD_COMPLEX;
158  sparse->dtype = CHOLMOD_DOUBLE;
159  sparse->x = x;
160  sparse->p = p;
161  sparse->i = i;
162 
163  }
164 
165  static void cholmod_init_dense(int nrow, int ncol, int d, void *x,
166  cholmod_dense *dense)
167  {
168  dense->nrow = nrow;
169  dense->ncol = ncol;
170  dense->d = d;
171  dense->xtype = CHOLMOD_COMPLEX;
172  dense->dtype = CHOLMOD_DOUBLE;
173  dense->x = x;
174  dense->nzmax = 0;
175  dense->z = NULL;
176  }
177  };
178 
179  template <>
180  struct FunctionMap<Cholmod,Kokkos::complex<float>>
181  {
182 
183  static void cholmod_init_sparse(size_t nrow, size_t ncol, size_t nzmax,
184  int sorted, void *p, void *x, void *i,
185  cholmod_sparse* sparse, int cholmod_itype)
186  {
187  sparse->nrow = nrow;
188  sparse->ncol = ncol;
189  sparse->nzmax = nzmax;
190  sparse->stype = 1;
191  sparse->itype = cholmod_itype;
192  sparse->sorted = 0;
193  sparse->packed = 1;
194  sparse->xtype = CHOLMOD_COMPLEX;
195  sparse->dtype = CHOLMOD_SINGLE;
196  sparse->x = x;
197  sparse->p = p;
198  sparse->i = i;
199 
200  }
201 
202  static void cholmod_init_dense(int nrow, int ncol, int d, void *x,
203  cholmod_dense *dense)
204  {
205  dense->nrow = nrow;
206  dense->ncol = ncol;
207  dense->d = d;
208  dense->xtype = CHOLMOD_COMPLEX;
209  dense->dtype = CHOLMOD_SINGLE;
210  dense->x = x;
211  dense->nzmax = 0;
212  dense->z = NULL;
213  }
214  };
215 #endif
216 
217 } // end namespace Amesos2
218 
219 #endif // AMESOS2_CHOLMOD_FUNCTIONMAP_HPP
Declaration of Function mapping class for Amesos2.
Provides definition of Cholmod types as well as conversions and type traits.