NEURON
spconfig.h
Go to the documentation of this file.
1 /*
2  * CONFIGURATION MACRO DEFINITIONS for sparse matrix routines
3  *
4  * Author: Advising professor:
5  * Kenneth S. Kundert Alberto Sangiovanni-Vincentelli
6  * U.C. Berkeley
7  *
8  * This file contains macros for the sparse matrix routines that are used
9  * to define the personality of the routines. The user is expected to
10  * modify this file to maximize the performance of the routines with
11  * his/her matrices.
12  *
13  * Macros are distinguished by using solely capital letters in their
14  * identifiers. This contrasts with C defined identifiers which are
15  * strictly lower case, and program variable and procedure names which use
16  * both upper and lower case.
17  */
18 
19 /*
20  * Revision and copyright information.
21  *
22  * Copyright (c) 1985,86,87,88
23  * by Kenneth S. Kundert and the University of California.
24  *
25  * Permission to use, copy, modify, and distribute this software and
26  * its documentation for any purpose and without fee is hereby granted,
27  * provided that the copyright notices appear in all copies and
28  * supporting documentation and that the authors and the University of
29  * California are properly credited. The authors and the University of
30  * California make no representations as to the suitability of this
31  * software for any purpose. It is provided `as is', without express
32  * or implied warranty.
33  *
34  * $Date: 2003-02-11 19:36:05 +0100 (Tue, 11 Feb 2003) $
35  * $Revision: 3 $
36  */
37 
38 #ifndef spCONFIG_DEFS
39 #define spCONFIG_DEFS
40 
41 #if defined(cmplx_spPrefix)
42 #include "cspredef.h"
43 #endif
44 
45 #ifdef spINSIDE_SPARSE
46 /*
47  * OPTIONS
48  *
49  * These are compiler options. Set each option to one to compile that
50  * section of the code. If a feature is not desired, set the macro
51  * to NO. Recommendations are given in brackets, [ignore them].
52  *
53  * >>> Option descriptions:
54  * Arithmetic Precision
55  * The precision of the arithmetic used by Sparse can be set by
56  * changing changing the spREAL macro. This macro is
57  * contained in the file spMatrix.h. It is strongly suggested to
58  * used double precision with circuit simulators. Note that
59  * because C always performs arithmetic operations in double
60  * precision, the only benefit to using single precision is that
61  * less storage is required. There is often a noticeable speed
62  * penalty when using single precision. Sparse internally refers
63  * to a spREAL as a RealNumber.
64  * REAL
65  * This specifies that the routines are expected to handle real
66  * systems of equations. The routines can be compiled to handle
67  * both real and complex systems at the same time, but there is a
68  * slight speed and memory advantage if the routines are complied
69  * to handle only real systems of equations.
70  * EXPANDABLE
71  * Setting this compiler flag true (1) makes the matrix
72  * expandable before it has been factored. If the matrix is
73  * expandable, then if an element is added that would be
74  * considered out of bounds in the current matrix, the size of
75  * the matrix is increased to hold that element. As a result,
76  * the size of the matrix need not be known before the matrix is
77  * built. The matrix can be allocated with size zero and
78  * expanded.
79  * TRANSLATE
80  * This option allows the set of external row and column numbers
81  * to be non-packed. In other words, the row and column numbers
82  * do not have to be contiguous. The priced paid for this
83  * flexibility is that when TRANSLATE is set true, the time
84  * required to initially build the matrix will be greater because
85  * the external row and column number must be translated into
86  * internal equivalents. This translation brings about other
87  * benefits though. First, the spGetElement() and
88  * spGetAdmittance() routines may be used after the matrix has
89  * been factored. Further, elements, and even rows and columns,
90  * may be added to the matrix, and row and columns may be deleted
91  * from the matrix, after it has been factored. Note that when
92  * the set of row and column number is not a packed set, neither
93  * are the RHS and Solution vectors. Thus the size of these
94  * vectors must be at least as large as the external size, which
95  * is the value of the largest given row or column numbers.
96  * INITIALIZE
97  * Causes the spInitialize(), spGetInitInfo(), and
98  * spInstallInitInfo() routines to be compiled. These routines
99  * allow the user to store and read one pointer in each nonzero
100  * element in the matrix. spInitialize() then calls a user
101  * specified function for each structural nonzero in the matrix,
102  * and includes this pointer as well as the external row and
103  * column numbers as arguments. This allows the user to write
104  * custom matrix initialization routines.
105  * DIAGONAL_PIVOTING
106  * Many matrices, and in particular node- and modified-node
107  * admittance matrices, tend to be nearly symmetric and nearly
108  * diagonally dominant. For these matrices, it is a good idea to
109  * select pivots from the diagonal. With this option enabled,
110  * this is exactly what happens, though if no satisfactory pivot
111  * can be found on the diagonal, an off-diagonal pivot will be
112  * used. If this option is disabled, Sparse does not
113  * preferentially search the diagonal. Because of this, Sparse
114  * has a wider variety of pivot candidates available, and so
115  * presumably fewer fill-ins will be created. However, the
116  * initial pivot selection process will take considerably longer.
117  * If working with node admittance matrices, or other matrices
118  * with a strong diagonal, it is probably best to use
119  * DIAGONAL_PIVOTING for two reasons. First, accuracy will be
120  * better because pivots will be chosen from the large diagonal
121  * elements, thus reducing the chance of growth. Second, a near
122  * optimal ordering will be chosen quickly. If the class of
123  * matrices you are working with does not have a strong diagonal,
124  * do not use DIAGONAL_PIVOTING, but consider using a larger
125  * threshold. When DIAGONAL_PIVOTING is turned off, the following
126  * options and constants are not used: MODIFIED_MARKOWITZ,
127  * MAX_MARKOWITZ_TIES, and TIES_MULTIPLIER.
128  * ARRAY_OFFSET
129  * This determines whether arrays start at an index of zero or one.
130  * This option is necessitated by the fact that standard C
131  * convention dictates that arrays begin with an index of zero but
132  * the standard mathematic convention states that arrays begin with
133  * an index of one. So if you prefer to start your arrays with
134  * zero, or your calling Sparse from FORTRAN, set ARRAY_OFFSET to
135  * NO or 0. Otherwise, set ARRAY_OFFSET to YES or 1. Note that if
136  * you use an offset of one, the arrays that you pass to Sparse
137  * must have an allocated length of one plus the size of the
138  * matrix. ARRAY_OFFSET must be either 0 or 1, no other offsets
139  * are valid.
140  * MODIFIED_MARKOWITZ
141  * This specifies that the modified Markowitz method of pivot
142  * selection is to be used. The modified Markowitz method differs
143  * from standard Markowitz in two ways. First, under modified
144  * Markowitz, the search for a pivot can be terminated early if a
145  * adequate (in terms of sparsity) pivot candidate is found.
146  * Thus, when using modified Markowitz, the initial factorization
147  * can be faster, but at the expense of a suboptimal pivoting
148  * order that may slow subsequent factorizations. The second
149  * difference is in the way modified Markowitz breaks Markowitz
150  * ties. When two or more elements are pivot candidates and they
151  * all have the same Markowitz product, then the tie is broken by
152  * choosing the element that is best numerically. The numerically
153  * best element is the one with the largest ratio of its magnitude
154  * to the magnitude of the largest element in the same column,
155  * excluding itself. The modified Markowitz method results in
156  * marginally better accuracy. This option is most appropriate
157  * for use when working with very large matrices where the initial
158  * factor time represents an unacceptable burden. [NO]
159  * DELETE
160  * This specifies that the spDeleteRowAndCol() routine
161  * should be compiled. Note that for this routine to be
162  * compiled, both DELETE and TRANSLATE should be set true.
163  * STRIP
164  * This specifies that the spStripFills() routine should be compiled.
165  * MODIFIED_NODAL
166  * This specifies that the routine that preorders modified node
167  * admittance matrices should be compiled. This routine results
168  * in greater speed and accuracy if used with this type of
169  * matrix.
170  * QUAD_ELEMENT
171  * This specifies that the routines that allow four related
172  * elements to be entered into the matrix at once should be
173  * compiled. These elements are usually related to an
174  * admittance. The routines affected by QUAD_ELEMENT are the
175  * spGetAdmittance, spGetQuad and spGetOnes routines.
176  * TRANSPOSE
177  * This specifies that the routines that solve the matrix as if
178  * it was transposed should be compiled. These routines are
179  * useful when performing sensitivity analysis using the adjoint
180  * method.
181  * SCALING
182  * This specifies that the routine that performs scaling on the
183  * matrix should be complied. Scaling is not strongly
184  * supported. The routine to scale the matrix is provided, but
185  * no routines are provided to scale and descale the RHS and
186  * Solution vectors. It is suggested that if scaling is desired,
187  * it only be preformed when the pivot order is being chosen [in
188  * spOrderAndFactor()]. This is the only time scaling has
189  * an effect. The scaling may then either be removed from the
190  * solution by the user or the scaled factors may simply be
191  * thrown away. [NO]
192  * DOCUMENTATION
193  * This specifies that routines that are used to document the
194  * matrix, such as spPrint() and spFileMatrix(), should be
195  * compiled.
196  * DETERMINANT
197  * This specifies that the routine spDeterminant() should be complied.
198  * STABILITY
199  * This specifies that spLargestElement() and spRoundoff() should
200  * be compiled. These routines are used to check the stability (and
201  * hence the quality of the pivoting) of the factorization by
202  * computing a bound on the size of the element is the matrix E =
203  * A - LU. If this bound is very high after applying
204  * spOrderAndFactor(), then the pivot threshold should be raised.
205  * If the bound increases greatly after using spFactor(), then the
206  * matrix should probably be reordered.
207  * CONDITION
208  * This specifies that spCondition() and spNorm(), the code that
209  * computes a good estimate of the condition number of the matrix,
210  * should be compiled.
211  * PSEUDOCONDITION
212  * This specifies that spPseudoCondition(), the code that computes
213  * a crude and easily fooled indicator of ill-conditioning in the
214  * matrix, should be compiled.
215  * MULTIPLICATION
216  * This specifies that the routines to multiply the unfactored
217  * matrix by a vector should be compiled.
218  * FORTRAN
219  * This specifies that the FORTRAN interface routines should be
220  * compiled. When interfacing to FORTRAN programs, the ARRAY_OFFSET
221  * options should be set to NO.
222  * DEBUG
223  * This specifies that additional error checking will be compiled.
224  * The type of error checked are those that are common when the
225  * matrix routines are first integrated into a user's program. Once
226  * the routines have been integrated in and are running smoothly, this
227  * option should be turned off.
228  */
229 
230 /* Begin options. */
231 #define REAL YES
232 #define EXPANDABLE YES
233 #define INITIALIZE NO /* instead of YES */
234 #define DIAGONAL_PIVOTING YES
235 #define ARRAY_OFFSET NOT FORTRAN
236 #define MODIFIED_MARKOWITZ NO
237 #define DELETE YES
238 #define STRIP YES
239 #define MODIFIED_NODAL YES
240 #define QUAD_ELEMENT YES
241 #define TRANSPOSE YES
242 #define SCALING YES
243 #define DOCUMENTATION YES
244 #define MULTIPLICATION YES
245 #define DETERMINANT YES
246 #define STABILITY YES
247 #define CONDITION YES
248 #define PSEUDOCONDITION YES
249 #define FORTRAN NO
250 #define DEBUG YES
251 
252 /*
253  * The following options affect Sparse exports and so are exported as a
254  * side effect. For this reason they use the `sp' prefix. The bool
255  * constants YES an NO are not defined in spMatrix.h to avoid conflicts
256  * with user code, so use 0 for NO and 1 for YES.
257  */
258 #endif /* spINSIDE_SPARSE */
259 #ifdef spINSIDE_SPARSE
260 
261 /*
262  * MATRIX CONSTANTS
263  *
264  * These constants are used throughout the sparse matrix routines. They
265  * should be set to suit the type of matrix being solved. Recommendations
266  * are given in brackets.
267  *
268  * Some terminology should be defined. The Markowitz row count is the number
269  * of non-zero elements in a row excluding the one being considered as pivot.
270  * There is one Markowitz row count for every row. The Markowitz column
271  * is defined similarly for columns. The Markowitz product for an element
272  * is the product of its row and column counts. It is a measure of how much
273  * work would be required on the next step of the factorization if that
274  * element were chosen to be pivot. A small Markowitz product is desirable.
275  *
276  * >>> Constants descriptions:
277  * DEFAULT_THRESHOLD
278  * The relative threshold used if the user enters an invalid
279  * threshold. Also the threshold used by spFactor() when
280  * calling spOrderAndFactor(). The default threshold should
281  * not be less than or equal to zero nor larger than one. [0.001]
282  * DIAG_PIVOTING_AS_DEFAULT
283  * This indicates whether spOrderAndFactor() should use diagonal
284  * pivoting as default. This issue only arises when
285  * spOrderAndFactor() is called from spFactor().
286  * SPACE_FOR_ELEMENTS
287  * This number multiplied by the size of the matrix equals the number
288  * of elements for which memory is initially allocated in
289  * spCreate(). [6]
290  * SPACE_FOR_FILL_INS
291  * This number multiplied by the size of the matrix equals the number
292  * of elements for which memory is initially allocated and specifically
293  * reserved for fill-ins in spCreate(). [4]
294  * ELEMENTS_PER_ALLOCATION
295  * The number of matrix elements requested from the malloc utility on
296  * each call to it. Setting this value greater than 1 reduces the
297  * amount of overhead spent in this system call. On a virtual memory
298  * machine, its good to allocate slightly less than a page worth of
299  * elements at a time (or some multiple thereof).
300  * [For the VAX, for real only use 41, otherwise use 31]
301  * MINIMUM_ALLOCATED_SIZE
302  * The minimum allocated size of a matrix. Note that this does not
303  * limit the minimum size of a matrix. This just prevents having to
304  * resize a matrix many times if the matrix is expandable, large and
305  * allocated with an estimated size of zero. This number should not
306  * be less than one.
307  * EXPANSION_FACTOR
308  * The amount the allocated size of the matrix is increased when it
309  * is expanded.
310  * MAX_MARKOWITZ_TIES
311  * This number is used for two slightly different things, both of which
312  * relate to the search for the best pivot. First, it is the maximum
313  * number of elements that are Markowitz tied that will be sifted
314  * through when trying to find the one that is numerically the best.
315  * Second, it creates an upper bound on how large a Markowitz product
316  * can be before it eliminates the possibility of early termination
317  * of the pivot search. In other words, if the product of the smallest
318  * Markowitz product yet found and TIES_MULTIPLIER is greater than
319  * MAX_MARKOWITZ_TIES, then no early termination takes place.
320  * Set MAX_MARKOWITZ_TIES to some small value if no early termination of
321  * the pivot search is desired. An array of RealNumbers is allocated
322  * of size MAX_MARKOWITZ_TIES so it must be positive and shouldn't
323  * be too large. Active when MODIFIED_MARKOWITZ is 1 (true). [100]
324  * TIES_MULTIPLIER
325  * Specifies the number of Markowitz ties that are allowed to occur
326  * before the search for the pivot is terminated early. Set to some
327  * large value if no early termination of the pivot search is desired.
328  * This number is multiplied times the Markowitz product to determine
329  * how many ties are required for early termination. This means that
330  * more elements will be searched before early termination if a large
331  * number of fill-ins could be created by accepting what is currently
332  * considered the best choice for the pivot. Active when
333  * MODIFIED_MARKOWITZ is 1 (true). Setting this number to zero
334  * effectively eliminates all pivoting, which should be avoided.
335  * This number must be positive. TIES_MULTIPLIER is also used when
336  * diagonal pivoting breaks down. [5]
337  * DEFAULT_PARTITION
338  * Which partition mode is used by spPartition() as default.
339  * Possibilities include
340  * spDIRECT_PARTITION -- each row used direct addressing, best for
341  * a few relatively dense matrices.
342  * spINDIRECT_PARTITION -- each row used indirect addressing, best
343  * for a few very sparse matrices.
344  * spAUTO_PARTITION -- direct or indirect addressing is chosen on
345  * a row-by-row basis, carries a large overhead, but speeds up
346  * both dense and sparse matrices, best if there is a large
347  * number of matrices that can use the same ordering.
348  */
349 
350 /* Begin constants. */
351 #define DEFAULT_THRESHOLD 1.0e-3
352 #define DIAG_PIVOTING_AS_DEFAULT YES
353 /*#define SPACE_FOR_ELEMENTS 6*/
354 /*#define SPACE_FOR_FILL_INS 4*/
355 #define SPACE_FOR_ELEMENTS 3
356 #define SPACE_FOR_FILL_INS 1
357 #define ELEMENTS_PER_ALLOCATION 31
358 #define MINIMUM_ALLOCATED_SIZE 6
359 #define EXPANSION_FACTOR 1.5
360 #define MAX_MARKOWITZ_TIES 100
361 #define TIES_MULTIPLIER 5
362 #define DEFAULT_PARTITION spAUTO_PARTITION
363 
364 /*
365  * PRINTER WIDTH
366  *
367  * This macro characterize the printer for the spPrint() routine.
368  *
369  * >>> Macros:
370  * PRINTER_WIDTH
371  * The number of characters per page width. Set to 80 for terminal,
372  * 132 for line printer.
373  */
374 
375 /* Begin printer constants. */
376 #define PRINTER_WIDTH 80
377 
378 /*
379  * MACHINE CONSTANTS
380  *
381  * These numbers must be updated when the program is ported to a new machine.
382  */
383 
384 /* Begin machine constants. */
385 
386 #ifdef notdef /* __STDC__ */
387 /*
388  * This code is currently deleted because most ANSI standard C compilers
389  * do not provide the standard header files yet.
390  */
391 #endif
392 #include <float.h>
393 #include <limits.h>
394 #define MACHINE_RESOLUTION DBL_EPSILON
395 #define LARGEST_REAL DBL_MAX
396 #define SMALLEST_REAL DBL_MIN
397 #define LARGEST_SHORT_INTEGER SHRT_MAX
398 #define LARGEST_LONG_INTEGER LONG_MAX
399 
400 /*
401  * ANNOTATION
402  *
403  * This macro changes the amount of annotation produced by the matrix
404  * routines. The annotation is used as a debugging aid. Change the number
405  * associated with ANNOTATE to change the amount of annotation produced by
406  * the program.
407  */
408 
409 /* Begin annotation definitions. */
410 #define ANNOTATE NONE
411 
412 #define NONE 0
413 #define ON_STRANGE_BEHAVIOR 1
414 #define FULL 2
415 
416 #endif /* spINSIDE_SPARSE */
417 #endif /* spCONFIG_DEFS */