Skip to content

Commit

Permalink
TL: added second MPI implementation for parallel SDC
Browse files Browse the repository at this point in the history
  • Loading branch information
tlunet committed Jan 3, 2025
1 parent 4f18b6b commit 83d5dbc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pySDC/playgrounds/dedalus/sdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,47 @@ def step(self, dt, wall_time):
# Only last rank (i.e node) will be allowed to (eventually) write outputs
if self.rank != self.M-1:
self.firstEval = False


class SDCIMEX_MPI2(SDCIMEX_MPI):

def _broadcastState(self):
state = self.solver.state
sizes = [f.data.size for f in state]
buffer = np.empty(sum(sizes), dtype=state[0].data.dtype)
rank, M = self.rank, self.M

if rank == M-1: # copy last rank state into buffer
pos = 0
for f, size in zip(state, sizes):
np.copyto(buffer[pos:size], f.data.flat)
pos += size

self.comm.Bcast(buffer, root=self.M-1)

if rank != M-1: # copy buffer data into state
pos = 0
for f, size in zip(state, sizes):
np.copyto(f.data, buffer[pos:size].reshape(f.data.shape))
pos += size

def _computeMX0(self, MX0:CoeffSystem):
"""
Compute MX0 term used in RHS of both initStep and sweep methods
Update the MX0 attribute of the timestepper object.
"""
super(SDCIMEX_MPI, self)._computeMX0(MX0)

def _initSweep(self):
t0, dt, wall_time = self.solver.sim_time, self.dt, self.wall_time
Fk, LXk = self.F[0], self.LX[0]
if self.initSweep == 'COPY':
self._evalLX(LXk)
self._evalF(Fk, t0, dt, wall_time)
else:
raise NotImplementedError()

def step(self, dt, wall_time):
super().step(dt, wall_time)
self._broadcastState()

0 comments on commit 83d5dbc

Please sign in to comment.