Amesos Package Browser (Single Doxygen Collection) Development
amesos_cholmod_internal.h
Go to the documentation of this file.
00001 /* ========================================================================== */
00002 /* === Include/cholmod_internal.h =========================================== */
00003 /* ========================================================================== */
00004 
00005 /* -----------------------------------------------------------------------------
00006  * CHOLMOD/Include/cholmod_internal.h.
00007  * Copyright (C) 2005-2006, Univ. of Florida.  Author: Timothy A. Davis
00008  * CHOLMOD/Include/cholmod_internal.h is licensed under Version 2.1 of the GNU
00009  * Lesser General Public License.  See lesser.txt for a text of the license.
00010  * CHOLMOD is also available under other licenses; contact authors for details.
00011  * http://www.cise.ufl.edu/research/sparse
00012  * -------------------------------------------------------------------------- */
00013 
00014 /* CHOLMOD internal include file.
00015  *
00016  * This file contains internal definitions for CHOLMOD, not meant to be included
00017  * in user code.  They define macros that are not prefixed with CHOLMOD_.  This
00018  * file can safely #include'd in user code if you want to make use of the
00019  * macros defined here, and don't mind the possible name conflicts with your
00020  * code, however.
00021  *
00022  * Required by all CHOLMOD routines.  Not required by any user routine that
00023  * uses CHOLMOMD.  Unless debugging is enabled, this file does not require any
00024  * CHOLMOD module (not even the Core module).
00025  *
00026  * If debugging is enabled, all CHOLMOD modules require the Check module.
00027  * Enabling debugging requires that this file be editted.  Debugging cannot be
00028  * enabled with a compiler flag.  This is because CHOLMOD is exceedingly slow
00029  * when debugging is enabled.  Debugging is meant for development of CHOLMOD
00030  * itself, not by users of CHOLMOD.
00031  */
00032 
00033 #ifndef AMESOS_CHOLMOD_INTERNAL_H
00034 #define AMESOS_CHOLMOD_INTERNAL_H
00035 
00036 /* ========================================================================== */
00037 /* === large file I/O ======================================================= */
00038 /* ========================================================================== */
00039 
00040 /* Definitions for large file I/O must come before any other #includes.  If
00041  * this causes problems (may not be portable to all platforms), then compile
00042  * CHOLMOD with -DNLARGEFILE.  You must do this for MATLAB 6.5 and earlier,
00043  * for example. */
00044 
00045 #include "amesos_cholmod_io64.h"
00046 
00047 /* ========================================================================== */
00048 /* === debugging and basic includes ========================================= */
00049 /* ========================================================================== */
00050 
00051 /* turn off debugging */
00052 #ifndef NDEBUG
00053 #define NDEBUG
00054 #endif
00055 
00056 /* Uncomment this line to enable debugging.  CHOLMOD will be very slow.
00057 #undef NDEBUG
00058  */
00059 
00060 #if !defined(NPRINT) || !defined(NDEBUG)
00061 #include <stdio.h>
00062 #endif
00063 
00064 #include <stddef.h>
00065 #include <math.h>
00066 #include <limits.h>
00067 #include <float.h>
00068 #include <stdlib.h>
00069 
00070 /* ========================================================================== */
00071 /* === basic definitions ==================================================== */
00072 /* ========================================================================== */
00073 
00074 /* Some non-conforming compilers insist on defining TRUE and FALSE. */
00075 #undef TRUE
00076 #undef FALSE
00077 #define TRUE 1
00078 #define FALSE 0
00079 #define BOOLEAN(x) ((x) ? TRUE : FALSE)
00080 
00081 /* NULL should already be defined, but ensure it is here. */
00082 #ifndef NULL
00083 #define NULL ((void *) 0)
00084 #endif
00085 
00086 /* FLIP is a "negation about -1", and is used to mark an integer i that is
00087  * normally non-negative.  FLIP (EMPTY) is EMPTY.  FLIP of a number > EMPTY
00088  * is negative, and FLIP of a number < EMTPY is positive.  FLIP (FLIP (i)) = i
00089  * for all integers i.  UNFLIP (i) is >= EMPTY. */
00090 #define EMPTY (-1)
00091 #define FLIP(i) (-(i)-2)
00092 #define UNFLIP(i) (((i) < EMPTY) ? FLIP (i) : (i))
00093 
00094 /* MAX and MIN are not safe to use for NaN's */
00095 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
00096 #define MAX3(a,b,c) (((a) > (b)) ? (MAX (a,c)) : (MAX (b,c)))
00097 #define MAX4(a,b,c,d) (((a) > (b)) ? (MAX3 (a,c,d)) : (MAX3 (b,c,d)))
00098 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
00099 #define IMPLIES(p,q) (!(p) || (q))
00100 
00101 /* find the sign: -1 if x < 0, 1 if x > 0, zero otherwise.
00102  * Not safe for NaN's */
00103 #define SIGN(x) (((x) < 0) ? (-1) : (((x) > 0) ? 1 : 0))
00104 
00105 /* round up an integer x to a multiple of s */
00106 #define ROUNDUP(x,s) ((s) * (((x) + ((s) - 1)) / (s)))
00107 
00108 #define ERROR(status,msg) \
00109     CHOLMOD(error) (status, __FILE__, __LINE__, msg, Common)
00110 
00111 /* Check a pointer and return if null.  Set status to invalid, unless the
00112  * status is already "out of memory" */
00113 #define RETURN_IF_NULL(A,result) \
00114 { \
00115     if ((A) == NULL) \
00116     { \
00117   if (Common->status != CHOLMOD_OUT_OF_MEMORY) \
00118   { \
00119       ERROR (CHOLMOD_INVALID, "argument missing") ; \
00120   } \
00121   return (result) ; \
00122     } \
00123 }
00124 
00125 /* Return if Common is NULL or invalid */
00126 #define RETURN_IF_NULL_COMMON(result) \
00127 { \
00128     if (Common == NULL) \
00129     { \
00130   return (result) ; \
00131     } \
00132     if (Common->itype != ITYPE || Common->dtype != DTYPE) \
00133     { \
00134   Common->status = CHOLMOD_INVALID ; \
00135   return (result) ; \
00136     } \
00137 }
00138 
00139 #define IS_NAN(x) CHOLMOD_IS_NAN(x)
00140 #define IS_ZERO(x)  CHOLMOD_IS_ZERO(x)
00141 #define IS_NONZERO(x) CHOLMOD_IS_NONZERO(x)
00142 #define IS_LT_ZERO(x) CHOLMOD_IS_LT_ZERO(x)
00143 #define IS_GT_ZERO(x) CHOLMOD_IS_GT_ZERO(x)
00144 #define IS_LE_ZERO(x) CHOLMOD_IS_LE_ZERO(x)
00145 
00146 /* 1e308 is a huge number that doesn't take many characters to print in a
00147  * file, in CHOLMOD/Check/cholmod_read and _write.  Numbers larger than this
00148  * are interpretted as Inf, since sscanf doesn't read in Inf's properly.
00149  * This assumes IEEE double precision arithmetic.  DBL_MAX would be a little
00150  * better, except that it takes too many digits to print in a file. */
00151 #define HUGE_DOUBLE 1e308
00152 
00153 /* ========================================================================== */
00154 /* === int/UF_long and double/float definitions ============================= */
00155 /* ========================================================================== */
00156 
00157 /* CHOLMOD is designed for 3 types of integer variables:
00158  *
00159  *  (1) all integers are int
00160  *  (2) most integers are int, some are UF_long
00161  *  (3) all integers are UF_long
00162  *
00163  * and two kinds of floating-point values:
00164  *
00165  *  (1) double
00166  *  (2) float
00167  *
00168  * the complex types (ANSI-compatible complex, and MATLAB-compatable zomplex)
00169  * are based on the double or float type, and are not selected here.  They
00170  * are typically selected via template routines.
00171  *
00172  * This gives 6 different modes in which CHOLMOD can be compiled (only the
00173  * first two are currently supported):
00174  *
00175  *  DINT  double, int     prefix: cholmod_
00176  *  DLONG double, UF_long     prefix: cholmod_l_
00177  *  DMIX  double, mixed int/UF_long prefix: cholmod_m_
00178  *  SINT  float, int      prefix: cholmod_si_
00179  *  SLONG float, UF_long      prefix: cholmod_sl_
00180  *  SMIX  float, mixed int/log    prefix: cholmod_sm_
00181  *
00182  * These are selected with compile time flags (-DDLONG, for example).  If no
00183  * flag is selected, the default is DINT.
00184  *
00185  * All six versions use the same include files.  The user-visible include files
00186  * are completely independent of which int/UF_long/double/float version is being
00187  * used.  The integer / real types in all data structures (sparse, triplet,
00188  * dense, common, and triplet) are defined at run-time, not compile-time, so
00189  * there is only one "cholmod_sparse" data type.  Void pointers are used inside
00190  * that data structure to point to arrays of the proper type.  Each data
00191  * structure has an itype and dtype field which determines the kind of basic
00192  * types used.  These are defined in Include/cholmod_core.h.
00193  *
00194  * FUTURE WORK: support all six types (float, and mixed int/UF_long)
00195  *
00196  * UF_long is normally defined as long.  However, for WIN64 it is __int64.
00197  * It can also be redefined for other platforms, by modifying UFconfig.h.
00198  */
00199 
00200 #include "amesos_UFconfig.h"
00201 
00202 /* -------------------------------------------------------------------------- */
00203 /* Size_max: the largest value of size_t */
00204 /* -------------------------------------------------------------------------- */
00205 
00206 #define Size_max ((size_t) (-1))
00207 
00208 /* routines for doing arithmetic on size_t, and checking for overflow */
00209 size_t amesos_cholmod_add_size_t (size_t a, size_t b, int *ok) ;
00210 size_t amesos_cholmod_mult_size_t (size_t a, size_t k, int *ok) ;
00211 size_t amesos_cholmod_l_add_size_t (size_t a, size_t b, int *ok) ;
00212 size_t amesos_cholmod_l_mult_size_t (size_t a, size_t k, int *ok) ;
00213 
00214 /* -------------------------------------------------------------------------- */
00215 /* double (also complex double), UF_long */
00216 /* -------------------------------------------------------------------------- */
00217 
00218 #ifdef DLONG
00219 #define Real double
00220 #define Int UF_long
00221 #define Int_max UF_long_max
00222 #define CHOLMOD(name) amesos_cholmod_l_ ## name
00223 #define LONG
00224 #define DOUBLE
00225 #define ITYPE CHOLMOD_LONG
00226 #define DTYPE CHOLMOD_DOUBLE
00227 #define ID UF_long_id
00228 
00229 /* -------------------------------------------------------------------------- */
00230 /* double, int/UF_long */
00231 /* -------------------------------------------------------------------------- */
00232 
00233 #elif defined (DMIX)
00234 #error "mixed int/UF_long not yet supported"
00235 
00236 /* -------------------------------------------------------------------------- */
00237 /* single, int */
00238 /* -------------------------------------------------------------------------- */
00239 
00240 #elif defined (SINT)
00241 #error "single-precision not yet supported"
00242 
00243 /* -------------------------------------------------------------------------- */
00244 /* single, UF_long */
00245 /* -------------------------------------------------------------------------- */
00246 
00247 #elif defined (SLONG)
00248 #error "single-precision not yet supported"
00249 
00250 /* -------------------------------------------------------------------------- */
00251 /* single, int/UF_long */
00252 /* -------------------------------------------------------------------------- */
00253 
00254 #elif defined (SMIX)
00255 #error "single-precision not yet supported"
00256 
00257 /* -------------------------------------------------------------------------- */
00258 /* double (also complex double), int: this is the default */
00259 /* -------------------------------------------------------------------------- */
00260 
00261 #else
00262 
00263 #ifndef DINT
00264 #define DINT
00265 #endif
00266 #define INT
00267 #define DOUBLE
00268 
00269 #define Real double
00270 #define Int int
00271 #define Int_max INT_MAX
00272 #define CHOLMOD(name) amesos_cholmod_ ## name
00273 #define ITYPE CHOLMOD_INT
00274 #define DTYPE CHOLMOD_DOUBLE
00275 #define ID "%d"
00276 
00277 #endif
00278 
00279 
00280 /* ========================================================================== */
00281 /* === real/complex arithmetic ============================================== */
00282 /* ========================================================================== */
00283 
00284 #include "amesos_cholmod_complexity.h"
00285 
00286 /* ========================================================================== */
00287 /* === Architecture and BLAS ================================================ */
00288 /* ========================================================================== */
00289 
00290 #include "amesos_cholmod_blas.h"
00291 
00292 /* ========================================================================== */
00293 /* === debugging definitions ================================================ */
00294 /* ========================================================================== */
00295 
00296 #ifndef NDEBUG
00297 
00298 #include <assert.h>
00299 #include "amesos_cholmod.h"
00300 
00301 /* The cholmod_dump routines are in the Check module.  No CHOLMOD routine
00302  * calls the cholmod_check_* or cholmod_print_* routines in the Check module,
00303  * since they use Common workspace that may already be in use.  Instead, they
00304  * use the cholmod_dump_* routines defined there, which allocate their own
00305  * workspace if they need it. */
00306 
00307 #ifndef EXTERN
00308 #define EXTERN extern
00309 #endif
00310 
00311 /* double, int */
00312 EXTERN int amesos_cholmod_dump ;
00313 EXTERN int amesos_cholmod_dump_malloc ;
00314 UF_long amesos_cholmod_dump_sparse (cholmod_sparse  *, char *, cholmod_common *) ;
00315 int  amesos_cholmod_dump_factor (cholmod_factor  *, char *, cholmod_common *) ;
00316 int  amesos_cholmod_dump_triplet (cholmod_triplet *, char *, cholmod_common *) ;
00317 int  amesos_cholmod_dump_dense (cholmod_dense   *, char *, cholmod_common *) ;
00318 int  amesos_cholmod_dump_subset (int *, size_t, size_t, char *, cholmod_common *) ;
00319 int  amesos_cholmod_dump_perm (int *, size_t, size_t, char *, cholmod_common *) ;
00320 int  amesos_cholmod_dump_parent (int *, size_t, char *, cholmod_common *) ;
00321 void amesos_cholmod_dump_init (char *, cholmod_common *) ;
00322 int  amesos_cholmod_dump_mem (char *, UF_long, cholmod_common *) ;
00323 void amesos_cholmod_dump_real (char *, Real *, UF_long, UF_long, int, int,
00324   cholmod_common *) ;
00325 void amesos_cholmod_dump_super (UF_long, int *, int *, int *, int *, double *, int,
00326   cholmod_common *) ;
00327 int  amesos_cholmod_dump_partition (UF_long, int *, int *, int *, int *, UF_long,
00328   cholmod_common *) ;
00329 int  amesos_cholmod_dump_work(int, int, UF_long, cholmod_common *) ;
00330 
00331 /* double, UF_long */
00332 EXTERN int amesos_cholmod_l_dump ;
00333 EXTERN int amesos_cholmod_l_dump_malloc ;
00334 UF_long amesos_cholmod_l_dump_sparse (cholmod_sparse  *, char *, cholmod_common *) ;
00335 int  amesos_cholmod_l_dump_factor (cholmod_factor  *, char *, cholmod_common *) ;
00336 int  amesos_cholmod_l_dump_triplet (cholmod_triplet *, char *, cholmod_common *) ;
00337 int  amesos_cholmod_l_dump_dense (cholmod_dense   *, char *, cholmod_common *) ;
00338 int  amesos_cholmod_l_dump_subset (UF_long *, size_t, size_t, char *,
00339     cholmod_common *) ;
00340 int  amesos_cholmod_l_dump_perm (UF_long *, size_t, size_t, char *, cholmod_common *) ;
00341 int  amesos_cholmod_l_dump_parent (UF_long *, size_t, char *, cholmod_common *) ;
00342 void amesos_cholmod_l_dump_init (char *, cholmod_common *) ;
00343 int  amesos_cholmod_l_dump_mem (char *, UF_long, cholmod_common *) ;
00344 void amesos_cholmod_l_dump_real (char *, Real *, UF_long, UF_long, int, int,
00345   cholmod_common *) ;
00346 void amesos_cholmod_l_dump_super (UF_long, UF_long *, UF_long *, UF_long *, UF_long *,
00347         double *, int, cholmod_common *) ;
00348 int  amesos_cholmod_l_dump_partition (UF_long, UF_long *, UF_long *, UF_long *,
00349   UF_long *, UF_long, cholmod_common *) ;
00350 int  amesos_cholmod_l_dump_work(int, int, UF_long, cholmod_common *) ;
00351 
00352 #define DEBUG_INIT(s)  { CHOLMOD(dump_init)(s, Common) ; }
00353 #define PK_DEBUG_INIT(s,Common)  { CHOLMOD(dump_init)(s, Common) ; }
00354 
00355 #define ASSERT(expression) (assert (expression))
00356 
00357 #define PRK(k,params) \
00358 { \
00359     if (CHOLMOD(dump) >= (k) && Common->print_function != NULL) \
00360     { \
00361   (Common->print_function) params ; \
00362     } \
00363 }
00364 
00365 #define PRINT0(params) PRK (0, params)
00366 #define PRINT1(params) PRK (1, params)
00367 #define PRINT2(params) PRK (2, params)
00368 #define PRINT3(params) PRK (3, params)
00369 #define PRINTM(params) PRK (CHOLMOD(dump_malloc), params)
00370 
00371 #define DEBUG(statement) statement
00372 
00373 #else
00374 
00375 /* Debugging disabled (the normal case) */
00376 #define PRK(k,params)
00377 #define DEBUG_INIT(s)
00378 #define PK_DEBUG_INIT(s,Common)
00379 #define PRINT0(params)
00380 #define PRINT1(params)
00381 #define PRINT2(params)
00382 #define PRINT3(params)
00383 #define PRINTM(params)
00384 #define ASSERT(expression)
00385 #define DEBUG(statement)
00386 #endif
00387 
00388 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines