Instantly share code, notes, and snippets.

@malb /
Last active Apr 5, 2016

What would you like to do?
Testing threading in fpylll
# -*- coding: utf-8 -*-
import argparse
from fpylll import IntegerMatrix, LLL
from multiprocessing.pool import ThreadPool as Pool
def run_it(p, f, A, prefix=""):
import sys
r = []
for i, retval in enumerate(p.imap_unordered(f, A, 1)):
sys.stderr.write('\r{0} done: {1:.2%}'.format(prefix, float(i)/len(A)))
sys.stderr.write('\r{0} done {1:.2%}\n'.format(prefix, float(i+1)/len(A)))
return r
parser = argparse.ArgumentParser("NTRU-like stuff")
parser.add_argument("-d", "--dimension", help="dimension", type=int)
parser.add_argument("-w", "--workers", help="number of worker processes", type=int)
parser.add_argument("-t", "--tasks", help="number of tasks", type=int)
args = parser.parse_args()
d = args.dimension
workers = args.workers
tasks = args.tasks
print "d: %d, workers: %d, tasks: %d"%(d, workers, tasks)
A = [IntegerMatrix.random(d, "ntrulike", bits=bits, q=q) for _ in range(tasks)]
pool = Pool(workers)
Ar = run_it(pool, LLL.reduction, A, "rot")
norms_a = [A_[0].norm() for A_ in A]
norms_r = [A_[0].norm() for A_ in Ar]
print(u"LLL(rot):: min: %12.2f, avg: %12.2f, max: %12.2f"%(min(norms_r), sum(norms_r)/tasks, max(norms_r)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment