diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py index bbd7daf44eb84af3abaeeec0ef6d19a3d33acb59..42a9d4e124dc6506b4d17f72bd5cded9925352c5 100644 --- a/python/dune/perftool/pdelab/localoperator.py +++ b/python/dune/perftool/pdelab/localoperator.py @@ -208,8 +208,19 @@ def generate_kernel(integrals): # TODO: Use a clever strategy here, instead of random transformation until the problem is resolved from loopy import needs_iname_duplication, get_iname_duplication_options, duplicate_inames while needs_iname_duplication(kernel): - inames, within = next(get_iname_duplication_options(kernel)) - kernel = duplicate_inames(kernel, inames, within) + # If there is a duplication that solves the problem with just one duplication, we pick that one + iname, within = (None, None) + for i, w in get_iname_duplication_options(kernel): + if not needs_iname_duplication(duplicate_inames(kernel, i, w)): + iname, within = (i, w) + + # Otherwise pick a random one. + if iname is None: + iname, within = next(get_iname_duplication_options(kernel)) + + # Do the transformation + print "Applying iname duplication to measure {}: iname {}; within {}".format(measure, iname, within) + kernel = duplicate_inames(kernel, iname, within) # Loopy might have introduced some temporary variables during preprocessing. As I want to have my own # temporary declaration code right now, I call the declaration preamble manually.