Skip to content

ENH: Catch nested instances of `parallel_function`

Split from !225 (closed).

This is not a fix, more a warning for developers. The add code piece searches in the stack for multiple occurrences of parallel_function.

Example case would be:

#!/usr/bin/env python3
from __future__ import print_function
from mpi4py import MPI
from ase.parallel import parallel_function
from ase.parallel import rank


@parallel_function
def inner():
    return 'inner'

@parallel_function
def outer():
    out_list = ['outer']
    for _ in range(5):
        out_list.append(inner())
    return out_list

@parallel_function
def second():
    return 'next'

result = outer()

print(rank, ":", result)
print(rank, ":", second())

Which produces (for mpi-implementation where broadcast is non-blocking on the root process):

$ mpirun -np 2 python3.4 pf_test.py
0 : ['outer', 'inner', 'inner', 'inner', 'inner', 'inner']
0 : next
1 : inner
1 : inner

Merge request reports