summaryrefslogtreecommitdiffstats
path: root/src/misc
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2013-05-27 15:09:23 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2013-05-27 15:09:23 -0700
commit19c25fd6aab057b2373717f996fe538507c1b1e1 (patch)
tree7aa7cd7609a5de31d11b3455b6388fd9300c8d0f /src/misc
parent94356f0d1fa8e671303299717f631ecf0ca2f17e (diff)
downloadabc-19c25fd6aab057b2373717f996fe538507c1b1e1.tar.gz
abc-19c25fd6aab057b2373717f996fe538507c1b1e1.tar.bz2
abc-19c25fd6aab057b2373717f996fe538507c1b1e1.zip
Adding a wrapper around clock() for more accurate time counting in ABC.
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/extra/extra.h2
-rw-r--r--src/misc/extra/extraBddCas.c10
-rw-r--r--src/misc/extra/extraBddMisc.c18
-rw-r--r--src/misc/extra/extraBddTime.c10
-rw-r--r--src/misc/extra/extraUtilMisc.c4
-rw-r--r--src/misc/extra/extraUtilUtil.c6
-rw-r--r--src/misc/nm/nmTable.c6
-rw-r--r--src/misc/util/abc_global.h42
-rw-r--r--src/misc/util/utilNam.c4
-rw-r--r--src/misc/util/utilSort.c26
-rw-r--r--src/misc/util/util_hack.h2
11 files changed, 74 insertions, 56 deletions
diff --git a/src/misc/extra/extra.h b/src/misc/extra/extra.h
index c3c9a93d..28156486 100644
--- a/src/misc/extra/extra.h
+++ b/src/misc/extra/extra.h
@@ -373,7 +373,7 @@ extern unsigned Extra_TruthSemiCanonicize( unsigned * pInOut, unsigned * pAux
/*=== extraUtilUtil.c ================================================================*/
-extern clock_t Extra_CpuTime();
+extern abctime Extra_CpuTime();
extern double Extra_CpuTimeDouble();
extern int Extra_GetSoftDataLimit();
extern ABC_DLL void Extra_UtilGetoptReset();
diff --git a/src/misc/extra/extraBddCas.c b/src/misc/extra/extraBddCas.c
index b745d306..024e4462 100644
--- a/src/misc/extra/extraBddCas.c
+++ b/src/misc/extra/extraBddCas.c
@@ -192,7 +192,7 @@ Extra_bddEncodingNonStrict(
{
DdNode * bEncoded, * bResult;
int nVarsCol = Cudd_SupportSize(dd,bVarsCol);
- clock_t clk;
+ abctime clk;
// cannot work with more that 32-bit codes
assert( nMulti < 32 );
@@ -221,19 +221,19 @@ Extra_bddEncodingNonStrict(
s_MultiStart = nMulti;
- clk = clock();
+ clk = Abc_Clock();
// find the simplest encoding
if ( nColumns > 2 )
EvaluateEncodings_rec( dd, bVarsCol, nVarsCol, nMulti, 1 );
// printf( "The number of backtracks = %d\n", s_BackTracks );
-// s_EncSearchTime += clock() - clk;
+// s_EncSearchTime += Abc_Clock() - clk;
// allocate the temporary storage for the columns
s_pbTemp = (DdNode **)ABC_ALLOC( char, nColumns * sizeof(DdNode *) );
-// clk = clock();
+// clk = Abc_Clock();
bResult = CreateTheCodes_rec( dd, bEncoded, 0, pCVars ); Cudd_Ref( bResult );
-// s_EncComputeTime += clock() - clk;
+// s_EncComputeTime += Abc_Clock() - clk;
// delocate the preliminarily encoded set
Cudd_RecursiveDeref( dd, bEncoded );
diff --git a/src/misc/extra/extraBddMisc.c b/src/misc/extra/extraBddMisc.c
index 6575f7b0..7d9c26d5 100644
--- a/src/misc/extra/extraBddMisc.c
+++ b/src/misc/extra/extraBddMisc.c
@@ -1348,9 +1348,9 @@ extraTransferPermuteRecur(
if ( st__lookup( table, ( char * ) f, ( char ** ) &res ) )
return ( Cudd_NotCond( res, comple ) );
- if ( ddS->TimeStop && clock() > ddS->TimeStop )
+ if ( ddS->TimeStop && Abc_Clock() > ddS->TimeStop )
return NULL;
- if ( ddD->TimeStop && clock() > ddD->TimeStop )
+ if ( ddD->TimeStop && Abc_Clock() > ddD->TimeStop )
return NULL;
/* Recursive step. */
@@ -1909,9 +1909,9 @@ DdNode * extraBddAndPermute( DdHashTable * table, DdManager * ddF, DdNode * bF,
return bRes;
Counter++;
- if ( ddF->TimeStop && clock() > ddF->TimeStop )
+ if ( ddF->TimeStop && Abc_Clock() > ddF->TimeStop )
return NULL;
- if ( ddG->TimeStop && clock() > ddG->TimeStop )
+ if ( ddG->TimeStop && Abc_Clock() > ddG->TimeStop )
return NULL;
// find the topmost variable in F and G using var order of F
@@ -1982,7 +1982,7 @@ void Extra_TestAndPerm( DdManager * ddF, DdNode * bF, DdNode * bG )
{
DdManager * ddG;
DdNode * bG2, * bRes1, * bRes2;
- clock_t clk;
+ abctime clk;
// disable variable ordering in ddF
Cudd_AutodynDisable( ddF );
@@ -1995,15 +1995,15 @@ void Extra_TestAndPerm( DdManager * ddF, DdNode * bF, DdNode * bG )
Cudd_ReduceHeap( ddG, CUDD_REORDER_SYMM_SIFT, 1 );
// compute the result
-clk = clock();
+clk = Abc_Clock();
bRes1 = Cudd_bddAnd( ddF, bF, bG ); Cudd_Ref( bRes1 );
-Abc_PrintTime( 1, "Runtime of Cudd_bddAnd ", clock() - clk );
+Abc_PrintTime( 1, "Runtime of Cudd_bddAnd ", Abc_Clock() - clk );
// compute the result
Counter = 0;
-clk = clock();
+clk = Abc_Clock();
bRes2 = Extra_bddAndPermute( ddF, bF, ddG, bG2, NULL ); Cudd_Ref( bRes2 );
-Abc_PrintTime( 1, "Runtime of new procedure", clock() - clk );
+Abc_PrintTime( 1, "Runtime of new procedure", Abc_Clock() - clk );
printf( "Recursive calls = %d\n", Counter );
printf( "|F| =%6d |G| =%6d |H| =%6d |F|*|G| =%9d ",
Cudd_DagSize(bF), Cudd_DagSize(bG), Cudd_DagSize(bRes2),
diff --git a/src/misc/extra/extraBddTime.c b/src/misc/extra/extraBddTime.c
index 0f4d238d..dc9ff147 100644
--- a/src/misc/extra/extraBddTime.c
+++ b/src/misc/extra/extraBddTime.c
@@ -224,8 +224,8 @@ cuddBddAndRecurTime(
if (r != NULL) return(r);
}
-// if ( TimeOut && ((*pRecCalls)++ % CHECK_FACTOR) == 0 && TimeOut < clock() )
- if ( TimeOut && clock() > TimeOut )
+// if ( TimeOut && ((*pRecCalls)++ % CHECK_FACTOR) == 0 && TimeOut < Abc_Clock() )
+ if ( TimeOut && Abc_Clock() > TimeOut )
return NULL;
/* Here we can skip the use of cuddI, because the operands are known
@@ -378,8 +378,8 @@ cuddBddAndAbstractRecurTime(
}
}
-// if ( TimeOut && ((*pRecCalls)++ % CHECK_FACTOR) == 0 && TimeOut < clock() )
- if ( TimeOut && clock() > TimeOut )
+// if ( TimeOut && ((*pRecCalls)++ % CHECK_FACTOR) == 0 && TimeOut < Abc_Clock() )
+ if ( TimeOut && Abc_Clock() > TimeOut )
return NULL;
if (topf == top) {
@@ -596,7 +596,7 @@ extraTransferPermuteRecurTime(
if ( st__lookup( table, ( char * ) f, ( char ** ) &res ) )
return ( Cudd_NotCond( res, comple ) );
- if ( TimeOut && clock() > TimeOut )
+ if ( TimeOut && Abc_Clock() > TimeOut )
return NULL;
/* Recursive step. */
diff --git a/src/misc/extra/extraUtilMisc.c b/src/misc/extra/extraUtilMisc.c
index 3498abf7..51bd887e 100644
--- a/src/misc/extra/extraUtilMisc.c
+++ b/src/misc/extra/extraUtilMisc.c
@@ -2480,7 +2480,7 @@ void Extra_NpnTest()
// int nFuncs = 5687661;
// int nFuncs = 400777;
int nFuncs = 10;
- clock_t clk = clock();
+ abctime clk = Abc_Clock();
word * pFuncs;
int * pComp, * pPerm;
int i;//, k, nUnique = 0;
@@ -2528,7 +2528,7 @@ void Extra_NpnTest()
ABC_FREE( pPerm );
ABC_FREE( pComp );
ABC_FREE( pFuncs );
- Abc_PrintTime( 1, "Time", clock() - clk );
+ Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
}
diff --git a/src/misc/extra/extraUtilUtil.c b/src/misc/extra/extraUtilUtil.c
index 7f19480c..253d9e3c 100644
--- a/src/misc/extra/extraUtilUtil.c
+++ b/src/misc/extra/extraUtilUtil.c
@@ -347,9 +347,9 @@ void (*Extra_UtilMMoutOfMemory)( long size ) = (void (*)( long size ))Extra_Util
SeeAlso []
***********************************************************************/
-clock_t Extra_CpuTime()
+abctime Extra_CpuTime()
{
- return clock();
+ return Abc_Clock();
}
/**Function*************************************************************
@@ -366,7 +366,7 @@ clock_t Extra_CpuTime()
#if defined(NT) || defined(NT64) || defined(WIN32)
double Extra_CpuTimeDouble()
{
- return 1.0*clock()/CLOCKS_PER_SEC;
+ return 1.0*Abc_Clock()/CLOCKS_PER_SEC;
}
#else
diff --git a/src/misc/nm/nmTable.c b/src/misc/nm/nmTable.c
index 1a792242..5fab82d3 100644
--- a/src/misc/nm/nmTable.c
+++ b/src/misc/nm/nmTable.c
@@ -257,9 +257,9 @@ void Nm_ManResize( Nm_Man_t * p )
{
Nm_Entry_t ** pBinsNewI2N, ** pBinsNewN2I, * pEntry, * pEntry2, ** ppSpot;
int nBinsNew, Counter, e;
- clock_t clk;
+ abctime clk;
-clk = clock();
+clk = Abc_Clock();
// get the new table size
nBinsNew = Abc_PrimeCudd( p->nGrowthFactor * p->nBins );
// allocate a new array
@@ -289,7 +289,7 @@ clk = clock();
}
assert( Counter == p->nEntries );
// printf( "Increasing the structural table size from %6d to %6d. ", p->nBins, nBinsNew );
-// ABC_PRT( "Time", clock() - clk );
+// ABC_PRT( "Time", Abc_Clock() - clk );
// replace the table and the parameters
ABC_FREE( p->pBinsI2N );
ABC_FREE( p->pBinsN2I );
diff --git a/src/misc/util/abc_global.h b/src/misc/util/abc_global.h
index 914fd327..f824ea43 100644
--- a/src/misc/util/abc_global.h
+++ b/src/misc/util/abc_global.h
@@ -266,25 +266,43 @@ static inline int Abc_LitRegular( int Lit ) { return Lit & ~01
static inline int Abc_Lit2LitV( int * pMap, int Lit ) { return Abc_Var2Lit( pMap[Abc_Lit2Var(Lit)], Abc_LitIsCompl(Lit) ); }
static inline int Abc_Lit2LitL( int * pMap, int Lit ) { return Abc_LitNotCond( pMap[Abc_Lit2Var(Lit)], Abc_LitIsCompl(Lit) ); }
-enum Abc_VerbLevel
+
+// time counting
+typedef ABC_UINT64_T abctime;
+static inline abctime Abc_Clock()
{
- ABC_PROMPT = -2,
- ABC_ERROR = -1,
- ABC_WARNING = 0,
- ABC_STANDARD = 1,
- ABC_VERBOSE = 2
-};
+ static abctime PeriodNum = 0;
+ static clock_t Period = ((abctime)1 << 30);
+ clock_t ClockTime = clock();
+ if ( ClockTime >= Period )
+ {
+ ClockTime -= Period;
+ PeriodNum++;
+ }
+ return PeriodNum * Period + ClockTime;
+}
+
+// bridge communication
#define BRIDGE_NETLIST 106
#define BRIDGE_ABS_NETLIST 107
+extern int Gia_ManToBridgeText( FILE * pFile, int Size, unsigned char * pBuffer );
+extern int Gia_ManToBridgeAbsNetlist( FILE * pFile, void * p, int pkg_type );
// string printing
extern char * vnsprintf(const char* format, va_list args);
extern char * nsprintf(const char* format, ...);
-extern int Gia_ManToBridgeText( FILE * pFile, int Size, unsigned char * pBuffer );
-extern int Gia_ManToBridgeAbsNetlist( FILE * pFile, void * p, int pkg_type );
+
// misc printing procedures
+enum Abc_VerbLevel
+{
+ ABC_PROMPT = -2,
+ ABC_ERROR = -1,
+ ABC_WARNING = 0,
+ ABC_STANDARD = 1,
+ ABC_VERBOSE = 2
+};
static inline void Abc_Print( int level, const char * format, ... )
{
extern ABC_DLL int Abc_FrameIsBridgeMode();
@@ -339,12 +357,12 @@ static inline void Abc_PrintInt( int i )
Abc_Print( 1, "%4.0fm", v6 );
}
-static inline void Abc_PrintTime( int level, const char * pStr, clock_t time )
+static inline void Abc_PrintTime( int level, const char * pStr, abctime time )
{
ABC_PRT( pStr, time );
}
-static inline void Abc_PrintTimeP( int level, const char * pStr, clock_t time, clock_t Time )
+static inline void Abc_PrintTimeP( int level, const char * pStr, abctime time, abctime Time )
{
ABC_PRTP( pStr, time, Time );
}
@@ -381,6 +399,7 @@ static inline int Abc_PrimeCudd( unsigned int p )
} // end of Cudd_Prime
+
// sorting
extern void Abc_MergeSort( int * pInput, int nSize );
extern int * Abc_MergeSortCost( int * pCosts, int nSize );
@@ -391,7 +410,6 @@ extern void Abc_QuickSortCostData( int * pCosts, int nSize, int fDecrease, wor
extern int * Abc_QuickSortCost( int * pCosts, int nSize, int fDecrease );
-
ABC_NAMESPACE_HEADER_END
#endif
diff --git a/src/misc/util/utilNam.c b/src/misc/util/utilNam.c
index ccea6322..5fb38c51 100644
--- a/src/misc/util/utilNam.c
+++ b/src/misc/util/utilNam.c
@@ -302,7 +302,7 @@ void Abc_NamStrHashResize( Abc_Nam_t * p )
{
Vec_Int_t * vInt2HandleOld;
char * pThis;
- int * piPlace, * pBinsOld, iHandleOld, i;//, clk = clock();
+ int * piPlace, * pBinsOld, iHandleOld, i;//, clk = Abc_Clock();
assert( p->pBins != NULL );
// Abc_Print( 1, "Resizing names manager hash table from %6d to %6d. ", p->nBins, Abc_PrimeCudd( 3 * p->nBins ) );
// replace the table
@@ -327,7 +327,7 @@ void Abc_NamStrHashResize( Abc_Nam_t * p )
}
Vec_IntFree( vInt2HandleOld );
ABC_FREE( pBinsOld );
-// Abc_PrintTime( 1, "Time", clock() - clk );
+// Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
}
/**Function*************************************************************
diff --git a/src/misc/util/utilSort.c b/src/misc/util/utilSort.c
index 48321c9f..4dca700c 100644
--- a/src/misc/util/utilSort.c
+++ b/src/misc/util/utilSort.c
@@ -401,7 +401,7 @@ void Abc_SortTest()
int i, nSize = 50000000;
int * pArray = (int *)malloc( sizeof(int) * nSize );
int * pPerm;
- clock_t clk;
+ abctime clk;
// generate numbers
srand( 1000 );
for ( i = 0; i < nSize; i++ )
@@ -413,9 +413,9 @@ void Abc_SortTest()
int fUseCost = 1;
if ( fUseCost )
{
- clk = clock();
+ clk = Abc_Clock();
pPerm = Abc_MergeSortCost( pArray, nSize );
- Abc_PrintTime( 1, "New sort", clock() - clk );
+ Abc_PrintTime( 1, "New sort", Abc_Clock() - clk );
// check
for ( i = 1; i < nSize; i++ )
assert( pArray[pPerm[i-1]] <= pArray[pPerm[i]] );
@@ -423,9 +423,9 @@ void Abc_SortTest()
}
else
{
- clk = clock();
+ clk = Abc_Clock();
Abc_MergeSort( pArray, nSize );
- Abc_PrintTime( 1, "New sort", clock() - clk );
+ Abc_PrintTime( 1, "New sort", Abc_Clock() - clk );
// check
for ( i = 1; i < nSize; i++ )
assert( pArray[i-1] <= pArray[i] );
@@ -433,9 +433,9 @@ void Abc_SortTest()
}
else
{
- clk = clock();
+ clk = Abc_Clock();
qsort( (void *)pArray, nSize, sizeof(int), (int (*)(const void *, const void *)) Abc_SortNumCompare );
- Abc_PrintTime( 1, "Old sort", clock() - clk );
+ Abc_PrintTime( 1, "Old sort", Abc_Clock() - clk );
// check
for ( i = 1; i < nSize; i++ )
assert( pArray[i-1] <= pArray[i] );
@@ -745,18 +745,18 @@ void Abc_QuickSortTest()
int fVerbose = 0;
word * pData1, * pData2;
int i;
- clock_t clk = clock();
+ abctime clk = Abc_Clock();
// generate numbers
pData1 = ABC_ALLOC( word, nSize );
pData2 = ABC_ALLOC( word, nSize );
srand( 1111 );
for ( i = 0; i < nSize; i++ )
pData2[i] = pData1[i] = ((word)i << 32) | rand();
- Abc_PrintTime( 1, "Prepare ", clock() - clk );
+ Abc_PrintTime( 1, "Prepare ", Abc_Clock() - clk );
// perform sorting
- clk = clock();
+ clk = Abc_Clock();
Abc_QuickSort3( pData1, nSize, 1 );
- Abc_PrintTime( 1, "Sort new", clock() - clk );
+ Abc_PrintTime( 1, "Sort new", Abc_Clock() - clk );
// print the result
if ( fVerbose )
{
@@ -765,9 +765,9 @@ void Abc_QuickSortTest()
printf( "\n" );
}
// create new numbers
- clk = clock();
+ clk = Abc_Clock();
Abc_QuickSort1( pData2, nSize, 1 );
- Abc_PrintTime( 1, "Sort old", clock() - clk );
+ Abc_PrintTime( 1, "Sort old", Abc_Clock() - clk );
// print the result
if ( fVerbose )
{
diff --git a/src/misc/util/util_hack.h b/src/misc/util/util_hack.h
index 4d611ef4..cbbb7c2d 100644
--- a/src/misc/util/util_hack.h
+++ b/src/misc/util/util_hack.h
@@ -37,7 +37,7 @@ ABC_NAMESPACE_HEADER_START
#define getSoftDataLimit Extra_GetSoftDataLimit
#define MMoutOfMemory Extra_UtilMMoutOfMemory
-extern clock_t Extra_CpuTime();
+extern abctime Extra_CpuTime();
extern int Extra_GetSoftDataLimit();
extern void (*Extra_UtilMMoutOfMemory)( long size );