Too many communicators error
Function here can cause Too many communicators error
.
Because This line of code simple change fft object without destroying it.
Code below may fix it.
def get_mpi4py_fft(comm, nr, decomposition = 'Slab', backend = None, grid = None, max_saved = 10, cplx = False, **kwargs):
"""
Note :
'max_saved' means the number of fft objects saved. It should be manual release. see MP.free()
"""
fft_support = ['pyfftw', 'numpy','scipy', 'mkl_fft']
# fft_support = ['fftw', 'pyfftw', 'numpy','scipy', 'mkl_fft']
if backend not in fft_support :
backend = environ["FFTLIB"]
if backend not in fft_support :
backend = 'numpy'
if cplx :
backend = 'numpy' # If cplx, use numpy for safe
dtype = np.complex
else :
dtype = np.float
global fft_saved
saved = 0
item = fft_saved.get(tuple(nr), None)
if item is not None and item.global_shape() == tuple(nr):
saved = 1
saved = comm.allreduce(saved, op=MPI.MIN)
if saved :
fft = fft_saved[tuple(nr)]
else :
if decomposition == 'Slab' :
fft = PFFT(comm, nr, axes=(0, 1, 2), dtype=dtype, grid=(-1,), backend = backend)
else :
fft = PFFT(comm, nr, axes=(0, 1, 2), dtype=dtype, backend = backend)
if len(fft_saved) >= max_saved :
for key in fft_saved :
delfft = fft_saved.pop(key)
delfft.destroy()
break
fft_saved[tuple(nr)] = fft
return fft