Skip to content
Snippets Groups Projects
Commit 3636bf3b authored by EXT Jean-Matthieu Etancelin's avatar EXT Jean-Matthieu Etancelin
Browse files

add mpi support for convergence and dummy operators

parent 1466cec2
No related branches found
No related tags found
1 merge request!16MPI operators
......@@ -9,6 +9,8 @@ from hysop.tools.decorators import debug
from hysop.core.graph.graph import op_apply
from hysop.tools.numpywrappers import npw
from hysop.constants import ResidualError
import mpi4py.MPI as MPI
import numpy as np
class PythonConvergence(ConvergenceBase, HostOperator):
......@@ -17,14 +19,14 @@ class PythonConvergence(ConvergenceBase, HostOperator):
@debug
def __init__(self, **kwds):
super(PythonConvergence, self).__init__(**kwds)
assert self.mpi_params.size == 1
@debug
def setup(self, **kwds):
super(PythonConvergence, self).setup(**kwds)
self.field_buffers = self.dField.compute_buffers
self._tmp_convergence = npw.zeros((self.field.nb_components))
self._tmp_convergence = npw.zeros((self.field.nb_components),
dtype=self.convergence.dtype)
old = [npw.zeros(_.shape) for _ in self.field_buffers]
self.dField_old = tuple(old)
......@@ -38,11 +40,11 @@ class PythonConvergence(ConvergenceBase, HostOperator):
self._eps = npw.finfo(HYSOP_REAL).eps
self._large_zero = 1e3 * npw.finfo(HYSOP_REAL).eps
@op_apply
def apply(self, **kwds):
u = self.field_buffers
u_old = self.dField_old
self._tmp_convergence[...] = 0.
for (i, (ui, ui_old)) in enumerate(zip(u, u_old)):
max_ui = npw.max(npw.abs(ui))
......@@ -51,4 +53,11 @@ class PythonConvergence(ConvergenceBase, HostOperator):
else:
self._tmp_convergence[i] = self.__compute_error(ui, ui_old, max_ui)
ui_old[...] = ui
self.mpi_params.comm.Allreduce(sendbuf=self._tmp_convergence,
recvbuf=self.convergence.value,
op=MPI.MAX)
self.convergence.value = self._tmp_convergence
@classmethod
def supports_mpi(cls):
return True
......@@ -39,6 +39,9 @@ class PythonDummy(HostOperator):
super(PythonDummy, self).apply(**kwds)
# Here doing nothing
@classmethod
def supports_mpi(cls):
return True
class Dummy(ComputationalGraphNodeFrontend):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment