This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
poolector.py
111 lines (93 loc) · 2.98 KB
/
poolector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python2.7
import argparse
import multiprocessing
import subprocess
import sys
import time
import signal
import os
g_result = None
DEFAULT_OPTIONS = ['--no-exit-codes', '-uc', '-br', 'fun',
'--declsort-bv-width=16',
'--simp-norm-adds']
CONFIGS = [
['-SE', 'cadical', '--fun:preprop', '--prop:nprops=10000'],
['-SE', 'cms'],
['-SE', 'lingeling'],
['-E', 'sls'],
]
def die(msg):
print('error: {}'.format(msg))
sys.exit(1)
def log(msg):
if args.verbose:
print('[poolector] {}'.format(msg))
# Spawn solver instance
def worker(i, procs):
cmd = [args.binary]
cmd.extend(DEFAULT_OPTIONS)
cmd.extend(CONFIGS[i])
cmd.append(args.benchmark)
result = 'unknown'
try:
log('{} start: {}'.format(i, ' '.join(cmd)))
start = time.time()
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
procs[i] = proc.pid
stdout, stderr = proc.communicate()
result = ''.join([stdout, stderr]).strip()
# Remove from process list since process terminated
procs[i] = 0
log('{} done: {} ({}s)'.format(i, result, time.time() - start))
except subprocess.CalledProcessError as error:
log('{} error: {}'.format(i, error.output.strip()))
except:
pass
if result in ['sat', 'unsat']:
return result
return 'unknown'
# Terminate pool processes
def terminate(result):
global g_result
if not g_result and result in ['sat', 'unsat']:
g_result = result
pool.terminate()
def parse_args():
ncpus = multiprocessing.cpu_count()
ap = argparse.ArgumentParser()
ap.add_argument('-c', dest='ncpus', type=int, default=ncpus)
ap.add_argument('-v', dest='verbose', action='store_true')
ap.add_argument('-b', dest='binary', type=str, default='./boolector')
ap.add_argument('benchmark')
return ap.parse_args()
if __name__ == '__main__':
args = parse_args()
try:
with multiprocessing.Manager() as manager:
#ncpus = min(len(CONFIGS), args.ncpus)
# TODO: for SMT-COMP only
ncpus = len(CONFIGS)
procs = manager.list([0 for i in range(ncpus)])
log('starting {} solver instances.'.format(ncpus))
pool = multiprocessing.Pool(ncpus)
for i in range(ncpus):
pool.apply_async(worker, args=(i, procs), callback=terminate)
pool.close()
pool.join()
# Kill remaining spawned solver processes
for i in range(len(procs)):
pid = procs[i]
if pid == 0:
continue
try:
os.kill(pid, signal.SIGKILL)
log('killed {} ({})'.format(i, pid))
except OSError:
log('could not kill: {}'.format(pid))
except:
pass
if g_result:
print(g_result)
else:
print('unknown')