devito icon indicating copy to clipboard operation
devito copied to clipboard

MPI slicing broken

Open FabioLuporini opened this issue 2 years ago • 2 comments

Reproducer

import numpy as np
from devito import Grid, Function, norm

nx =  100
ny =  100

shape   = (nx,ny)

grid = Grid(shape=shape, dtype=np.float32)
f1 = Function(name='f1', grid=grid)

f1.data[:] = f1.data[:]

Run as:

DEVITO_MPI=1 mpirun -n 4 python prova2.py

FabioLuporini avatar Mar 08 '22 13:03 FabioLuporini

The problem appears to be within the _setitem_ method when setting part/all of one Devito Function's MPI distributed Data to another Function's MPI distributed Data. Certain slicing short hands do not currently work.

In the above MFE for example f1.data[:, :] = f1.data[:] would work, as would

b = np.array(f1.data_gather())
f1.data[:]=b

This should be a one or two line fix. I previously fixed a similar bug in the _getitem_ method.

rhodrin avatar Mar 08 '22 15:03 rhodrin

Fix is under way here: https://github.com/devitocodes/devito/tree/mpi_slicing_fix

In this branch, the above MFE is fixed but below is a new failing example with -np 4:

import numpy as np
from devito import Grid, Function, norm

nx = 8
ny = 8
nz = 8
shape1 = (nx, ny)
shape2 = (nx, ny, nz)
grid1 = Grid(shape=shape1, dtype=np.float32)
grid2 = Grid(shape=shape2, dtype=np.float32)
f = Function(name='f', grid=grid1)
g = Function(name='g', grid=grid2)

dat1 = np.arange(64, dtype=np.int32).reshape(grid1.shape)
g.data[0, :, :] = dat1

f.data[:] = g.data[0, :] # Result is incorrect
f.data[:, :] = g.data[0, :] # Result is correct

The above example is more complex in that g.data[0,:] is contained on ranks 0 and 1 but needs to be distributed to ranks 0, 1, 2 and 3. The fix will probably be an extension of the patch already in place, but need to dig a little further.

rhodrin avatar Mar 25 '22 11:03 rhodrin

Fixed by https://github.com/devitocodes/devito/pull/1949

georgebisbas avatar Sep 19 '22 11:09 georgebisbas