abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
reoTest.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [reoTest.c]
4 
5  PackageName [REO: A specialized DD reordering engine.]
6 
7  Synopsis [Various testing procedures (may be outdated).]
8 
9  Author [Alan Mishchenko <alanmi@ece.pdx.edu>]
10 
11  Affiliation [ECE Department. Portland State University, Portland, Oregon.]
12 
13  Date [Ver. 1.0. Started - October 15, 2002.]
14 
15  Revision [$Id: reoTest.c,v 1.0 2002/15/10 03:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "reo.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// FUNCTION DEFINITIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 /**Function*************************************************************
33 
34  Synopsis [Reorders the DD using REO and CUDD.]
35 
36  Description [This function can be used to test the performance of the reordering package.]
37 
38  SideEffects []
39 
40  SeeAlso []
41 
42 ***********************************************************************/
43 void Extra_ReorderTest( DdManager * dd, DdNode * Func )
44 {
45  reo_man * pReo;
46  DdNode * Temp, * Temp1;
47  int pOrder[1000];
48 
49  pReo = Extra_ReorderInit( 100, 100 );
50 
51 //Extra_DumpDot( dd, &Func, 1, "beforReo.dot", 0 );
52  Temp = Extra_Reorder( pReo, dd, Func, pOrder ); Cudd_Ref( Temp );
53 //Extra_DumpDot( dd, &Temp, 1, "afterReo.dot", 0 );
54 
55  Temp1 = Extra_ReorderCudd(dd, Func, NULL ); Cudd_Ref( Temp1 );
56 printf( "Initial = %d. Final = %d. Cudd = %d.\n", Cudd_DagSize(Func), Cudd_DagSize(Temp), Cudd_DagSize(Temp1) );
57  Cudd_RecursiveDeref( dd, Temp1 );
58  Cudd_RecursiveDeref( dd, Temp );
59 
60  Extra_ReorderQuit( pReo );
61 }
62 
63 
64 /**Function*************************************************************
65 
66  Synopsis [Reorders the DD using REO and CUDD.]
67 
68  Description [This function can be used to test the performance of the reordering package.]
69 
70  SideEffects []
71 
72  SeeAlso []
73 
74 ***********************************************************************/
75 void Extra_ReorderTestArray( DdManager * dd, DdNode * Funcs[], int nFuncs )
76 {
77  reo_man * pReo;
78  DdNode * FuncsRes[1000];
79  int pOrder[1000];
80  int i;
81 
82  pReo = Extra_ReorderInit( 100, 100 );
83  Extra_ReorderArray( pReo, dd, Funcs, FuncsRes, nFuncs, pOrder );
84  Extra_ReorderQuit( pReo );
85 
86 printf( "Initial = %d. Final = %d.\n", Cudd_SharingSize(Funcs,nFuncs), Cudd_SharingSize(FuncsRes,nFuncs) );
87 
88  for ( i = 0; i < nFuncs; i++ )
89  Cudd_RecursiveDeref( dd, FuncsRes[i] );
90 
91 }
92 
93 /**Function*************************************************************
94 
95  Synopsis [Reorders the DD using CUDD package.]
96 
97  Description [Transfers the DD into a temporary manager in such a way
98  that the level correspondence is preserved. Reorders the manager
99  and transfers the DD back into the original manager using the topmost
100  levels of the manager, in such a way that the ordering of levels is
101  preserved. The resulting permutation is returned in the array
102  given by the user.]
103 
104  SideEffects []
105 
106  SeeAlso []
107 
108 ***********************************************************************/
109 DdNode * Extra_ReorderCudd( DdManager * dd, DdNode * aFunc, int pPermuteReo[] )
110 {
111  static DdManager * ddReorder = NULL;
112  static int * Permute = NULL;
113  static int * PermuteReo1 = NULL;
114  static int * PermuteReo2 = NULL;
115  DdNode * aFuncReorder, * aFuncNew;
116  int lev, var;
117 
118  // start the reordering manager
119  if ( ddReorder == NULL )
120  {
121  Permute = ABC_ALLOC( int, dd->size );
122  PermuteReo1 = ABC_ALLOC( int, dd->size );
123  PermuteReo2 = ABC_ALLOC( int, dd->size );
124  ddReorder = Cudd_Init( dd->size, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
125  Cudd_AutodynDisable(ddReorder);
126  }
127 
128  // determine the permutation of variable to make sure that var order in bFunc
129  // will not change when this function is transfered into the new manager
130  for ( lev = 0; lev < dd->size; lev++ )
131  {
132  Permute[ dd->invperm[lev] ] = ddReorder->invperm[lev];
133  PermuteReo1[ ddReorder->invperm[lev] ] = dd->invperm[lev];
134  }
135  // transfer this function into the new manager in such a way that ordering of vars does not change
136  aFuncReorder = Extra_TransferPermute( dd, ddReorder, aFunc, Permute ); Cudd_Ref( aFuncReorder );
137 // assert( Cudd_DagSize(aFunc) == Cudd_DagSize(aFuncReorder) );
138 
139  // perform the reordering
140 printf( "Nodes before = %d.\n", Cudd_DagSize(aFuncReorder) );
141  Cudd_ReduceHeap( ddReorder, CUDD_REORDER_SYMM_SIFT, 1 );
142 printf( "Nodes before = %d.\n", Cudd_DagSize(aFuncReorder) );
143 
144  // determine the reverse variable permutation
145  for ( lev = 0; lev < dd->size; lev++ )
146  {
147  Permute[ ddReorder->invperm[lev] ] = dd->invperm[lev];
148  PermuteReo2[ dd->invperm[lev] ] = ddReorder->invperm[lev];
149  }
150 
151  // transfer this function into the new manager in such a way that ordering of vars does not change
152  aFuncNew = Extra_TransferPermute( ddReorder, dd, aFuncReorder, Permute ); Cudd_Ref( aFuncNew );
153 // assert( Cudd_DagSize(aFuncNew) == Cudd_DagSize(aFuncReorder) );
154  Cudd_RecursiveDeref( ddReorder, aFuncReorder );
155 
156  // derive the resulting variable ordering
157  if ( pPermuteReo )
158  for ( var = 0; var < dd->size; var++ )
159  pPermuteReo[var] = PermuteReo1[ PermuteReo2[var] ];
160 
161  Cudd_Deref( aFuncNew );
162  return aFuncNew;
163 }
164 
165 
166 /**Function*************************************************************
167 
168  Synopsis []
169 
170  Description [Transfers the BDD into another manager minimizes it and
171  returns the min number of nodes; disposes of the BDD in the new manager.
172  Useful for debugging or comparing the performance of other reordering
173  procedures.]
174 
175  SideEffects []
176 
177  SeeAlso []
178 
179 ***********************************************************************/
181 {
182  static DdManager * s_ddmin;
183  DdNode * bFmin;
184  int nNodes;
185 // abctime clk1;
186 
187  if ( s_ddmin == NULL )
188  s_ddmin = Cudd_Init( dd->size, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0);
189 
190 // Cudd_ShuffleHeap( s_ddmin, dd->invperm );
191 
192 // clk1 = Abc_Clock();
193  bFmin = Cudd_bddTransfer( dd, s_ddmin, bF ); Cudd_Ref( bFmin );
195 // Cudd_ReduceHeap(s_ddmin,CUDD_REORDER_SYMM_SIFT,1);
196  nNodes = Cudd_DagSize( bFmin );
197  Cudd_RecursiveDeref( s_ddmin, bFmin );
198 
199 // printf( "Classical variable reordering time = %.2f sec\n", (float)(Abc_Clock() - clk1)/(float)(CLOCKS_PER_SEC) );
200  return nNodes;
201 }
202 
203 /**Function*************************************************************
204 
205  Synopsis []
206 
207  Description [Transfers the ADD into another manager minimizes it and
208  returns the min number of nodes; disposes of the BDD in the new manager.
209  Useful for debugging or comparing the performance of other reordering
210  procedures.]
211 
212  SideEffects []
213 
214  SeeAlso []
215 
216 ***********************************************************************/
218 {
219  static DdManager * s_ddmin;
220  DdNode * bF;
221  DdNode * bFmin;
222  DdNode * aFmin;
223  int nNodesBeg;
224  int nNodesEnd;
225  abctime clk1;
226 
227  if ( s_ddmin == NULL )
228  s_ddmin = Cudd_Init( dd->size, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0);
229 
230 // Cudd_ShuffleHeap( s_ddmin, dd->invperm );
231 
232  clk1 = Abc_Clock();
233  bF = Cudd_addBddPattern( dd, aF ); Cudd_Ref( bF );
234  bFmin = Cudd_bddTransfer( dd, s_ddmin, bF ); Cudd_Ref( bFmin );
235  Cudd_RecursiveDeref( dd, bF );
236  aFmin = Cudd_BddToAdd( s_ddmin, bFmin ); Cudd_Ref( aFmin );
237  Cudd_RecursiveDeref( s_ddmin, bFmin );
238 
239  nNodesBeg = Cudd_DagSize( aFmin );
241 // Cudd_ReduceHeap(s_ddmin,CUDD_REORDER_SYMM_SIFT,1);
242  nNodesEnd = Cudd_DagSize( aFmin );
243  Cudd_RecursiveDeref( s_ddmin, aFmin );
244 
245  printf( "Classical reordering of ADDs: Before = %d. After = %d.\n", nNodesBeg, nNodesEnd );
246  printf( "Classical variable reordering time = %.2f sec\n", (float)(Abc_Clock() - clk1)/(float)(CLOCKS_PER_SEC) );
247  return nNodesEnd;
248 }
249 
250 
251 ////////////////////////////////////////////////////////////////////////
252 /// END OF FILE ///
253 ////////////////////////////////////////////////////////////////////////
254 
256 
#define CUDD_UNIQUE_SLOTS
Definition: cudd.h:97
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
int size
Definition: cuddInt.h:361
DdNode * Cudd_addBddPattern(DdManager *dd, DdNode *f)
Definition: cuddBridge.c:379
int var(Lit p)
Definition: SolverTypes.h:62
DdNode * Extra_Reorder(reo_man *p, DdManager *dd, DdNode *Func, int *pOrder)
Definition: reoApi.c:262
DdNode * Extra_TransferPermute(DdManager *ddSource, DdManager *ddDestination, DdNode *f, int *Permute)
Definition: extraBddMisc.c:87
#define CUDD_CACHE_SLOTS
Definition: cudd.h:98
void Extra_ReorderTestArray(DdManager *dd, DdNode *Funcs[], int nFuncs)
Definition: reoTest.c:75
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
DdNode * Extra_ReorderCudd(DdManager *dd, DdNode *aFunc, int pPermuteReo[])
Definition: reoTest.c:109
static abctime Abc_Clock()
Definition: abc_global.h:279
DdNode * Cudd_bddTransfer(DdManager *ddSource, DdManager *ddDestination, DdNode *f)
Definition: cuddBridge.c:409
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
Definition: cuddInit.c:125
void Extra_ReorderArray(reo_man *p, DdManager *dd, DdNode *Funcs[], DdNode *FuncsRes[], int nFuncs, int *pOrder)
Definition: reoApi.c:283
DdNode * Cudd_BddToAdd(DdManager *dd, DdNode *B)
Definition: cuddBridge.c:349
ABC_NAMESPACE_IMPL_START void Extra_ReorderTest(DdManager *dd, DdNode *Func)
DECLARATIONS ///.
Definition: reoTest.c:43
int Extra_addReorderTest(DdManager *dd, DdNode *aF)
Definition: reoTest.c:217
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Cudd_AutodynDisable(DdManager *unique)
Definition: cuddAPI.c:708
static DdManager * s_ddmin
Definition: casCore.c:927
reo_man * Extra_ReorderInit(int nDdVarsMax, int nNodesMax)
FUNCTION DECLARATIONS ///.
Definition: reoApi.c:50
void Extra_ReorderQuit(reo_man *p)
Definition: reoApi.c:79
int * invperm
Definition: cuddInt.h:388
int Cudd_ReduceHeap(DdManager *table, Cudd_ReorderingType heuristic, int minsize)
Definition: cuddReorder.c:176
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
ABC_INT64_T abctime
Definition: abc_global.h:278
int Cudd_SharingSize(DdNode **nodeArray, int n)
Definition: cuddUtil.c:544
int Extra_bddReorderTest(DdManager *dd, DdNode *bF)
Definition: reoTest.c:180
Definition: reo.h:101
int Cudd_DagSize(DdNode *node)
Definition: cuddUtil.c:442