Skip to content

Commit 8bbdb8e

Browse files
committed
api: fixup complex dtype handling for mpi
1 parent 3f5eb5f commit 8bbdb8e

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

devito/passes/iet/engine.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,13 @@ def wrapper(*args, **kwargs):
259259
try:
260260
# Pure function case
261261
graph, = args
262-
return maybe_timed(call(graph), func.__name__)(func, **kwargs)
262+
ietfunc = func
263263
except ValueError:
264264
# Instance method case
265265
self, graph = args
266-
return maybe_timed(call(graph), func.__name__)(partial(func, self), **kwargs)
266+
ietfunc = partial(func, self)
267+
268+
return maybe_timed(call(graph), func.__name__)(ietfunc, **kwargs)
267269

268270
return wrapper
269271

devito/tools/dtypes_lowering.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
dtype_mapper = {
2727
"int": np.int32,
2828
"float": np.float32,
29-
"double": np.float64
29+
"double": np.float64,
30+
"cfloat": np.complex64,
31+
"cdouble": np.complex128
3032
}
3133

3234

@@ -238,7 +240,11 @@ class c_restrict_void_p(ctypes.c_void_p):
238240

239241
ctypes_vector_mapper = {}
240242
for base_name, base_dtype in dtype_mapper.items():
241-
base_ctype = dtype_to_ctype(base_dtype)
243+
try:
244+
base_ctype = dtype_to_ctype(base_dtype)
245+
except NotImplementedError:
246+
# E.g., np.complex64
247+
continue
242248

243249
for count in counts:
244250
dtype = dtypes_vector_mapper[(base_dtype, count)]
@@ -250,7 +256,6 @@ class c_restrict_void_p(ctypes.c_void_p):
250256

251257
ctypes_vector_mapper[dtype] = ctype
252258

253-
254259
# *** ctypes lowering
255260

256261

tests/test_mpi.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,19 +2067,24 @@ def test_merge_smart_if_within_conditional(self, mode):
20672067
for n in FindNodes(Conditional).visit(op1):
20682068
assert len(FindNodes(HaloUpdateCall).visit(n)) == 0
20692069

2070+
@pytest.mark.parametrize('dtype', [np.float32, np.complex64])
20702071
@pytest.mark.parallel(mode=2)
2071-
def test_allreduce_time(self, mode):
2072+
def test_allreduce_time(self, dtype, mode):
20722073
space_order = 8
20732074
nx, ny = 11, 11
20742075

20752076
grid = Grid(shape=(nx, ny))
20762077
tt = grid.time_dim
20772078
nt = 10
20782079

2079-
ux = TimeFunction(name="ux", grid=grid, time_order=1, space_order=space_order)
2080-
g = TimeFunction(name="g", grid=grid, dimensions=(tt, ), shape=(nt,))
2080+
c = tt if dtype == np.float32 else tt + tt * 1j
2081+
2082+
ux = TimeFunction(name="ux", grid=grid, time_order=1, space_order=space_order,
2083+
dtype=dtype)
2084+
g = TimeFunction(name="g", grid=grid, dimensions=(tt, ), shape=(nt,),
2085+
dtype=dtype)
20812086

2082-
op = Operator([Eq(ux.forward, ux + tt), Inc(g, ux)], name="Op")
2087+
op = Operator([Eq(ux.forward, ux + c), Inc(g, ux)], name="Op")
20832088
assert_structure(op, ['t,x,y', 't'], 'txy')
20842089

20852090
# Reduce should be in time loop but not in space loop
@@ -2091,7 +2096,10 @@ def test_allreduce_time(self, mode):
20912096
assert len(FindNodes(Call).visit(i)) == 0
20922097

20932098
op.apply(time_m=0, time_M=nt-1)
2094-
assert np.isclose(np.max(g.data), 4356.0)
2099+
if dtype == np.float32:
2100+
assert np.isclose(np.max(g.data), 4356.0)
2101+
else:
2102+
assert np.isclose(np.max(g.data), 4356.0 + 4356.0j)
20952103

20962104
@pytest.mark.parallel(mode=2)
20972105
def test_multi_allreduce_time(self, mode):

0 commit comments

Comments
 (0)