Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_cholmod_internal.h
Go to the documentation of this file.
1 /* ========================================================================== */
2 /* === Include/cholmod_internal.h =========================================== */
3 /* ========================================================================== */
4 
5 /* -----------------------------------------------------------------------------
6  * CHOLMOD/Include/cholmod_internal.h.
7  * Copyright (C) 2005-2006, Univ. of Florida. Author: Timothy A. Davis
8  * CHOLMOD/Include/cholmod_internal.h is licensed under Version 2.1 of the GNU
9  * Lesser General Public License. See lesser.txt for a text of the license.
10  * CHOLMOD is also available under other licenses; contact authors for details.
11  * http://www.cise.ufl.edu/research/sparse
12  * -------------------------------------------------------------------------- */
13 
14 /* CHOLMOD internal include file.
15  *
16  * This file contains internal definitions for CHOLMOD, not meant to be included
17  * in user code. They define macros that are not prefixed with CHOLMOD_. This
18  * file can safely #include'd in user code if you want to make use of the
19  * macros defined here, and don't mind the possible name conflicts with your
20  * code, however.
21  *
22  * Required by all CHOLMOD routines. Not required by any user routine that
23  * uses CHOLMOMD. Unless debugging is enabled, this file does not require any
24  * CHOLMOD module (not even the Core module).
25  *
26  * If debugging is enabled, all CHOLMOD modules require the Check module.
27  * Enabling debugging requires that this file be editted. Debugging cannot be
28  * enabled with a compiler flag. This is because CHOLMOD is exceedingly slow
29  * when debugging is enabled. Debugging is meant for development of CHOLMOD
30  * itself, not by users of CHOLMOD.
31  */
32 
33 #ifndef AMESOS_CHOLMOD_INTERNAL_H
34 #define AMESOS_CHOLMOD_INTERNAL_H
35 
36 /* ========================================================================== */
37 /* === large file I/O ======================================================= */
38 /* ========================================================================== */
39 
40 /* Definitions for large file I/O must come before any other #includes. If
41  * this causes problems (may not be portable to all platforms), then compile
42  * CHOLMOD with -DNLARGEFILE. You must do this for MATLAB 6.5 and earlier,
43  * for example. */
44 
45 #include "amesos_cholmod_io64.h"
46 
47 /* ========================================================================== */
48 /* === debugging and basic includes ========================================= */
49 /* ========================================================================== */
50 
51 /* turn off debugging */
52 #ifndef NDEBUG
53 #define NDEBUG
54 #endif
55 
56 /* Uncomment this line to enable debugging. CHOLMOD will be very slow.
57 #undef NDEBUG
58  */
59 
60 #if !defined(NPRINT) || !defined(NDEBUG)
61 #include <stdio.h>
62 #endif
63 
64 #include <stddef.h>
65 #include <math.h>
66 #include <limits.h>
67 #include <float.h>
68 #include <stdlib.h>
69 
70 /* ========================================================================== */
71 /* === basic definitions ==================================================== */
72 /* ========================================================================== */
73 
74 /* Some non-conforming compilers insist on defining TRUE and FALSE. */
75 #undef TRUE
76 #undef FALSE
77 #define TRUE 1
78 #define FALSE 0
79 #define BOOLEAN(x) ((x) ? TRUE : FALSE)
80 
81 /* NULL should already be defined, but ensure it is here. */
82 #ifndef NULL
83 #define NULL ((void *) 0)
84 #endif
85 
86 /* FLIP is a "negation about -1", and is used to mark an integer i that is
87  * normally non-negative. FLIP (EMPTY) is EMPTY. FLIP of a number > EMPTY
88  * is negative, and FLIP of a number < EMTPY is positive. FLIP (FLIP (i)) = i
89  * for all integers i. UNFLIP (i) is >= EMPTY. */
90 #define EMPTY (-1)
91 #define FLIP(i) (-(i)-2)
92 #define UNFLIP(i) (((i) < EMPTY) ? FLIP (i) : (i))
93 
94 /* MAX and MIN are not safe to use for NaN's */
95 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
96 #define MAX3(a,b,c) (((a) > (b)) ? (MAX (a,c)) : (MAX (b,c)))
97 #define MAX4(a,b,c,d) (((a) > (b)) ? (MAX3 (a,c,d)) : (MAX3 (b,c,d)))
98 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
99 #define IMPLIES(p,q) (!(p) || (q))
100 
101 /* find the sign: -1 if x < 0, 1 if x > 0, zero otherwise.
102  * Not safe for NaN's */
103 #define SIGN(x) (((x) < 0) ? (-1) : (((x) > 0) ? 1 : 0))
104 
105 /* round up an integer x to a multiple of s */
106 #define ROUNDUP(x,s) ((s) * (((x) + ((s) - 1)) / (s)))
107 
108 #define ERROR(status,msg) \
109  CHOLMOD(error) (status, __FILE__, __LINE__, msg, Common)
110 
111 /* Check a pointer and return if null. Set status to invalid, unless the
112  * status is already "out of memory" */
113 #define RETURN_IF_NULL(A,result) \
114 { \
115  if ((A) == NULL) \
116  { \
117  if (Common->status != CHOLMOD_OUT_OF_MEMORY) \
118  { \
119  ERROR (CHOLMOD_INVALID, "argument missing") ; \
120  } \
121  return (result) ; \
122  } \
123 }
124 
125 /* Return if Common is NULL or invalid */
126 #define RETURN_IF_NULL_COMMON(result) \
127 { \
128  if (Common == NULL) \
129  { \
130  return (result) ; \
131  } \
132  if (Common->itype != ITYPE || Common->dtype != DTYPE) \
133  { \
134  Common->status = CHOLMOD_INVALID ; \
135  return (result) ; \
136  } \
137 }
138 
139 #define IS_NAN(x) CHOLMOD_IS_NAN(x)
140 #define IS_ZERO(x) CHOLMOD_IS_ZERO(x)
141 #define IS_NONZERO(x) CHOLMOD_IS_NONZERO(x)
142 #define IS_LT_ZERO(x) CHOLMOD_IS_LT_ZERO(x)
143 #define IS_GT_ZERO(x) CHOLMOD_IS_GT_ZERO(x)
144 #define IS_LE_ZERO(x) CHOLMOD_IS_LE_ZERO(x)
145 
146 /* 1e308 is a huge number that doesn't take many characters to print in a
147  * file, in CHOLMOD/Check/cholmod_read and _write. Numbers larger than this
148  * are interpretted as Inf, since sscanf doesn't read in Inf's properly.
149  * This assumes IEEE double precision arithmetic. DBL_MAX would be a little
150  * better, except that it takes too many digits to print in a file. */
151 #define HUGE_DOUBLE 1e308
152 
153 /* ========================================================================== */
154 /* === int/UF_long and double/float definitions ============================= */
155 /* ========================================================================== */
156 
157 /* CHOLMOD is designed for 3 types of integer variables:
158  *
159  * (1) all integers are int
160  * (2) most integers are int, some are UF_long
161  * (3) all integers are UF_long
162  *
163  * and two kinds of floating-point values:
164  *
165  * (1) double
166  * (2) float
167  *
168  * the complex types (ANSI-compatible complex, and MATLAB-compatable zomplex)
169  * are based on the double or float type, and are not selected here. They
170  * are typically selected via template routines.
171  *
172  * This gives 6 different modes in which CHOLMOD can be compiled (only the
173  * first two are currently supported):
174  *
175  * DINT double, int prefix: cholmod_
176  * DLONG double, UF_long prefix: cholmod_l_
177  * DMIX double, mixed int/UF_long prefix: cholmod_m_
178  * SINT float, int prefix: cholmod_si_
179  * SLONG float, UF_long prefix: cholmod_sl_
180  * SMIX float, mixed int/log prefix: cholmod_sm_
181  *
182  * These are selected with compile time flags (-DDLONG, for example). If no
183  * flag is selected, the default is DINT.
184  *
185  * All six versions use the same include files. The user-visible include files
186  * are completely independent of which int/UF_long/double/float version is being
187  * used. The integer / real types in all data structures (sparse, triplet,
188  * dense, common, and triplet) are defined at run-time, not compile-time, so
189  * there is only one "cholmod_sparse" data type. Void pointers are used inside
190  * that data structure to point to arrays of the proper type. Each data
191  * structure has an itype and dtype field which determines the kind of basic
192  * types used. These are defined in Include/cholmod_core.h.
193  *
194  * FUTURE WORK: support all six types (float, and mixed int/UF_long)
195  *
196  * UF_long is normally defined as long. However, for WIN64 it is __int64.
197  * It can also be redefined for other platforms, by modifying UFconfig.h.
198  */
199 
200 #include "amesos_UFconfig.h"
201 
202 /* -------------------------------------------------------------------------- */
203 /* Size_max: the largest value of size_t */
204 /* -------------------------------------------------------------------------- */
205 
206 #define Size_max ((size_t) (-1))
207 
208 /* routines for doing arithmetic on size_t, and checking for overflow */
209 size_t amesos_cholmod_add_size_t (size_t a, size_t b, int *ok) ;
210 size_t amesos_cholmod_mult_size_t (size_t a, size_t k, int *ok) ;
211 size_t amesos_cholmod_l_add_size_t (size_t a, size_t b, int *ok) ;
212 size_t amesos_cholmod_l_mult_size_t (size_t a, size_t k, int *ok) ;
213 
214 /* -------------------------------------------------------------------------- */
215 /* double (also complex double), UF_long */
216 /* -------------------------------------------------------------------------- */
217 
218 #ifdef DLONG
219 #define Real double
220 #define Int UF_long
221 #define Int_max UF_long_max
222 #define CHOLMOD(name) amesos_cholmod_l_ ## name
223 #define LONG
224 #define DOUBLE
225 #define ITYPE CHOLMOD_LONG
226 #define DTYPE CHOLMOD_DOUBLE
227 #define ID UF_long_id
228 
229 /* -------------------------------------------------------------------------- */
230 /* double, int/UF_long */
231 /* -------------------------------------------------------------------------- */
232 
233 #elif defined (DMIX)
234 #error "mixed int/UF_long not yet supported"
235 
236 /* -------------------------------------------------------------------------- */
237 /* single, int */
238 /* -------------------------------------------------------------------------- */
239 
240 #elif defined (SINT)
241 #error "single-precision not yet supported"
242 
243 /* -------------------------------------------------------------------------- */
244 /* single, UF_long */
245 /* -------------------------------------------------------------------------- */
246 
247 #elif defined (SLONG)
248 #error "single-precision not yet supported"
249 
250 /* -------------------------------------------------------------------------- */
251 /* single, int/UF_long */
252 /* -------------------------------------------------------------------------- */
253 
254 #elif defined (SMIX)
255 #error "single-precision not yet supported"
256 
257 /* -------------------------------------------------------------------------- */
258 /* double (also complex double), int: this is the default */
259 /* -------------------------------------------------------------------------- */
260 
261 #else
262 
263 #ifndef DINT
264 #define DINT
265 #endif
266 #define INT
267 #define DOUBLE
268 
269 #define Real double
270 #define Int int
271 #define Int_max INT_MAX
272 #define CHOLMOD(name) amesos_cholmod_ ## name
273 #define ITYPE CHOLMOD_INT
274 #define DTYPE CHOLMOD_DOUBLE
275 #define ID "%d"
276 
277 #endif
278 
279 
280 /* ========================================================================== */
281 /* === real/complex arithmetic ============================================== */
282 /* ========================================================================== */
283 
285 
286 /* ========================================================================== */
287 /* === Architecture and BLAS ================================================ */
288 /* ========================================================================== */
289 
290 #include "amesos_cholmod_blas.h"
291 
292 /* ========================================================================== */
293 /* === debugging definitions ================================================ */
294 /* ========================================================================== */
295 
296 #ifndef NDEBUG
297 
298 #include <assert.h>
299 #include "amesos_cholmod.h"
300 
301 /* The cholmod_dump routines are in the Check module. No CHOLMOD routine
302  * calls the cholmod_check_* or cholmod_print_* routines in the Check module,
303  * since they use Common workspace that may already be in use. Instead, they
304  * use the cholmod_dump_* routines defined there, which allocate their own
305  * workspace if they need it. */
306 
307 #ifndef EXTERN
308 #define EXTERN extern
309 #endif
310 
311 /* double, int */
312 EXTERN int amesos_cholmod_dump ;
313 EXTERN int amesos_cholmod_dump_malloc ;
314 UF_long amesos_cholmod_dump_sparse (cholmod_sparse *, char *, cholmod_common *) ;
315 int amesos_cholmod_dump_factor (cholmod_factor *, char *, cholmod_common *) ;
316 int amesos_cholmod_dump_triplet (cholmod_triplet *, char *, cholmod_common *) ;
317 int amesos_cholmod_dump_dense (cholmod_dense *, char *, cholmod_common *) ;
318 int amesos_cholmod_dump_subset (int *, size_t, size_t, char *, cholmod_common *) ;
319 int amesos_cholmod_dump_perm (int *, size_t, size_t, char *, cholmod_common *) ;
320 int amesos_cholmod_dump_parent (int *, size_t, char *, cholmod_common *) ;
321 void amesos_cholmod_dump_init (char *, cholmod_common *) ;
322 int amesos_cholmod_dump_mem (char *, UF_long, cholmod_common *) ;
323 void amesos_cholmod_dump_real (char *, Real *, UF_long, UF_long, int, int,
324  cholmod_common *) ;
325 void amesos_cholmod_dump_super (UF_long, int *, int *, int *, int *, double *, int,
326  cholmod_common *) ;
327 int amesos_cholmod_dump_partition (UF_long, int *, int *, int *, int *, UF_long,
328  cholmod_common *) ;
329 int amesos_cholmod_dump_work(int, int, UF_long, cholmod_common *) ;
330 
331 /* double, UF_long */
332 EXTERN int amesos_cholmod_l_dump ;
333 EXTERN int amesos_cholmod_l_dump_malloc ;
334 UF_long amesos_cholmod_l_dump_sparse (cholmod_sparse *, char *, cholmod_common *) ;
335 int amesos_cholmod_l_dump_factor (cholmod_factor *, char *, cholmod_common *) ;
336 int amesos_cholmod_l_dump_triplet (cholmod_triplet *, char *, cholmod_common *) ;
337 int amesos_cholmod_l_dump_dense (cholmod_dense *, char *, cholmod_common *) ;
338 int amesos_cholmod_l_dump_subset (UF_long *, size_t, size_t, char *,
339  cholmod_common *) ;
340 int amesos_cholmod_l_dump_perm (UF_long *, size_t, size_t, char *, cholmod_common *) ;
341 int amesos_cholmod_l_dump_parent (UF_long *, size_t, char *, cholmod_common *) ;
342 void amesos_cholmod_l_dump_init (char *, cholmod_common *) ;
343 int amesos_cholmod_l_dump_mem (char *, UF_long, cholmod_common *) ;
344 void amesos_cholmod_l_dump_real (char *, Real *, UF_long, UF_long, int, int,
345  cholmod_common *) ;
346 void amesos_cholmod_l_dump_super (UF_long, UF_long *, UF_long *, UF_long *, UF_long *,
347  double *, int, cholmod_common *) ;
348 int amesos_cholmod_l_dump_partition (UF_long, UF_long *, UF_long *, UF_long *,
350 int amesos_cholmod_l_dump_work(int, int, UF_long, cholmod_common *) ;
351 
352 #define DEBUG_INIT(s) { CHOLMOD(dump_init)(s, Common) ; }
353 #define PK_DEBUG_INIT(s,Common) { CHOLMOD(dump_init)(s, Common) ; }
354 
355 #define ASSERT(expression) (assert (expression))
356 
357 #define PRK(k,params) \
358 { \
359  if (CHOLMOD(dump) >= (k) && Common->print_function != NULL) \
360  { \
361  (Common->print_function) params ; \
362  } \
363 }
364 
365 #define PRINT0(params) PRK (0, params)
366 #define PRINT1(params) PRK (1, params)
367 #define PRINT2(params) PRK (2, params)
368 #define PRINT3(params) PRK (3, params)
369 #define PRINTM(params) PRK (CHOLMOD(dump_malloc), params)
370 
371 #define DEBUG(statement) statement
372 
373 #else
374 
375 /* Debugging disabled (the normal case) */
376 #define PRK(k,params)
377 #define DEBUG_INIT(s)
378 #define PK_DEBUG_INIT(s,Common)
379 #define PRINT0(params)
380 #define PRINT1(params)
381 #define PRINT2(params)
382 #define PRINT3(params)
383 #define PRINTM(params)
384 #define ASSERT(expression)
385 #define DEBUG(statement)
386 #endif
387 
388 #endif
size_t amesos_cholmod_mult_size_t(size_t a, size_t k, int *ok)
size_t amesos_cholmod_l_add_size_t(size_t a, size_t b, int *ok)
#define EXTERN
Definition: amesos_amd.h:315
size_t amesos_cholmod_add_size_t(size_t a, size_t b, int *ok)
size_t amesos_cholmod_l_mult_size_t(size_t a, size_t k, int *ok)
double Real
#define UF_long