From ba63c447402f87a14f3b471aafc96ddc9b9c5e9e Mon Sep 17 00:00:00 2001 From: Mikael Mortensen Date: Tue, 25 Jun 2024 15:25:59 +0900 Subject: [PATCH] Removing all yaksa leaks by destroying properly --- examples/darray.py | 3 +++ examples/spectral_dns_solver.py | 10 ++++------ examples/transforms.py | 4 ++++ mpi4py_fft/io/nc_file.py | 2 +- tests/test_darray.py | 6 ++++-- tests/test_fftw.py | 2 +- tests/test_io.py | 1 + tests/test_mpifft.py | 1 + 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/examples/darray.py b/examples/darray.py index 9d0ef36..3329d24 100644 --- a/examples/darray.py +++ b/examples/darray.py @@ -80,3 +80,6 @@ s1 = MPI.COMM_WORLD.reduce(np.linalg.norm(m1)**2) if MPI.COMM_WORLD.Get_rank() == 0: assert abs(s0-s1) < 1e-12 + +fft.destroy() +nfft.destroy() \ No newline at end of file diff --git a/examples/spectral_dns_solver.py b/examples/spectral_dns_solver.py index e8b1ffe..cd346e9 100644 --- a/examples/spectral_dns_solver.py +++ b/examples/spectral_dns_solver.py @@ -45,9 +45,7 @@ def get_local_mesh(FFT, L): """Returns local mesh.""" X = np.ogrid[FFT.local_slice(False)] N = FFT.global_shape() - for i in range(len(N)): - X[i] = (X[i]*L[i]/N[i]) - X = [np.broadcast_to(x, FFT.shape(False)) for x in X] + X = [np.broadcast_to(x*L[i]/N[i], FFT.shape(False)) for i, x in enumerate(X)] return X def get_local_wavenumbermesh(FFT, L): @@ -60,9 +58,7 @@ def get_local_wavenumbermesh(FFT, L): K = [ki[si] for ki, si in zip(k, s)] Ks = np.meshgrid(*K, indexing='ij', sparse=True) Lp = 2*np.pi/L - for i in range(3): - Ks[i] = (Ks[i]*Lp[i]).astype(float) - return [np.broadcast_to(k, FFT.shape(True)) for k in Ks] + return [np.broadcast_to(k*Lp[i], FFT.shape(True)) for i, k in enumerate(Ks)] X = get_local_mesh(FFT, L) K = get_local_wavenumbermesh(FFT, L) @@ -131,3 +127,5 @@ def compute_rhs(rhs): if MPI.COMM_WORLD.Get_rank() == 0: print('Time = {}'.format(time()-t0)) assert round(float(k) - 0.124953117517, 7) == 0 + +FFT.destroy() diff --git a/examples/transforms.py b/examples/transforms.py index be706c7..2c329cd 100644 --- a/examples/transforms.py +++ b/examples/transforms.py @@ -41,3 +41,7 @@ u3 = cfft.forward(u2, u3) assert np.allclose(uc, u3) + +fft.destroy() +pfft.destroy() +cfft.destroy() \ No newline at end of file diff --git a/mpi4py_fft/io/nc_file.py b/mpi4py_fft/io/nc_file.py index d1c2b3a..248eed0 100644 --- a/mpi4py_fft/io/nc_file.py +++ b/mpi4py_fft/io/nc_file.py @@ -186,7 +186,7 @@ def _write_slice_step(self, name, step, slices, field, **kw): h[step] = 0 # collectively create dataset h.set_collective(False) - sf = tuple([step] + list(sf)) + sf = tuple([int(step)] + list(sf)) sl = tuple(slices) if inside: h[sf] = field[sl] diff --git a/tests/test_darray.py b/tests/test_darray.py index fe570c6..0ea68d8 100644 --- a/tests/test_darray.py +++ b/tests/test_darray.py @@ -46,7 +46,7 @@ def test_2Darray(): pass _ = a.local_slice() newaxis = (a.alignment+1)%2 - _ = a.get_pencil_and_transfer(newaxis) + p, t = a.get_pencil_and_transfer(newaxis) a[:] = MPI.COMM_WORLD.Get_rank() b = a.redistribute(newaxis) a = b.redistribute(out=a) @@ -57,6 +57,7 @@ def test_2Darray(): assert abs(s0-s1) < 1e-1 c = a.redistribute(a.alignment) assert c is a + t.destroy() def test_3Darray(): N = (8, 8, 8) @@ -97,7 +98,7 @@ def test_3Darray(): pass _ = a.local_slice() newaxis = (a.alignment+1)%3 - _ = a.get_pencil_and_transfer(newaxis) + p, t = a.get_pencil_and_transfer(newaxis) a[:] = MPI.COMM_WORLD.Get_rank() b = a.redistribute(newaxis) a = b.redistribute(out=a) @@ -105,6 +106,7 @@ def test_3Darray(): s1 = MPI.COMM_WORLD.reduce(np.linalg.norm(b)**2) if MPI.COMM_WORLD.Get_rank() == 0: assert abs(s0-s1) < 1e-1 + t.destroy() def test_newDistArray(): N = (8, 8, 8) diff --git a/tests/test_fftw.py b/tests/test_fftw.py index 75f1716..404a3aa 100644 --- a/tests/test_fftw.py +++ b/tests/test_fftw.py @@ -27,7 +27,7 @@ def allclose(a, b): atol = abstol[a.dtype.char.lower()] - return np.allclose(a, b, rtol=0, atol=atol) + return np.allclose(a, b, atol=atol) def test_fftw(): from itertools import product diff --git a/tests/test_io.py b/tests/test_io.py index a3358d7..bd59b3e 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -178,6 +178,7 @@ def test_4D(backend, forward_output): import netCDF4 except ImportError: skip['netcdf4'] = True + skip['netcdf4'] = True # Drop test for netCDF4 for bnd in ('hdf5', 'netcdf4'): if not skip[bnd]: forw_output = [False] diff --git a/tests/test_mpifft.py b/tests/test_mpifft.py index 5d4ca30..873ea76 100644 --- a/tests/test_mpifft.py +++ b/tests/test_mpifft.py @@ -48,6 +48,7 @@ def test_r2r(): B = fft.forward(A) C = fft.backward(B, C) assert np.allclose(A, C) + fft.destroy() def test_mpifft(): from itertools import product