emergency commit
[cl-cudd.git] / distr / cudd / doc / node4.html
blobd7a60ba0c6d366195783fd836ae9a4ea95d18bf8
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3 <!--Converted with jLaTeX2HTML 2002-2-1 (1.70) JA patch-2.0
4 patched version by: Kenshi Muto, Debian Project.
5 * modified by: Shige TAKENO
6 LaTeX2HTML 2002-2-1 (1.70),
7 original version by: Nikos Drakos, CBLU, University of Leeds
8 * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
9 * with significant contributions from:
10 Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
11 <HTML>
12 <HEAD>
13 <TITLE>Programmer's Manual</TITLE>
14 <META NAME="description" CONTENT="Programmer's Manual">
15 <META NAME="keywords" CONTENT="cuddIntro">
16 <META NAME="resource-type" CONTENT="document">
17 <META NAME="distribution" CONTENT="global">
19 <META NAME="Generator" CONTENT="jLaTeX2HTML v2002-2-1 JA patch-2.0">
20 <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
22 <LINK REL="STYLESHEET" HREF="cuddIntro.css">
24 <LINK REL="next" HREF="node5.html">
25 <LINK REL="previous" HREF="node3.html">
26 <LINK REL="up" HREF="cuddIntro.html">
27 <LINK REL="next" HREF="node5.html">
28 </HEAD>
30 <BODY >
31 <!--Navigation Panel-->
32 <A NAME="tex2html152"
33 HREF="node5.html">
34 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
35 SRC="icons/next.png"></A>
36 <A NAME="tex2html148"
37 HREF="cuddIntro.html">
38 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
39 SRC="icons/up.png"></A>
40 <A NAME="tex2html142"
41 HREF="node3.html">
42 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
43 SRC="icons/prev.png"></A>
44 <A NAME="tex2html150"
45 HREF="node8.html">
46 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
47 SRC="icons/index.png"></A>
48 <BR>
49 <B> Next:</B> <A NAME="tex2html153"
50 HREF="node5.html">The C++ Interface</A>
51 <B> Up:</B> <A NAME="tex2html149"
52 HREF="cuddIntro.html">CUDD: CU Decision Diagram</A>
53 <B> Previous:</B> <A NAME="tex2html143"
54 HREF="node3.html">User's Manual</A>
55 &nbsp; <B> <A NAME="tex2html151"
56 HREF="node8.html">Index</A></B>
57 <BR>
58 <BR>
59 <!--End of Navigation Panel-->
60 <!--Table of Child-Links-->
61 <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
63 <UL>
64 <LI><A NAME="tex2html154"
65 HREF="node4.html#SECTION00041000000000000000">Compiling and Linking</A>
66 <LI><A NAME="tex2html155"
67 HREF="node4.html#SECTION00042000000000000000">Reference Counts</A>
68 <UL>
69 <LI><A NAME="tex2html156"
70 HREF="node4.html#SECTION00042100000000000000">NULL Return Values</A>
71 <LI><A NAME="tex2html157"
72 HREF="node4.html#SECTION00042200000000000000"><I>Cudd_RecursiveDeref</I> vs. <I>Cudd_Deref</I></A>
73 <LI><A NAME="tex2html158"
74 HREF="node4.html#SECTION00042300000000000000">When Increasing the Reference Count is Unnecessary</A>
75 <LI><A NAME="tex2html159"
76 HREF="node4.html#SECTION00042400000000000000">Saturating Increments and Decrements</A>
77 </UL>
78 <BR>
79 <LI><A NAME="tex2html160"
80 HREF="node4.html#SECTION00043000000000000000">Complement Arcs</A>
81 <LI><A NAME="tex2html161"
82 HREF="node4.html#SECTION00044000000000000000">The Cache</A>
83 <UL>
84 <LI><A NAME="tex2html162"
85 HREF="node4.html#SECTION00044100000000000000">Cache Sizing</A>
86 <LI><A NAME="tex2html163"
87 HREF="node4.html#SECTION00044200000000000000">Local Caches</A>
88 </UL>
89 <BR>
90 <LI><A NAME="tex2html164"
91 HREF="node4.html#SECTION00045000000000000000">The Unique Table</A>
92 <LI><A NAME="tex2html165"
93 HREF="node4.html#SECTION00046000000000000000">Allowing Asynchronous Reordering</A>
94 <LI><A NAME="tex2html166"
95 HREF="node4.html#SECTION00047000000000000000">Debugging</A>
96 <LI><A NAME="tex2html167"
97 HREF="node4.html#SECTION00048000000000000000">Gathering and Interpreting Statistics</A>
98 <UL>
99 <LI><A NAME="tex2html168"
100 HREF="node4.html#SECTION00048100000000000000">Non Modifiable Parameters</A>
101 <LI><A NAME="tex2html169"
102 HREF="node4.html#SECTION00048200000000000000">Modifiable Parameters</A>
103 <LI><A NAME="tex2html170"
104 HREF="node4.html#SECTION00048300000000000000">Extended Statistics and Reporting</A>
105 </UL>
106 <BR>
107 <LI><A NAME="tex2html171"
108 HREF="node4.html#SECTION00049000000000000000">Guidelines for Documentation</A>
109 </UL>
110 <!--End of Table of Child-Links-->
111 <HR>
113 <H1><A NAME="SECTION00040000000000000000"></A>
114 <A NAME="sec:prog"></A>
115 <BR>
116 Programmer's Manual
117 </H1>
120 This section provides additional detail on the working of the CUDD
121 package and on the programming conventions followed in its writing.
122 The additional detail should help those who want to write procedures
123 that directly manipulate the CUDD data structures.
127 <H2><A NAME="SECTION00041000000000000000"></A>
128 <A NAME="695"></A><A NAME="sec:compileInt"></A>
129 <BR>
130 Compiling and Linking
131 </H2>
134 If you plan to use the CUDD package as a clear box<A NAME="697"></A>
135 (for instance, you want to write a procedure that traverses a decision
136 diagram) you need to add
137 <PRE>
138 #include "cuddInt.h"
139 </PRE>
140 to your source files. In addition, you should link <code>libcudd.a</code> to
141 your executable. Some platforms require specific compiler and linker
142 flags. Refer to the <TT>Makefile</TT> in the top level directory of
143 the distribution.
147 <H2><A NAME="SECTION00042000000000000000"></A>
148 <A NAME="702"></A><A NAME="sec:ref"></A>
149 <BR>
150 Reference Counts
151 </H2>
154 Garbage<A NAME="704"></A> collection in the CUDD package is
155 based on reference counts. Each node stores the sum of the external
156 references and internal references. An internal BDD or ADD node is
157 created by a call to <I>cuddUniqueInter</I><A NAME="1283"></A>, an
158 internal ZDD node is created by a call to
159 <I>cuddUniqueInterZdd</I><A NAME="1285"></A>, and a
160 terminal<A NAME="709"></A> node is created by a call to
161 <I>cuddUniqueConst</I><A NAME="1287"></A>. If the node returned by
162 these functions is new, its reference count is zero. The function
163 that calls <I>cuddUniqueInter</I><A NAME="1289"></A>,
164 <I>cuddUniqueInterZdd</I><A NAME="1291"></A>, or
165 <I>cuddUniqueConst</I><A NAME="1293"></A> is responsible for
166 increasing the reference count of the node. This is accomplished by
167 calling <I>Cudd_Ref</I><A NAME="1295"></A>.
170 When a function is no longer needed by an application, the memory used
171 by its diagram can be recycled by calling
172 <I>Cudd_RecursiveDeref</I><A NAME="1297"></A> (BDDs and ADDs)
173 or <I>Cudd_RecursiveDerefZdd</I><A NAME="1299"></A>
174 (ZDDs). These functions decrease the reference <A NAME="724"></A> count of the node passed to them. If the reference count
175 becomes 0, then two things happen:
177 <OL>
178 <LI>The node is declared ``dead<A NAME="726"></A>;'' this entails
179 increasing the counters<A NAME="727"></A> of the dead
180 nodes. (One counter for the subtable<A NAME="728"></A> to which the
181 node belongs, and one global counter for the
182 unique<A NAME="729"></A> table to which the node belongs.) The
183 node itself is not affected.
184 </LI>
185 <LI>The function is recursively called on the two children of the
186 node.
187 </LI>
188 </OL>
189 For instance, if the diagram of a function does not share any nodes
190 with other diagrams, then calling
191 <I>Cudd_RecursiveDeref</I><A NAME="1301"></A> or
192 <I>Cudd_RecursiveDerefZdd</I><A NAME="1303"></A> on its
193 root will cause all the nodes of the diagram to become dead.
196 When the number of dead nodes reaches a given level (dynamically
197 determined by the package) garbage collection takes place. During
198 garbage<A NAME="735"></A> collection dead nodes are returned
199 to the node free list<A NAME="736"></A>.
202 When a new node is created, it is important to increase its
203 reference<A NAME="737"></A> count before one of the two
204 following events occurs:
206 <OL>
207 <LI>A call to <I>cuddUniqueInter</I><A NAME="1305"></A>,
208 to <I>cuddUniqueInterZdd</I><A NAME="1307"></A>, to
209 <I>cuddUniqueConst</I><A NAME="1309"></A>, or to a
210 function that may eventually cause a call to them.
211 </LI>
212 <LI>A call to
213 <I>Cudd_RecursiveDeref</I><A NAME="1311"></A>, to
214 <I>Cudd_RecursiveDerefZdd</I><A NAME="1313"></A>, or to
215 a function that may eventually cause a call to them.
216 </LI>
217 </OL>
218 In practice, it is recommended to increase the reference count as soon
219 as the returned pointer has been tested for not being NULL.
223 <H3><A NAME="SECTION00042100000000000000"></A>
224 <A NAME="sec:null"></A>
225 <BR>
226 NULL Return Values
227 </H3>
230 The interface to the memory management functions (e.g., malloc) used
231 by CUDD intercepts NULL return values and calls a handler. The
232 default handler exits with an error message. If the application does
233 not install another handler, therefore, a NULL return value from an
234 exported function of CUDD signals an internal error.
237 If the aplication, however, installs another handler that lets
238 execution continue, a NULL pointer returned by an exported function
239 typically indicates that the process has run out of memory.
240 <I>Cudd_ReadErrorCode</I><A NAME="1315"></A> can be used to
241 ascertain the nature of the problem.
244 An application that tests for the result being NULL can try some
245 remedial action, if it runs out of memory. For instance, it may free
246 some memory that is not strictly necessary, or try a slower algorithm
247 that takes less space. As an example, CUDD overrides the default
248 handler when trying to enlarge the cache or increase the number of
249 slots of the unique table. If the allocation fails, the package prints
250 out a message and continues without resizing the cache.
254 <H3><A NAME="SECTION00042200000000000000"></A>
255 <A NAME="sec:deref"></A>
256 <BR>
257 <I>Cudd_RecursiveDeref</I> vs. <I>Cudd_Deref</I>
258 </H3>
261 It is often the case that a recursive procedure has to protect the
262 result it is going to return, while it disposes of intermediate
263 results. (See the previous discussion on when to increase reference
264 counts.) Once the intermediate results have been properly disposed
265 of, the final result must be returned to its pristine state, in which
266 the root node may have a reference count of 0. One cannot use
267 <I>Cudd_RecursiveDeref</I><A NAME="1317"></A> (or
268 <I>Cudd_RecursiveDerefZdd</I>) for this purpose, because it may
269 erroneously make some nodes dead. Therefore, the package provides a
270 different function: <I>Cudd_Deref</I><A NAME="1319"></A>. This
271 function is not recursive, and does not change the dead node counts.
272 Its use is almost exclusively the one just described: Decreasing the
273 reference count of the root of the final result before returning from
274 a recursive procedure.
278 <H3><A NAME="SECTION00042300000000000000"></A>
279 <A NAME="763"></A><A NAME="sec:noref"></A>
280 <BR>
281 When Increasing the Reference Count is Unnecessary
282 </H3>
285 When a copy of a predefined constant<A NAME="765"></A> or of a
286 simple BDD variable is needed for comparison purposes, then calling
287 <I>Cudd_Ref</I><A NAME="1321"></A> is not necessary, because these
288 simple functions are guaranteed to have reference counts greater than
289 0 at all times. If no call to <I>Cudd_Ref</I> is made, then no
290 attempt to free the diagram by calling
291 <I>Cudd_RecursiveDeref</I><A NAME="1323"></A> or
292 <I>Cudd_RecursiveDerefZdd</I><A NAME="1325"></A> should be
293 made.
297 <H3><A NAME="SECTION00042400000000000000"></A>
298 <A NAME="774"></A><A NAME="775"></A><A NAME="sec:satur"></A>
299 <BR>
300 Saturating Increments and Decrements
301 </H3>
304 On 32-bit machines, the CUDD package stores the
305 reference<A NAME="777"></A> counts in unsigned short int's.
306 For large diagrams, it is possible for some reference counts to exceed
307 the capacity of an unsigned short int. Therefore, increments and
308 decrements of reference counts are <I>saturating</I>. This means that
309 once a reference count has reached the maximum possible value, it is
310 no longer changed by calls to <I>Cudd_Ref</I>,
311 <I>Cudd_RecursiveDeref</I><A NAME="1327"></A>,
312 <I>Cudd_RecursiveDerefZdd</I><A NAME="1329"></A>, or
313 <I>Cudd_Deref</I><A NAME="1331"></A>. As a consequence, some nodes
314 that have no references may not be declared dead. This may result in a
315 small waste of memory, which is normally more than offset by the
316 reduction in size of the node structure.
319 When using 64-bit pointers, there is normally no memory advantage from
320 using short int's instead of int's in a DdNode. Therefore, increments
321 and decrements are not saturating in that case. What option is in
322 effect depends on two macros, SIZEOF_VOID_P<A NAME="786"></A>
323 and SIZEOF_INT<A NAME="787"></A>, defined in the external
324 header<A NAME="788"></A> file (<I>cudd.h</I><A NAME="790"></A>). The
325 increments and decrements of the reference counts are performed using
326 two macros: <I>cuddSatInc</I><A NAME="1333"></A> and
327 <I>cuddSatDec</I><A NAME="1335"></A>, whose definitions depend on
328 SIZEOF_VOID_P<A NAME="795"></A> and
329 SIZEOF_INT<A NAME="796"></A>.
333 <H2><A NAME="SECTION00043000000000000000"></A>
334 <A NAME="798"></A><A NAME="sec:compl"></A>
335 <BR>
336 Complement Arcs
337 </H2>
340 If ADDs are restricted to use only the constants 0 and 1, they behave
341 like BDDs without complement arcs. It is normally easier to write code
342 that manipulates 0-1 ADDs, than to write code for BDDs. However,
343 complementation is trivial with complement arcs, and is not trivial
344 without. As a consequence, with complement arcs it is possible to
345 check for more terminal cases and it is possible to apply De Morgan's
346 laws to reduce problems that are essentially identical to a standard
347 form. This in turn increases the utilization of the cache<A NAME="800"></A>.
350 The complement attribute is stored in the least significant bit of the
351 ``else'' pointer of each node. An external pointer to a function can
352 also be complemented. The ``then'' pointer to a node, on the other
353 hand, is always <I>regular<A NAME="801"></A></I>. It is a mistake to
354 use a complement<A NAME="802"></A> pointer as it is to address
355 memory. Instead, it is always necessary to obtain a regular version
356 of it. This is normally done by calling
357 <I>Cudd_Regular</I><A NAME="1337"></A>. It is also a mistake to
358 call <I>cuddUniqueInter</I><A NAME="1339"></A> with a complemented
359 ``then'' child as argument. The calling procedure must apply De
360 Morgan's laws by complementing both pointers passed to
361 <I>cuddUniqueInter</I><A NAME="1341"></A> and then taking the
362 complement of the result.
366 <H2><A NAME="SECTION00044000000000000000"></A>
367 <A NAME="810"></A><A NAME="sec:cache"></A>
368 <BR>
369 The Cache
370 </H2>
373 Each entry of the cache consists of five fields: The operator, three
374 pointers to operands and a pointer to the result. The operator and the
375 three pointers to the operands are combined to form three words. The
376 combination relies on two facts:
378 <UL>
379 <LI>Most operations have one or two operands. A few bits are
380 sufficient to discriminate all three-operands operations.
381 </LI>
382 <LI>All nodes are aligned to 16-byte boundaries. (32-byte boundaries
383 if 64-bit pointers are used.) Hence, there are a few bits available
384 to distinguish the three-operand operations from te others and to
385 assign unique codes to them.
386 </LI>
387 </UL>
390 The cache does not contribute to the reference
391 <A NAME="814"></A>
392 counts of the nodes. The fact that the cache contains a
393 pointer to a node does not imply that the node is alive. Instead, when
394 garbage<A NAME="815"></A> collection takes place, all entries
395 of the cache pointing to dead<A NAME="816"></A> nodes are cleared.
398 The cache is also cleared (of all entries) when dynamic
399 reordering<A NAME="817"></A> takes place. In both cases, the entries
400 removed from the cache are about to become invalid.
403 All operands and results in a cache entry must be pointers to
404 DdNodes<A NAME="818"></A>. If a function produces more than one result,
405 or uses more than three arguments, there are currently two solutions:
407 <UL>
408 <LI>Build a separate, local, cache<A NAME="820"></A>. (Using, for
409 instance, the <I>st</I> library<A NAME="822"></A>.)
410 </LI>
411 <LI>Combine multiple results, or multiple operands, into a single
412 diagram, by building a ``multiplexing structure'' with reserved
413 variables.
414 </LI>
415 </UL>
416 Support of the former solution is under development. (See
417 <TT>cuddLCache.c</TT>..) Support for the latter solution may be
418 provided in future versions of the package.
421 There are three sets of interface<A NAME="825"></A> functions to
422 the cache. The first set is for functions with three operands:
423 <I>cuddCacheInsert</I><A NAME="1343"></A> and
424 <I>cuddCacheLookup</I><A NAME="1345"></A>. The second set is for
425 functions with two operands:
426 <I>cuddCacheInsert2</I><A NAME="1347"></A> and
427 <I>cuddCacheLookup2</I><A NAME="1349"></A>. The second set is for
428 functions with one operand:
429 <I>cuddCacheInsert1</I><A NAME="1351"></A> and
430 <I>cuddCacheLookup1</I><A NAME="1353"></A>. The second set is
431 slightly faster than the first, and the third set is slightly faster
432 than the second.
436 <H3><A NAME="SECTION00044100000000000000"></A>
437 <A NAME="839"></A><A NAME="sec:cache-sizing"></A>
438 <BR>
439 Cache Sizing
440 </H3>
443 The size of the cache can increase during the execution of an
444 application. (There is currently no way to decrease the size of the
445 cache, though it would not be difficult to do it.) When a cache miss
446 occurs, the package uses the following criteria to decide whether to
447 resize the cache:
449 <OL>
450 <LI>If the cache already exceeds the limit given by the
451 <TT>maxCache<A NAME="842"></A></TT> field of the manager, no resizing
452 takes place. The limit is the minimum of two values: a value set at
453 initialization time and possibly modified by the application, which
454 constitutes the hard limit beyond which the cache will never grow;
455 and a number that depends on the current total number of slots in
456 the unique<A NAME="843"></A> table.
457 </LI>
458 <LI>If the cache is not too large already, resizing is decided based
459 on the hit rate. The policy adopted by the CUDD package is
460 ``reward-based<A NAME="844"></A>.'' If the cache hit
461 rate is high, then it is worthwhile to increase the size of the
462 cache.
463 </LI>
464 </OL>
465 When resizing takes place, the statistical counters <A NAME="846"></A> used to compute the hit rate are reinitialized so as to
466 prevent immediate resizing. The number of entries is doubled.
469 The rationale for the ``reward-based<A NAME="847"></A>''
470 policy is as follows. In many BDD/ADD applications the hit rate is
471 not very sensitive to the size of the cache: It is primarily a
472 function of the problem instance at hand. If a large hit rate is
473 observed, chances are that by using a large cache, the results of
474 large problems (those that would take longer to solve) will survive in
475 the cache without being overwritten long enough to cause a valuable
476 cache hit. Notice that when a large problem is solved more than once,
477 so are its recursively generated subproblems. If the hit rate is
478 low, the probability of large problems being solved more than once is
479 low.
482 The other observation about the cache sizing policy is that there is
483 little point in keeping a cache which is much larger than the unique
484 table. Every time the unique table ``fills up,'' garbage collection is
485 invoked and the cache is cleared of all dead entries. A cache that is
486 much larger than the unique<A NAME="848"></A> table is therefore
487 less than fully utilized.
491 <H3><A NAME="SECTION00044200000000000000"></A>
492 <A NAME="850"></A><A NAME="sec:local-caches"></A>
493 <BR>
494 Local Caches
495 </H3>
498 Sometimes it may be necessary or convenient to use a local cache. A
499 local cache can be lossless<A NAME="852"></A> (no results are ever
500 overwritten), or it may store objects for which
501 canonical<A NAME="853"></A> representations are not available. One
502 important fact to keep in mind when using a local cache is that local
503 caches are not cleared during garbage<A NAME="854"></A>
504 collection or before reordering. Therefore, it is necessary to
505 increment the reference<A NAME="855"></A> count of all nodes
506 pointed by a local cache. (Unless their reference counts are
507 guaranteed positive in some other way. One such way is by including
508 all partial results in the global result.) Before disposing of the
509 local cache, all elements stored in it must be passed to
510 <I>Cudd_RecursiveDeref</I><A NAME="1355"></A>. As consequence
511 of the fact that all results in a local cache are referenced, it is
512 generally convenient to store in the local cache also the result of
513 trivial problems, which are not usually stored in the global cache.
514 Otherwise, after a recursive call, it is difficult to tell whether the
515 result is in the cache, and therefore referenced, or not in the cache,
516 and therefore not referenced.
519 An alternative approach to referencing the results in the local caches
520 is to install hook functions (see Section&nbsp;<A HREF="node3.html#sec:hooks">3.16</A>) to be
521 executed before garbage collection.
525 <H2><A NAME="SECTION00045000000000000000"></A>
526 <A NAME="860"></A><A NAME="sec:unique"></A>
527 <BR>
528 The Unique Table
529 </H2>
532 A recursive procedure typically splits the operands by expanding with
533 respect to the topmost variable. Topmost in this context refers to the
534 variable that is closest to the roots in the current variable order.
535 The nodes, on the other hand, hold the index, which is invariant with
536 reordering. Therefore, when splitting, one must use the
537 permutation<A NAME="862"></A> array maintained by the
538 package to get the right level. Access to the permutation array is
539 provided by the macro <I>cuddI</I><A NAME="1357"></A> for BDDs and ADDs,
540 and by the macro <I>cuddIZ</I><A NAME="1359"></A> for ZDDs.
543 The unique table consists of as many hash<A NAME="867"></A> tables as
544 there are variables in use. These has tables are called <I>unique
545 subtables</I>. The sizes of the unique subtables are determined by two
546 criteria:
548 <OL>
549 <LI>The collision<A NAME="870"></A> lists should be short
550 to keep access time down.
551 </LI>
552 <LI>There should be enough room for dead<A NAME="871"></A> nodes, to
553 prevent too frequent garbage<A NAME="872"></A> collections.
554 </LI>
555 </OL>
556 While the first criterion is fairly straightforward to implement, the
557 second leaves more room to creativity. The CUDD package tries to
558 figure out whether more dead node should be allowed to increase
559 performance. (See also Section&nbsp;<A HREF="node3.html#sec:params">3.4</A>.) There are two
560 reasons for not doing garbage collection too often. The obvious one is
561 that it is expensive. The second is that dead nodes may be
562 reclaimed<A NAME="875"></A>, if they are the result of a
563 successful cache lookup. Hence dead nodes may provide a substantial
564 speed-up if they are kept around long enough. The usefulness of
565 keeping many dead nodes around varies from application to application,
566 and from problem instance to problem instance. As in the sizing of the
567 cache, the CUDD package adopts a
568 ``reward-based<A NAME="876"></A>'' policy to
569 decide how much room should be used for the unique table. If the
570 number of dead nodes reclaimed is large compared to the number of
571 nodes directly requested from the memory manager, then the CUDD
572 package assumes that it will be beneficial to allow more room for the
573 subtables, thereby reducing the frequency of garbage collection. The
574 package does so by switching between two modes of operation:
576 <OL>
577 <LI>Fast growth<A NAME="878"></A>: In this mode, the
578 ratio of dead nodes to total nodes required for garbage collection
579 is higher than in the slow growth mode to favor resizing
580 of the subtables.
581 </LI>
582 <LI>Slow growth<A NAME="879"></A>: In this
583 mode keeping many dead nodes around is not as important as
584 keeping memory requirements low.
585 </LI>
586 </OL>
587 Switching from one mode to the other is based on the following
588 criteria:
590 <OL>
591 <LI>If the unique table is already large, only slow growth is
592 possible.
593 </LI>
594 <LI>If the table is small and many dead nodes are being reclaimed,
595 then fast growth is selected.
596 </LI>
597 </OL>
598 This policy is especially effective when the diagrams being
599 manipulated have lots of recombination. Notice the interplay of the
600 cache sizing and unique sizing: Fast growth normally occurs when the
601 cache hit rate is large. The cache and the unique table then grow in
602 concert, preserving a healthy balance between their sizes.
606 <H2><A NAME="SECTION00046000000000000000"></A>
607 <A NAME="884"></A><A NAME="sec:async"></A>
608 <BR>
609 Allowing Asynchronous Reordering
610 </H2>
613 Asynchronous reordering is the reordering that is triggered
614 automatically by the increase of the number of nodes. Asynchronous
615 reordering takes place when a new internal node must be created, and
616 the number of nodes has reached a given
617 threshold<A NAME="886"></A>. (The threshold is adjusted by
618 the package every time reordering takes place.)
621 Those procedures that do not create new nodes (e.g., procedures that
622 count the number of nodes or minterms<A NAME="887"></A>) need
623 not worry about asynchronous reordering: No special precaution is
624 necessary in writing them.
627 Procedures that only manipulate decision diagrams through the exported
628 functions of the CUDD package also need not concern themselves with
629 asynchronous reordering. (See Section&nbsp;<A HREF="node3.html#sec:nodes">3.2.1</A> for the
630 exceptions.)
633 The remaining class of procedures is composed of functions that visit
634 the diagrams and may create new nodes. All such procedures in the CUDD
635 package are written so that they can be interrupted by dynamic
636 reordering. The general approach followed goes under the name of
637 ``abort and retry<A NAME="889"></A>.'' As the name
638 implies, a computation that is interrupted by dynamic reordering is
639 aborted and tried again.
642 A recursive procedure that can be interrupted by dynamic reordering
643 (an interruptible<A NAME="890"></A> procedure
644 from now on) is composed of two functions. One is responsible for the
645 real computation. The other is a simple
646 wrapper<A NAME="891"></A>, which tests whether
647 reordering occurred and restarts the computation if it did.
650 Asynchronous reordering of BDDs and ADDs can only be triggered inside
651 <I>cuddUniqueInter</I><A NAME="1361"></A>, when a new node is about
652 to be created. Likewise, asynchronous reordering of ZDDs can only be
653 triggered inside <I>cuddUniqueInterZdd</I><A NAME="1363"></A>.
654 When reordering is triggered, three things happen:
656 <OL>
657 <LI><I>cuddUniqueInter</I><A NAME="1365"></A> returns a NULL
658 value;
659 </LI>
660 <LI>The flag <I>reordered</I> of the manager is set to 1. (0 means
661 no reordering, while 2 indicates an error occurred during
662 reordering.)
663 </LI>
664 <LI>The counter <I>reorderings</I> of the manager is incremented.
665 The counter is initialized to 0 when the manager is started and can
666 be accessed by calling
667 <I>Cudd_ReadReorderings</I><A NAME="1367"></A>. By taking
668 two readings of the counter, an application can determine if
669 variable reordering has taken place between the first and the second
670 reading. The package itself, however, does not make use of the
671 counter: It is mentioned here for completeness.
672 </LI>
673 </OL>
676 The recursive procedure that receives a NULL value from
677 <I>cuddUniqueInter</I><A NAME="1369"></A> must free all
678 intermediate results that it may have computed before, and return NULL
679 in its turn.
682 The wrapper<A NAME="906"></A> function does not
683 decide whether reordering occurred based on the NULL return value,
684 because the NULL value may be the result of lack of memory. Instead,
685 it checks the <I>reordered</I> flag.
688 When a recursive procedure calls another recursive procedure that may
689 cause reordering, it should bypass the wrapper and call the recursive
690 procedure directly. Otherwise, the calling procedure will not know
691 whether reordering occurred, and will not be able to restart. This is
692 the main reason why most recursive procedures are internal, rather
693 than static. (The wrappers, on the other hand, are mostly exported.)
697 <H2><A NAME="SECTION00047000000000000000"></A>
698 <A NAME="909"></A><A NAME="sec:debug"></A>
699 <BR>
700 Debugging
701 </H2>
704 By defining the symbol DD_DEBUG<A NAME="911"></A> during compilation,
705 numerous checks are added to the code. In addition, the procedures
706 <I>Cudd_DebugCheck</I><A NAME="1371"></A>,
707 <I>Cudd_CheckKeys</I><A NAME="1373"></A>, and
708 <I>cuddHeapProfile</I><A NAME="1375"></A> can be called at any
709 point to verify the consistency of the data structure.
710 (<I>cuddHeapProfile</I> is an internal procedure. It is declared in
711 <I>cuddInt.h</I><A NAME="920"></A>.) Procedures
712 <I>Cudd_DebugCheck</I> and <I>Cudd_CheckKeys</I> are especially
713 useful when CUDD reports that during garbage collection the number of
714 nodes actually deleted from the unique table is different from the
715 count of dead nodes kept by the manager. The error causing the
716 discrepancy may have occurred much earlier than it is discovered. A
717 few strategicaly placed calls to the debugging procedures can
718 considerably narrow down the search for the source of the problem.
719 (For instance, a call to <I>Cudd_RecursiveDeref</I> where one to
720 <I>Cudd_Deref</I> was required may be identified in this way.)
723 One of the most common problems encountered in debugging code based on
724 the CUDD package is a missing call to
725 <I>Cudd_RecursiveDeref</I><A NAME="1377"></A>. To help
726 identify this type of problems, the package provides a function called
727 <I>Cudd_CheckZeroRef</I><A NAME="1379"></A>. This function
728 should be called immediately before shutting down the manager.
729 <I>Cudd_CheckZeroRef</I> checks that the only nodes left with
730 non-zero reference<A NAME="930"></A> counts are the
731 predefined constants, the BDD projection<A NAME="931"></A>
732 functions, and nodes whose reference counts are
733 saturated<A NAME="932"></A>.
736 For this function to be effective the application must explicitly
737 dispose of all diagrams to which it has pointers before calling it.
741 <H2><A NAME="SECTION00048000000000000000"></A>
742 <A NAME="934"></A><A NAME="sec:stats"></A>
743 <BR>
744 Gathering and Interpreting Statistics
745 </H2>
748 Function <I>Cudd_PrintInfo</I><A NAME="1381"></A> can be called to
749 print out the values of parameters and statistics for a manager. The
750 output of <I>Cudd_PrintInfo</I> is divided in two sections. The
751 first reports the values of parameters that are under the application
752 control. The second reports the values of statistical counters and
753 other non-modifiable parameters. A quick guide to the interpretation
754 of all these quantities follows. For ease of exposition, we reverse
755 the order and describe the non-modifiable parameters first. We'll use
756 a sample run as example. There is nothing special about this run.
760 <H3><A NAME="SECTION00048100000000000000"></A>
761 <A NAME="sec:nonModPar"></A>
762 <BR>
763 Non Modifiable Parameters
764 </H3>
767 The list of non-modifiable parameters starts with:
768 <PRE>
769 **** CUDD non-modifiable parameters ****
770 Memory in use: 32544220
771 </PRE>
772 This is the memory used by CUDD for three things mainly: Unique table
773 (including all DD nodes in use), node free list, and computed table.
774 This number almost never decreases in the lifetime of a CUDD manager,
775 because CUDD does not release memory when it frees nodes. Rather, it
776 puts the nodes on its own free list. This number is in bytes. It does
777 not represent the peak memory occupation, because it does not include
778 the size of data structures created temporarily by some functions (e.g.,
779 local look-up tables).
782 <PRE>
783 Peak number of nodes: 837018
784 </PRE>
785 This number is the number of nodes that the manager has allocated.
786 This is not the largest size of the BDDs, because the manager will
787 normally have some dead nodes and some nodes on the free list.
790 <PRE>
791 Peak number of live nodes: 836894
792 </PRE>
793 This is the largest number of live nodes that the manager has held
794 since its creation.
797 <PRE>
798 Number of BDD variables: 198
799 Number of ZDD variables: 0
800 </PRE>
801 These numbers tell us this run was not using ZDDs.
804 <PRE>
805 Number of cache entries: 1048576
806 </PRE>
807 Current number of slots of the computed table. If one has a
808 performance problem, this is one of the numbers to look at. The cache
809 size is always a power of 2.
812 <PRE>
813 Number of cache look-ups: 2996536
814 Number of cache hits: 1187087
815 </PRE>
816 These numbers give an indication of the hit rate in the computed
817 table. It is not unlikely for model checking runs to get
818 hit rates even higher than this one (39.62%).
821 <PRE>
822 Number of cache insertions: 1809473
823 Number of cache collisions: 961208
824 Number of cache deletions: 0
825 </PRE>
826 A collision<A NAME="955"></A> occurs when a cache entry is
827 overwritten. A deletion<A NAME="956"></A>
828 occurs when a cache entry is invalidated (e.g., during garbage
829 collection). If the number of deletions is high compared to the
830 number of collisions, it means that garbage collection occurs too
831 often. In this case there were no garbage collections; hence, no
832 deletions.
835 <PRE>
836 Cache used slots = 80.90% (expected 82.19%)
837 </PRE>
838 Percentage of cache slots that contain a valid entry. If this
839 number is small, it may signal one of three conditions:
841 <OL>
842 <LI>The cache may have been recently resized and it is still filling
844 </LI>
845 <LI>The cache is too large for the BDDs. This should not happen if
846 the size of the cache is determined by CUDD.
847 </LI>
848 <LI>The hash function is not working properly. This is accompanied
849 by a degradation in performance. Conversely, a degradation in
850 performance may be due to bad hash function behavior.
851 </LI>
852 </OL>
853 The expected value is computed assuming a uniformly random
854 distribution of the accesses. If the difference between the measured
855 value and the expected value is large (unlike this case), the cache is
856 not working properly.
859 <PRE>
860 Soft limit for cache size: 1318912
861 </PRE>
862 This number says how large the cache can grow. This limit is based on
863 the size of the unique table. CUDD uses a reward-based policy for
864 growing the cache. (See Section&nbsp;<A HREF="#sec:cache-sizing">4.4.1</A>.) The default
865 hit rate for resizing is 30% and the value in effect is reported
866 among the modifiable parameters.
869 <PRE>
870 Number of buckets in unique table: 329728
871 </PRE>
872 This number is exactly one quarter of the one above. This is indeed
873 how the soft limit is determined currently, unless the computed table
874 hits the specified hard limit. (See below.)
877 <PRE>
878 Used buckets in unique table: 87.96% (expected 87.93%)
879 </PRE>
880 Percentage of unique table buckets that contain at least one
881 node. Remarks analogous to those made about the used cache slots apply.
884 <PRE>
885 Number of BDD and ADD nodes: 836894
886 Number of ZDD nodes: 0
887 </PRE>
888 How many nodes are currently in the unique table, either alive or dead.
891 <PRE>
892 Number of dead BDD and ADD nodes: 0
893 Number of dead ZDD nodes: 0
894 </PRE>
895 Subtract these numbers from those above to get the number of live
896 nodes. In this case there are no dead nodes because the application
897 uses delayed dereferencing
898 <I>Cudd_DelayedDerefBdd</I><A NAME="1383"></A>.
901 <PRE>
902 Total number of nodes allocated: 836894
903 </PRE>
904 This is the total number of nodes that were requested and obtained
905 from the free list. It never decreases, and is not an indication of
906 memory occupation after the first garbage collection. Rather, it is a
907 measure of the package activity.
910 <PRE>
911 Total number of nodes reclaimed: 0
912 </PRE>
913 These are the nodes that were resuscitated from the dead. If they are
914 many more than the allocated nodes, and the total
915 number of slots is low relative to the number of nodes, then one may
916 want to increase the limit for fast unique table growth. In this case,
917 the number is 0 because of delayed dereferencing.
920 <PRE>
921 Garbage collections so far: 0
922 Time for garbage collections: 0.00 sec
923 Reorderings so far: 0
924 Time for reordering: 0.00 sec
925 </PRE>
926 There is a GC for each reordering. Hence the first count will always be
927 at least as large as the second.
930 <PRE>
931 Node swaps in reordering: 0
932 </PRE>
933 This is the number of elementary reordering steps. Each step consists
934 of the re-expression of one node while swapping two adjacent
935 variables. This number is a good measure of the amount of work done in
936 reordering.
940 <H3><A NAME="SECTION00048200000000000000"></A>
941 <A NAME="sec:modPar"></A>
942 <BR>
943 Modifiable Parameters
944 </H3>
947 Let us now consider the modifiable parameters, that is, those settings on
948 which the application or the user has control.
951 <PRE>
952 **** CUDD modifiable parameters ****
953 Hard limit for cache size: 8388608
954 </PRE>
955 This number counts entries. Each entry is 16 bytes if CUDD is compiled
956 to use 32-bit pointers. Two important observations are in order:
958 <OL>
959 <LI>If the datasize limit is set, CUDD will use it to determine this
960 number automatically. On a Unix system, one can type ``limit'' or
961 ``ulimit'' to verify if this value is set. If the datasize limit is
962 not set, CUDD uses a default which is rather small. If you have
963 enough memory (say 64MB or more) you should seriously consider
964 <I>not</I> using the default. So, either set the datasize limit, or
965 override the default with
966 <I>Cudd_SetMaxCacheHard</I><A NAME="1385"></A>.
967 </LI>
968 <LI>If a process seems to be going nowhere, a small value for
969 this parameter may be the culprit. One cannot overemphasize the
970 importance of the computed table in BDD algorithms.
971 </LI>
972 </OL>
973 In this case the limit was automatically set for a target maximum
974 memory occupation of 104 MB.
977 <PRE>
978 Cache hit threshold for resizing: 15%
979 </PRE>
980 This number can be changed if one suspects performance is hindered by
981 the small size of the cache, and the cache is not growing towards the
982 soft limit sufficiently fast. In such a case one can change the
983 default 30% to 15% (as in this case) or even 1%.
986 <PRE>
987 Garbage collection enabled: yes
988 </PRE>
989 One can disable it, but there are few good reasons for doing
990 so. It is normally preferable to raise the limit for fast unique table
991 growth. (See below.)
994 <PRE>
995 Limit for fast unique table growth: 1363148
996 </PRE>
997 See Section&nbsp;<A HREF="#sec:unique">4.5</A> and the comments above about reclaimed
998 nodes and hard limit for the cache size. This value was chosen
999 automatically by CUDD for a datasize limit of 1 GB.
1002 <PRE>
1003 Maximum number of variables sifted per reordering: 1000
1004 Maximum number of variable swaps per reordering: 2000000
1005 Maximum growth while sifting a variable: 1.2
1006 </PRE>
1007 Lowering these numbers will cause reordering to be less accurate and
1008 faster. Results are somewhat unpredictable, because larger BDDs after one
1009 reordering do not necessarily mean the process will go faster or slower.
1012 <PRE>
1013 Dynamic reordering of BDDs enabled: yes
1014 Default BDD reordering method: 4
1015 Dynamic reordering of ZDDs enabled: no
1016 Default ZDD reordering method: 4
1017 </PRE>
1018 These lines tell whether automatic reordering can take place and what
1019 method would be used. The mapping from numbers to methods is in
1020 <TT>cudd.h</TT>. One may want to try different BDD reordering
1021 methods. If variable groups are used, however, one should not expect
1022 to see big differences, because CUDD uses the reported method only to
1023 reorder each leaf variable group (typically corresponding present and
1024 next state variables). For the relative order of the groups, it
1025 always uses the same algorithm, which is effectively sifting.
1028 As for enabling dynamic reordering or not, a sensible recommendation is the
1029 following: Unless the circuit is rather small or one has a pretty good
1030 idea of what the order should be, reordering should be enabled.
1033 <PRE>
1034 Realignment of ZDDs to BDDs enabled: no
1035 Realignment of BDDs to ZDDs enabled: no
1036 Dead nodes counted in triggering reordering: no
1037 Group checking criterion: 7
1038 Recombination threshold: 0
1039 Symmetry violation threshold: 0
1040 Arc violation threshold: 0
1041 GA population size: 0
1042 Number of crossovers for GA: 0
1043 </PRE>
1044 Parameters for reordering. See the documentation of the functions used
1045 to control these parameters for the details.
1048 <PRE>
1049 Next reordering threshold: 100000
1050 </PRE>
1051 When the number of nodes crosses this threshold, reordering will be
1052 triggered. (If enabled; in this case it is not.) This parameter is
1053 updated by the package whenever reordering takes place. The
1054 application can change it, for instance at start-up. Another
1055 possibility is to use a hook function (see Section&nbsp;<A HREF="node3.html#sec:hooks">3.16</A>) to
1056 override the default updating policy.
1060 <H3><A NAME="SECTION00048300000000000000"></A>
1061 <A NAME="sec:extendedStats"></A>
1062 <BR>
1063 Extended Statistics and Reporting
1064 </H3>
1067 The following symbols can be defined during compilation to increase
1068 the amount of statistics gathered and the number of messages produced
1069 by the package:
1071 <UL>
1072 <LI>DD_STATS<A NAME="1011"></A>;
1073 </LI>
1074 <LI>DD_CACHE_PROFILE<A NAME="1012"></A>;
1075 </LI>
1076 <LI>DD_UNIQUE_PROFILE<A NAME="1013"></A>.
1077 </LI>
1078 <LI>DD_VERBOSE<A NAME="1014"></A>;
1079 </LI>
1080 </UL>
1081 Defining DD_CACHE_PROFILE causes each entry of the cache to include
1082 an access counter, which is used to compute simple statistics on the
1083 distribution of the keys.
1087 <H2><A NAME="SECTION00049000000000000000"></A>
1088 <A NAME="sec:doc"></A><A NAME="1018"></A>
1089 <BR>
1090 Guidelines for Documentation
1091 </H2>
1094 The documentation of the CUDD functions is extracted automatically
1095 from the sources by Stephen Edwards's extdoc. (The Ext system is
1096 available via anonymous FTP<A NAME="1019"></A> from
1097 <A NAME="tex2html11"
1098 HREF="ftp://ic.eecs.berkeley.edu"><TT>ic.eecs.berkeley.edu</TT></A>.)
1099 The following guidelines are followed in CUDD to insure consistent and
1100 effective use of automatic extraction. It is recommended that
1101 extensions to CUDD follow the same documentation guidelines.
1103 <UL>
1104 <LI>The documentation of an exported procedure should be sufficient
1105 to allow one to use it without reading the code. It is not necessary
1106 to explain how the procedure works; only what it does.
1107 </LI>
1108 <LI>The <I>SeeAlso</I><A NAME="1089"></A>
1109 fields should be space-separated lists of function names. The
1110 <I>SeeAlso</I> field of an exported procedure should only reference
1111 other exported procedures. The <I>SeeAlso</I> field of an internal
1112 procedure may reference other internal procedures as well as
1113 exported procedures, but no static procedures.
1114 </LI>
1115 <LI>The return values are detailed in the
1116 <I>Description</I><A NAME="1090"></A>
1117 field, not in the
1118 <I>Synopsis</I><A NAME="1091"></A> field.
1119 </LI>
1120 <LI>The parameters are documented alongside their declarations.
1121 Further comments may appear in the <I>Description</I> field.
1122 </LI>
1123 <LI>If the <I>Description</I> field is non-empty--which is the
1124 normal case for an exported procedure--then the synopsis is
1125 repeated--possibly slightly changed--at the beginning of the
1126 <I>Description</I> field. This is so because extdoc will not put the
1127 synopsis in the same HTML file<A NAME="1034"></A> as
1128 the description.
1129 </LI>
1130 <LI>The <I>Synopsis</I> field should be about one line long.
1131 </LI>
1132 </UL>
1135 <HR>
1136 <!--Navigation Panel-->
1137 <A NAME="tex2html152"
1138 HREF="node5.html">
1139 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
1140 SRC="icons/next.png"></A>
1141 <A NAME="tex2html148"
1142 HREF="cuddIntro.html">
1143 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
1144 SRC="icons/up.png"></A>
1145 <A NAME="tex2html142"
1146 HREF="node3.html">
1147 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
1148 SRC="icons/prev.png"></A>
1149 <A NAME="tex2html150"
1150 HREF="node8.html">
1151 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
1152 SRC="icons/index.png"></A>
1153 <BR>
1154 <B> Next:</B> <A NAME="tex2html153"
1155 HREF="node5.html">The C++ Interface</A>
1156 <B> Up:</B> <A NAME="tex2html149"
1157 HREF="cuddIntro.html">CUDD: CU Decision Diagram</A>
1158 <B> Previous:</B> <A NAME="tex2html143"
1159 HREF="node3.html">User's Manual</A>
1160 &nbsp; <B> <A NAME="tex2html151"
1161 HREF="node8.html">Index</A></B>
1162 <!--End of Navigation Panel-->
1163 <ADDRESS>
1164 Fabio Somenzi
1165 2009-02-20
1166 </ADDRESS>
1167 </BODY>
1168 </HTML>