1 /* ========================================================================== */ 2 /* === Include/cholmod_internal.h =========================================== */ 3 /* ========================================================================== */ 4 5 /* ----------------------------------------------------------------------------- 6 * CHOLMOD/Include/cholmod_internal.h. 7 * Copyright (C) 2005-2013, Univ. of Florida. Author: Timothy A. Davis 8 * -------------------------------------------------------------------------- */ 9 10 /* CHOLMOD internal include file. 11 * 12 * This file contains internal definitions for CHOLMOD, not meant to be included 13 * in user code. They define macros that are not prefixed with CHOLMOD_. This 14 * file can safely #include'd in user code if you want to make use of the 15 * macros defined here, and don't mind the possible name conflicts with your 16 * code, however. 17 * 18 * Required by all CHOLMOD routines. Not required by any user routine that 19 * uses CHOLMOMD. Unless debugging is enabled, this file does not require any 20 * CHOLMOD module (not even the Core module). 21 * 22 * If debugging is enabled, all CHOLMOD modules require the Check module. 23 * Enabling debugging requires that this file be editted. Debugging cannot be 24 * enabled with a compiler flag. This is because CHOLMOD is exceedingly slow 25 * when debugging is enabled. Debugging is meant for development of CHOLMOD 26 * itself, not by users of CHOLMOD. 27 */ 28 29 #ifndef CHOLMOD_INTERNAL_H 30 #define CHOLMOD_INTERNAL_H 31 32 /* ========================================================================== */ 33 /* === large file I/O ======================================================= */ 34 /* ========================================================================== */ 35 36 /* Definitions for large file I/O must come before any other #includes. If 37 * this causes problems (may not be portable to all platforms), then compile 38 * CHOLMOD with -DNLARGEFILE. You must do this for MATLAB 6.5 and earlier, 39 * for example. */ 40 41 #include "cholmod_io64.h" 42 43 /* ========================================================================== */ 44 /* === debugging and basic includes ========================================= */ 45 /* ========================================================================== */ 46 47 /* turn off debugging */ 48 #ifndef NDEBUG 49 #define NDEBUG 50 #endif 51 52 /* Uncomment this line to enable debugging. CHOLMOD will be very slow. 53 #undef NDEBUG 54 */ 55 56 #ifdef MATLAB_MEX_FILE 57 #include "mex.h" 58 #endif 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/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 SuiteSparse_long 161 * (3) all integers are SuiteSparse_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, SuiteSparse_long prefix: cholmod_l_ 177 * DMIX double, mixed int/SuiteSparse_long prefix: cholmod_m_ 178 * SINT float, int prefix: cholmod_si_ 179 * SLONG float, SuiteSparse_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/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/long) 195 * 196 * SuiteSparse_long is normally defined as long. However, for WIN64 it is 197 * __int64. It can also be redefined for other platforms, by modifying 198 * SuiteSparse_config.h. 199 */ 200 201 #include "SuiteSparse_config.h" 202 203 /* -------------------------------------------------------------------------- */ 204 /* Size_max: the largest value of size_t */ 205 /* -------------------------------------------------------------------------- */ 206 207 #define Size_max ((size_t) (-1)) 208 209 /* routines for doing arithmetic on size_t, and checking for overflow */ 210 size_t cholmod_add_size_t (size_t a, size_t b, int *ok) ; 211 size_t cholmod_mult_size_t (size_t a, size_t k, int *ok) ; 212 size_t cholmod_l_add_size_t (size_t a, size_t b, int *ok) ; 213 size_t cholmod_l_mult_size_t (size_t a, size_t k, int *ok) ; 214 215 /* -------------------------------------------------------------------------- */ 216 /* double (also complex double), SuiteSparse_long */ 217 /* -------------------------------------------------------------------------- */ 218 219 #ifdef DLONG 220 #define Real double 221 #define Int SuiteSparse_long 222 #define Int_max SuiteSparse_long_max 223 #define CHOLMOD(name) cholmod_l_ ## name 224 #define LONG 225 #define DOUBLE 226 #define ITYPE CHOLMOD_LONG 227 #define DTYPE CHOLMOD_DOUBLE 228 #define ID SuiteSparse_long_id 229 230 /* -------------------------------------------------------------------------- */ 231 /* double (also complex double), int: this is the default */ 232 /* -------------------------------------------------------------------------- */ 233 234 #else 235 236 #ifndef DINT 237 #define DINT 238 #endif 239 #define INT 240 #define DOUBLE 241 242 #define Real double 243 #define Int int 244 #define Int_max INT_MAX 245 #define CHOLMOD(name) cholmod_ ## name 246 #define ITYPE CHOLMOD_INT 247 #define DTYPE CHOLMOD_DOUBLE 248 #define ID "%d" 249 250 /* GPU acceleration is not available for the int version of CHOLMOD */ 251 #undef GPU_BLAS 252 253 #endif 254 255 256 /* ========================================================================== */ 257 /* === real/complex arithmetic ============================================== */ 258 /* ========================================================================== */ 259 260 #include "cholmod_complexity.h" 261 262 /* ========================================================================== */ 263 /* === Architecture and BLAS ================================================ */ 264 /* ========================================================================== */ 265 266 #define BLAS_OK Common->blas_ok 267 #include "cholmod_blas.h" 268 269 /* ========================================================================== */ 270 /* === debugging definitions ================================================ */ 271 /* ========================================================================== */ 272 273 #ifndef NDEBUG 274 275 #include <assert.h> 276 #include "cholmod.h" 277 278 /* The cholmod_dump routines are in the Check module. No CHOLMOD routine 279 * calls the cholmod_check_* or cholmod_print_* routines in the Check module, 280 * since they use Common workspace that may already be in use. Instead, they 281 * use the cholmod_dump_* routines defined there, which allocate their own 282 * workspace if they need it. */ 283 284 #ifndef EXTERN 285 #define EXTERN extern 286 #endif 287 288 /* double, int */ 289 EXTERN int cholmod_dump ; 290 EXTERN int cholmod_dump_malloc ; 291 SuiteSparse_long cholmod_dump_sparse (cholmod_sparse *, const char *, 292 cholmod_common *) ; 293 int cholmod_dump_factor (cholmod_factor *, const char *, cholmod_common *) ; 294 int cholmod_dump_triplet (cholmod_triplet *, const char *, cholmod_common *) ; 295 int cholmod_dump_dense (cholmod_dense *, const char *, cholmod_common *) ; 296 int cholmod_dump_subset (int *, size_t, size_t, const char *, 297 cholmod_common *) ; 298 int cholmod_dump_perm (int *, size_t, size_t, const char *, cholmod_common *) ; 299 int cholmod_dump_parent (int *, size_t, const char *, cholmod_common *) ; 300 void cholmod_dump_init (const char *, cholmod_common *) ; 301 int cholmod_dump_mem (const char *, SuiteSparse_long, cholmod_common *) ; 302 void cholmod_dump_real (const char *, Real *, SuiteSparse_long, 303 SuiteSparse_long, int, int, cholmod_common *) ; 304 void cholmod_dump_super (SuiteSparse_long, int *, int *, int *, int *, double *, 305 int, cholmod_common *) ; 306 int cholmod_dump_partition (SuiteSparse_long, int *, int *, int *, int *, 307 SuiteSparse_long, cholmod_common *) ; 308 int cholmod_dump_work(int, int, SuiteSparse_long, cholmod_common *) ; 309 310 /* double, SuiteSparse_long */ 311 EXTERN int cholmod_l_dump ; 312 EXTERN int cholmod_l_dump_malloc ; 313 SuiteSparse_long cholmod_l_dump_sparse (cholmod_sparse *, const char *, 314 cholmod_common *) ; 315 int cholmod_l_dump_factor (cholmod_factor *, const char *, cholmod_common *) ; 316 int cholmod_l_dump_triplet (cholmod_triplet *, const char *, cholmod_common *); 317 int cholmod_l_dump_dense (cholmod_dense *, const char *, cholmod_common *) ; 318 int cholmod_l_dump_subset (SuiteSparse_long *, size_t, size_t, const char *, 319 cholmod_common *) ; 320 int cholmod_l_dump_perm (SuiteSparse_long *, size_t, size_t, const char *, 321 cholmod_common *) ; 322 int cholmod_l_dump_parent (SuiteSparse_long *, size_t, const char *, 323 cholmod_common *) ; 324 void cholmod_l_dump_init (const char *, cholmod_common *) ; 325 int cholmod_l_dump_mem (const char *, SuiteSparse_long, cholmod_common *) ; 326 void cholmod_l_dump_real (const char *, Real *, SuiteSparse_long, 327 SuiteSparse_long, int, int, cholmod_common *) ; 328 void cholmod_l_dump_super (SuiteSparse_long, SuiteSparse_long *, 329 SuiteSparse_long *, SuiteSparse_long *, SuiteSparse_long *, 330 double *, int, cholmod_common *) ; 331 int cholmod_l_dump_partition (SuiteSparse_long, SuiteSparse_long *, 332 SuiteSparse_long *, SuiteSparse_long *, 333 SuiteSparse_long *, SuiteSparse_long, cholmod_common *) ; 334 int cholmod_l_dump_work(int, int, SuiteSparse_long, cholmod_common *) ; 335 336 #define DEBUG_INIT(s,Common) { CHOLMOD(dump_init)(s, Common) ; } 337 #define ASSERT(expression) (assert (expression)) 338 339 #define PRK(k,params) \ 340 { \ 341 if (CHOLMOD(dump) >= (k) && SuiteSparse_config.printf_func != NULL) \ 342 { \ 343 (SuiteSparse_config.printf_func) params ; \ 344 } \ 345 } 346 347 #define PRINT0(params) PRK (0, params) 348 #define PRINT1(params) PRK (1, params) 349 #define PRINT2(params) PRK (2, params) 350 #define PRINT3(params) PRK (3, params) 351 352 #define PRINTM(params) \ 353 { \ 354 if (CHOLMOD(dump_malloc) > 0) \ 355 { \ 356 printf params ; \ 357 } \ 358 } 359 360 #define DEBUG(statement) statement 361 362 #else 363 364 /* Debugging disabled (the normal case) */ 365 #define PRK(k,params) 366 #define DEBUG_INIT(s,Common) 367 #define PRINT0(params) 368 #define PRINT1(params) 369 #define PRINT2(params) 370 #define PRINT3(params) 371 #define PRINTM(params) 372 #define ASSERT(expression) 373 #define DEBUG(statement) 374 #endif 375 376 #endif 377