Commit 38fbc83c authored by Kirill Smelkov's avatar Kirill Smelkov

demo_zbigarray: Allow to specify work size as option

Since the beginning (1ee72371 "Demo program that shows how to work with
ZBigArrays bigger than RAM in size") the work size was 2*RAM.

However sometimes for demonstration purposes it could be handy to set it
to be even more (e.g.  16*RAM) or vise versa - to something lower.

So add command line option to do so instead of manually patching sources
every time.
parent 4228d8b6
...@@ -23,6 +23,7 @@ import transaction ...@@ -23,6 +23,7 @@ import transaction
from numpy import float64, dtype, cumsum, sin from numpy import float64, dtype, cumsum, sin
import psutil import psutil
import sys import sys
import getopt
KB = 1024 KB = 1024
MB = 1024*KB MB = 1024*KB
...@@ -68,14 +69,29 @@ def gen(signalv): ...@@ -68,14 +69,29 @@ def gen(signalv):
def usage(): def usage():
print("Usage: %s (gen|read) <dburi>" % sys.argv[0], file=sys.stderr) print(
"""Usage: %s [options] (gen|read) <dburi>
options:
--worksize=<n> generate array of size n*MB (default 2*RAM)
""" % sys.argv[0], file=sys.stderr)
sys.exit(1) sys.exit(1)
def main(): def main():
worksize = None
optv, argv = getopt.getopt(sys.argv[1:], '', ['worksize='])
for opt, v in optv:
if opt == '--worksize':
worksize = int(v) * MB
else:
usage()
try: try:
act = sys.argv[1] act = argv[0]
dburi = sys.argv[2] dburi = argv[1]
except IndexError: except IndexError:
usage() usage()
...@@ -83,13 +99,16 @@ def main(): ...@@ -83,13 +99,16 @@ def main():
usage() usage()
ram_nbytes = psutil.virtual_memory().total ram_nbytes = psutil.virtual_memory().total
print('I: RAM: %.2fGB' % (float(ram_nbytes) / GB)) print('I: RAM: %.2fGB' % (float(ram_nbytes) / GB))
root = dbopen(dburi) root = dbopen(dburi)
if act == 'gen': if act == 'gen':
if worksize is None:
worksize = 2*ram_nbytes
print('I: WORK: %.2fGB' % (float(worksize) / GB))
sig_dtype = dtype(float64) sig_dtype = dtype(float64)
sig_len = (2*ram_nbytes) // sig_dtype.itemsize sig_len = worksize // sig_dtype.itemsize
sig = ZBigArray((sig_len,), sig_dtype) sig = ZBigArray((sig_len,), sig_dtype)
root['signalv'] = sig root['signalv'] = sig
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment