Skip to content

Commit

Permalink
fixups and simplify gather
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjward committed Jan 10, 2025
1 parent 15ed39b commit 82056b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
23 changes: 4 additions & 19 deletions gusto/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,24 +985,9 @@ def gather_field_data(field, field_index, domain):
if comm.size == 1:
return field.dat.data_ro

space_name = field.function_space().name

gathered_data = comm.gather(field.dat.data_ro)
if comm.rank == 0:
# Set up array to store full data in
global_data = np.zeros(field.function_space().dim(), dtype=field.dat.dtype)

# Store data for this processor first
(start, stop) = domain.coords.parallel_array_lims[space_name]
global_data[start:stop] = field.dat.data_ro[...]

# Receive data from other processors
for rank in range(1, comm.size):
incoming_data = comm.recv(source=rank, tag=comm.size*field_index + rank)
start, stop = stop, stop + incoming_data.size
global_data[start:stop] = incoming_data

return np.concatenate(gathered_data)
else:
comm.send(field.dat.data_ro, dest=0, tag=comm.size*field_index + comm.rank)
global_data = None

return global_data
assert gathered_data is None
return None
8 changes: 4 additions & 4 deletions integration-tests/model/test_nc_outputting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from pytest_mpi import parallel_assert


def make_dirname(test_name):
def make_dirname(test_name, suffix=""):
if MPI.COMM_WORLD.size > 1:
return f'pytest_{test_name}_parallel'
return f"pytest_{test_name}_parallel" + suffix
else:
return f'pytest_{test_name}'
return f"pytest_{test_name}" + suffix


@pytest.fixture
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_nc_outputting(geometry, domain_and_mesh_details):
# ------------------------------------------------------------------------ #

# Make sure all ranks use the same file
dirname = make_dirname("nc_outputting")
dirname = make_dirname("nc_outputting", suffix=f"_{geometry}_{MPI.COMM_WORLD.size}")

domain, mesh_details = domain_and_mesh_details
V = domain.spaces('DG')
Expand Down

0 comments on commit 82056b6

Please sign in to comment.