From 46d2fba2df22558fa476db38a31b446f1b40fbe4 Mon Sep 17 00:00:00 2001
From: Kaushik Kulkarni <kaushikcfd@gmail.com>
Date: Fri, 25 Jun 2021 18:32:32 -0500
Subject: [PATCH] numpyify scalars before calling MPI-reduce on them

---
 grudge/reductions.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/grudge/reductions.py b/grudge/reductions.py
index 026f76d3..869cebd7 100644
--- a/grudge/reductions.py
+++ b/grudge/reductions.py
@@ -143,8 +143,9 @@ def nodal_sum(dcoll: DiscretizationCollection, dd, vec) -> float:
 
     # NOTE: Don't move this
     from mpi4py import MPI
+    actx = vec.array_context
 
-    return comm.allreduce(nodal_sum_loc(dcoll, dd, vec), op=MPI.SUM)
+    return comm.allreduce(actx.to_numpy(nodal_sum_loc(dcoll, dd, vec)), op=MPI.SUM)
 
 
 def nodal_sum_loc(dcoll: DiscretizationCollection, dd, vec) -> float:
@@ -177,8 +178,9 @@ def nodal_min(dcoll: DiscretizationCollection, dd, vec) -> float:
 
     # NOTE: Don't move this
     from mpi4py import MPI
+    actx = vec.array_context
 
-    return comm.allreduce(nodal_min_loc(dcoll, dd, vec), op=MPI.MIN)
+    return comm.allreduce(actx.to_numpy(nodal_min_loc(dcoll, dd, vec)), op=MPI.MIN)
 
 
 def nodal_min_loc(dcoll: DiscretizationCollection, dd, vec) -> float:
@@ -213,8 +215,9 @@ def nodal_max(dcoll: DiscretizationCollection, dd, vec) -> float:
 
     # NOTE: Don't move this
     from mpi4py import MPI
+    actx = vec.array_context
 
-    return comm.allreduce(nodal_max_loc(dcoll, dd, vec), op=MPI.MAX)
+    return comm.allreduce(actx.to_numpy(nodal_max_loc(dcoll, dd, vec)), op=MPI.MAX)
 
 
 def nodal_max_loc(dcoll: DiscretizationCollection, dd, vec) -> float:
-- 
GitLab