-
Notifications
You must be signed in to change notification settings - Fork 14
/
set-fuzzy-libmath.py
executable file
·67 lines (49 loc) · 1.96 KB
/
set-fuzzy-libmath.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
#!/usr/bin/env python3
# TODO rewrite this script in bash to avoid the python3 dependency
import argparse
import os
import textwrap
ld_preload_file = "/etc/ld.so.preload"
fuzzy_libmath_root = "/opt/mca-libmath"
versions = ["no-fuzzy", "fast", "standard", "quad", "mpfr"]
libmath_so = "libmath.so"
def switch_version(version):
try:
with open(ld_preload_file, encoding="utf-8") as fi:
current_so = fi.readline().strip().split()
except FileNotFoundError:
current_so = []
new_so = [so for so in current_so if not so.startswith(fuzzy_libmath_root)]
if version != "no-fuzzy":
new_version = os.path.join(fuzzy_libmath_root, version, libmath_so)
new_so.append(new_version)
to_write = " ".join(new_so)
with open(ld_preload_file, "w", encoding="utf-8") as fo:
fo.write(to_write)
def parse_args():
help_msg = """\
Fuzzy libmath version to use:
- no-fuzzy: Disable fuzzy libmath
- fast: Use the standard libmath available on the system.
Not possible to modify the virtual precision!
Fastest instrumentation but possibly not accurate
- standard: Use the standard libmath available on the system.
Fast instrumentation but possibly not accurate
- quad: Use the libquadmath for intermediate results.
Slower than the standard version but more accurate.
- mpfr: Use the mpfr library for intermediate results.
Slowest version but gives the correct rounding.
"""
parser = argparse.ArgumentParser(
"set-fuzzy-libmath",
formatter_class=argparse.RawTextHelpFormatter,
epilog=textwrap.dedent(help_msg),
)
parser.add_argument("--version", required=True, choices=versions, action="store")
args = parser.parse_args()
return args
def main():
args = parse_args()
switch_version(args.version)
if "__main__" == __name__:
main()