ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cecProve.c
Go to the documentation of this file.
1
20
21#include <math.h>
22#include "aig/gia/gia.h"
23#include "aig/gia/giaAig.h"
24
25#include "sat/bmc/bmc.h"
26#include "proof/pdr/pdr.h"
27#include "proof/cec/cec.h"
28#include "proof/ssw/ssw.h"
29
30
31#ifdef ABC_USE_PTHREADS
32
33#ifdef _WIN32
34#include "../lib/pthread.h"
35#else
36#include <pthread.h>
37#include <unistd.h>
38#endif
39
40#endif
41
43
44
48
49extern int Ssw_RarSimulateGia( Gia_Man_t * p, Ssw_RarPars_t * pPars );
50extern int Bmcg_ManPerform( Gia_Man_t * pGia, Bmc_AndPar_t * pPars );
51
52#ifndef ABC_USE_PTHREADS
53
54int Cec_GiaProveTest( Gia_Man_t * p, int nProcs, int nTimeOut, int nTimeOut2, int nTimeOut3, int fVerbose, int fVeryVerbose, int fSilent ) { return -1; }
55
56#else // pthreads are used
57
61
73int Cec_GiaProveOne( Gia_Man_t * p, int iEngine, int nTimeOut, int fVerbose )
74{
75 abctime clk = Abc_Clock();
76 int RetValue = -1;
77 //abctime clkStop = nTimeOut * CLOCKS_PER_SEC + Abc_Clock();
78 if ( fVerbose )
79 printf( "Calling engine %d with timeout %d sec.\n", iEngine, nTimeOut );
80 Abc_CexFreeP( &p->pCexSeq );
81 if ( iEngine == 0 )
82 {
83 Ssw_RarPars_t Pars, * pPars = &Pars;
85 pPars->TimeOut = nTimeOut;
86 pPars->fSilent = 1;
87 RetValue = Ssw_RarSimulateGia( p, pPars );
88 }
89 else if ( iEngine == 1 )
90 {
91 Saig_ParBmc_t Pars, * pPars = &Pars;
93 pPars->nTimeOut = nTimeOut;
94 pPars->fSilent = 1;
95 Aig_Man_t * pAig = Gia_ManToAigSimple( p );
96 RetValue = Saig_ManBmcScalable( pAig, pPars );
97 p->pCexSeq = pAig->pSeqModel; pAig->pSeqModel = NULL;
98 Aig_ManStop( pAig );
99 }
100 else if ( iEngine == 2 )
101 {
102 Pdr_Par_t Pars, * pPars = &Pars;
104 pPars->nTimeOut = nTimeOut;
105 pPars->fSilent = 1;
106 Aig_Man_t * pAig = Gia_ManToAigSimple( p );
107 RetValue = Pdr_ManSolve( pAig, pPars );
108 p->pCexSeq = pAig->pSeqModel; pAig->pSeqModel = NULL;
109 Aig_ManStop( pAig );
110 }
111 else if ( iEngine == 3 )
112 {
113 Saig_ParBmc_t Pars, * pPars = &Pars;
115 pPars->fUseGlucose = 1;
116 pPars->nTimeOut = nTimeOut;
117 pPars->fSilent = 1;
118 Aig_Man_t * pAig = Gia_ManToAigSimple( p );
119 RetValue = Saig_ManBmcScalable( pAig, pPars );
120 p->pCexSeq = pAig->pSeqModel; pAig->pSeqModel = NULL;
121 Aig_ManStop( pAig );
122 }
123 else if ( iEngine == 4 )
124 {
125 Pdr_Par_t Pars, * pPars = &Pars;
127 pPars->fUseAbs = 1;
128 pPars->nTimeOut = nTimeOut;
129 pPars->fSilent = 1;
130 Aig_Man_t * pAig = Gia_ManToAigSimple( p );
131 RetValue = Pdr_ManSolve( pAig, pPars );
132 p->pCexSeq = pAig->pSeqModel; pAig->pSeqModel = NULL;
133 Aig_ManStop( pAig );
134 }
135 else if ( iEngine == 5 )
136 {
137 Bmc_AndPar_t Pars, * pPars = &Pars;
138 memset( pPars, 0, sizeof(Bmc_AndPar_t) );
139 pPars->nProcs = 1; // the number of parallel solvers
140 pPars->nFramesAdd = 1; // the number of additional frames
141 pPars->fNotVerbose = 1; // silent
142 pPars->nTimeOut = nTimeOut; // timeout in seconds
143 RetValue = Bmcg_ManPerform( p, pPars );
144 }
145 else assert( 0 );
146 //while ( Abc_Clock() < clkStop );
147 if ( fVerbose ) {
148 printf( "Engine %d finished and %ssolved the problem. ", iEngine, RetValue != -1 ? " " : "not " );
149 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
150 }
151 return RetValue;
152}
153Gia_Man_t * Cec_GiaScorrOld( Gia_Man_t * p )
154{
155 Ssw_Pars_t Pars, * pPars = &Pars;
157 Aig_Man_t * pAig = Gia_ManToAigSimple( p );
158 Aig_Man_t * pAig2 = Ssw_SignalCorrespondence( pAig, pPars );
159 Gia_Man_t * pGia2 = Gia_ManFromAigSimple( pAig2 );
160 Aig_ManStop( pAig2 );
161 Aig_ManStop( pAig );
162 return pGia2;
163}
164Gia_Man_t * Cec_GiaScorrNew( Gia_Man_t * p )
165{
166 Cec_ParCor_t Pars, * pPars = &Pars;
168 pPars->nBTLimit = 100;
169 pPars->nLevelMax = 100;
170 pPars->fVerbose = 0;
171 pPars->fUseCSat = 1;
172 return Cec_ManLSCorrespondence( p, pPars );
173}
174
186#define PAR_THR_MAX 8
187typedef struct Par_ThData_t_
188{
189 Gia_Man_t * p;
190 int iEngine;
191 int fWorking;
192 int nTimeOut;
193 int Result;
194 int fVerbose;
195} Par_ThData_t;
196void * Cec_GiaProveWorkerThread( void * pArg )
197{
198 Par_ThData_t * pThData = (Par_ThData_t *)pArg;
199 volatile int * pPlace = &pThData->fWorking;
200 while ( 1 )
201 {
202 while ( *pPlace == 0 );
203 assert( pThData->fWorking );
204 if ( pThData->p == NULL )
205 {
206 pthread_exit( NULL );
207 assert( 0 );
208 return NULL;
209 }
210 pThData->Result = Cec_GiaProveOne( pThData->p, pThData->iEngine, pThData->nTimeOut, pThData->fVerbose );
211 pThData->fWorking = 0;
212 }
213 assert( 0 );
214 return NULL;
215}
216void Cec_GiaInitThreads( Par_ThData_t * ThData, int nProcs, Gia_Man_t * p, int nTimeOut, int fVerbose, pthread_t * WorkerThread )
217{
218 int i, status;
219 assert( nProcs <= PAR_THR_MAX );
220 for ( i = 0; i < nProcs; i++ )
221 {
222 ThData[i].p = Gia_ManDup(p);
223 ThData[i].iEngine = i;
224 ThData[i].nTimeOut = nTimeOut;
225 ThData[i].fWorking = 0;
226 ThData[i].Result = -1;
227 ThData[i].fVerbose = fVerbose;
228 if ( !WorkerThread )
229 continue;
230 status = pthread_create( WorkerThread + i, NULL,Cec_GiaProveWorkerThread, (void *)(ThData + i) ); assert( status == 0 );
231 }
232 for ( i = 0; i < nProcs; i++ )
233 ThData[i].fWorking = 1;
234}
235int Cec_GiaWaitThreads( Par_ThData_t * ThData, int nProcs, Gia_Man_t * p, int RetValue, int * pRetEngine )
236{
237 int i;
238 for ( i = 0; i < nProcs; i++ )
239 {
240 if ( RetValue == -1 && !ThData[i].fWorking && ThData[i].Result != -1 ) {
241 RetValue = ThData[i].Result;
242 *pRetEngine = i;
243 if ( !p->pCexSeq && ThData[i].p->pCexSeq )
244 p->pCexSeq = Abc_CexDup( ThData[i].p->pCexSeq, -1 );
245 }
246 if ( ThData[i].fWorking )
247 i = -1;
248 }
249 return RetValue;
250}
251
252int Cec_GiaProveTest( Gia_Man_t * p, int nProcs, int nTimeOut, int nTimeOut2, int nTimeOut3, int fVerbose, int fVeryVerbose, int fSilent )
253{
254 abctime clkScorr = 0, clkTotal = Abc_Clock();
255 Par_ThData_t ThData[PAR_THR_MAX];
256 pthread_t WorkerThread[PAR_THR_MAX];
257 int i, RetValue = -1, RetEngine = -2;
258 Abc_CexFreeP( &p->pCexComb );
259 Abc_CexFreeP( &p->pCexSeq );
260 if ( !fSilent && fVerbose )
261 printf( "Solving verification problem with the following parameters:\n" );
262 if ( !fSilent && fVerbose )
263 printf( "Processes = %d TimeOut = %d sec Verbose = %d.\n", nProcs, nTimeOut, fVerbose );
264 fflush( stdout );
265
266 assert( nProcs == 3 || nProcs == 5 );
267 Cec_GiaInitThreads( ThData, nProcs, p, nTimeOut, fVerbose, WorkerThread );
268
269 // meanwhile, perform scorr
270 Gia_Man_t * pScorr = Cec_GiaScorrNew( p );
271 clkScorr = Abc_Clock() - clkTotal;
272 if ( Gia_ManAndNum(pScorr) == 0 )
273 RetValue = 1, RetEngine = -1;
274
275 RetValue = Cec_GiaWaitThreads( ThData, nProcs, p, RetValue, &RetEngine );
276 if ( RetValue == -1 )
277 {
278 abctime clkScorr2, clkStart = Abc_Clock();
279 if ( !fSilent && fVerbose ) {
280 printf( "Reduced the miter from %d to %d nodes. ", Gia_ManAndNum(p), Gia_ManAndNum(pScorr) );
281 Abc_PrintTime( 1, "Time", clkScorr );
282 }
283 Cec_GiaInitThreads( ThData, nProcs, pScorr, nTimeOut2, fVerbose, NULL );
284
285 // meanwhile, perform scorr
286 if ( Gia_ManAndNum(pScorr) < 100000 )
287 {
288 Gia_Man_t * pScorr2 = Cec_GiaScorrOld( pScorr );
289 clkScorr2 = Abc_Clock() - clkStart;
290 if ( Gia_ManAndNum(pScorr2) == 0 )
291 RetValue = 1;
292
293 RetValue = Cec_GiaWaitThreads( ThData, nProcs, p, RetValue, &RetEngine );
294 if ( RetValue == -1 )
295 {
296 if ( !fSilent && fVerbose ) {
297 printf( "Reduced the miter from %d to %d nodes. ", Gia_ManAndNum(pScorr), Gia_ManAndNum(pScorr2) );
298 Abc_PrintTime( 1, "Time", clkScorr2 );
299 }
300 Cec_GiaInitThreads( ThData, nProcs, pScorr2, nTimeOut3, fVerbose, NULL );
301
302 RetValue = Cec_GiaWaitThreads( ThData, nProcs, p, RetValue, &RetEngine );
303 // do something else
304 }
305 Gia_ManStop( pScorr2 );
306 }
307 }
308 Gia_ManStop( pScorr );
309
310 // stop threads
311 for ( i = 0; i < nProcs; i++ )
312 {
313 ThData[i].p = NULL;
314 ThData[i].fWorking = 1;
315 }
316 if ( !fSilent )
317 {
318 printf( "Problem \"%s\" is ", p->pSpec );
319 if ( RetValue == 0 )
320 printf( "SATISFIABLE (solved by %d).", RetEngine );
321 else if ( RetValue == 1 )
322 printf( "UNSATISFIABLE (solved by %d).", RetEngine );
323 else if ( RetValue == -1 )
324 printf( "UNDECIDED." );
325 else assert( 0 );
326 printf( " " );
327 Abc_PrintTime( 1, "Time", Abc_Clock() - clkTotal );
328 fflush( stdout );
329 }
330 return RetValue;
331}
332
333#endif // pthreads are used
334
338
339
341
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
#define PAR_THR_MAX
DECLARATIONS ///.
Definition bmcBmcG.c:31
void Saig_ParBmcSetDefaultParams(Saig_ParBmc_t *p)
Definition bmcBmc3.c:1334
int Saig_ManBmcScalable(Aig_Man_t *pAig, Saig_ParBmc_t *pPars)
Definition bmcBmc3.c:1461
struct Bmc_AndPar_t_ Bmc_AndPar_t
Definition bmc.h:143
struct Saig_ParBmc_t_ Saig_ParBmc_t
Definition bmc.h:105
int Cec_GiaProveTest(Gia_Man_t *p, int nProcs, int nTimeOut, int nTimeOut2, int nTimeOut3, int fVerbose, int fVeryVerbose, int fSilent)
Definition cecProve.c:54
int Bmcg_ManPerform(Gia_Man_t *pGia, Bmc_AndPar_t *pPars)
Definition bmcBmcG.c:445
ABC_NAMESPACE_IMPL_START int Ssw_RarSimulateGia(Gia_Man_t *p, Ssw_RarPars_t *pPars)
DECLARATIONS ///.
Definition sswRarity.c:1188
void Cec_ManCorSetDefaultParams(Cec_ParCor_t *p)
Definition cecCore.c:183
Gia_Man_t * Cec_ManLSCorrespondence(Gia_Man_t *pAig, Cec_ParCor_t *pPars)
Definition cecCorr.c:1179
struct Cec_ParCor_t_ Cec_ParCor_t
Definition cec.h:145
Cube * p
Definition exorList.c:222
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
Definition giaAig.c:408
Gia_Man_t * Gia_ManFromAigSimple(Aig_Man_t *p)
Definition giaAig.c:212
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
void Pdr_ManSetDefaultParams(Pdr_Par_t *pPars)
MACRO DEFINITIONS ///.
Definition pdrCore.c:50
typedefABC_NAMESPACE_HEADER_START struct Pdr_Par_t_ Pdr_Par_t
INCLUDES ///.
Definition pdr.h:40
int Pdr_ManSolve(Aig_Man_t *p, Pdr_Par_t *pPars)
Definition pdrCore.c:1765
void Ssw_ManSetDefaultParams(Ssw_Pars_t *p)
DECLARATIONS ///.
Definition sswCore.c:45
void Ssw_RarSetDefaultParams(Ssw_RarPars_t *p)
FUNCTION DEFINITIONS ///.
Definition sswRarity.c:102
struct Ssw_RarPars_t_ Ssw_RarPars_t
Definition ssw.h:94
typedefABC_NAMESPACE_HEADER_START struct Ssw_Pars_t_ Ssw_Pars_t
INCLUDES ///.
Definition ssw.h:40
Aig_Man_t * Ssw_SignalCorrespondence(Aig_Man_t *pAig, Ssw_Pars_t *pPars)
Definition sswCore.c:436
int nFramesAdd
Definition bmc.h:148
int fNotVerbose
Definition bmc.h:161
int nTimeOut
Definition bmc.h:150
int nProcs
Definition bmc.h:152
int nLevelMax
Definition cec.h:155
int fUseCSat
Definition cec.h:162
int nBTLimit
Definition cec.h:152
int fVerbose
Definition cec.h:168
int nTimeOut
Definition bmc.h:113
int fUseGlucose
Definition bmc.h:125
int fSilent
Definition bmc.h:132
int TimeOut
Definition ssw.h:103
int fSilent
Definition ssw.h:109
void Abc_CexFreeP(Abc_Cex_t **p)
Definition utilCex.c:361
Abc_Cex_t * Abc_CexDup(Abc_Cex_t *p, int nRegsNew)
Definition utilCex.c:145
#define assert(ex)
Definition util_old.h:213
char * memset()