Skip to content

Commit

Permalink
removed setting of distributed metadata to False if nprocs==1
Browse files Browse the repository at this point in the history
  • Loading branch information
naylor-b committed Feb 14, 2024
1 parent eb6f053 commit b3fd91a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
4 changes: 0 additions & 4 deletions openmdao/core/component.py
Expand Up @@ -200,10 +200,6 @@ def _setup_procs(self, pathname, comm, mode, prob_meta):
self._has_distrib_vars = self._has_distrib_outputs = False

for meta in self._static_var_rel2meta.values():
# variable isn't distributed if we're only running on 1 proc
if nprocs == 1 and 'distributed' in meta and meta['distributed']:
meta['distributed'] = False

# reset shape if any dynamic shape parameters are set in case this is a resetup
# NOTE: this is necessary because we allow variables to be added in __init__.
if 'shape_by_conn' in meta and (meta['shape_by_conn'] or
Expand Down
49 changes: 49 additions & 0 deletions openmdao/core/tests/test_distribcomp.py
Expand Up @@ -1091,6 +1091,55 @@ def compute(self, inputs, outputs):
assert_near_equal(p.get_val('C1.y', get_remote=False), 6. if p.model.C1.comm.rank == 0 else 14.)


@unittest.skipUnless(MPI and PETScVector, "MPI and PETSc are required.")
class TestDistribCheckMPI(unittest.TestCase):
N_PROCS = 2

def test_distrib_conn_check(self):
class Serial2Distributed(om.ExplicitComponent):
def setup(self):
self.add_input("serial_in", shape=3)

if self.comm.rank == 0:
self.add_output("dist_out", shape=3, distributed=True)
else:
self.add_output("dist_out", shape=0, distributed=True)

def compute(self, inputs, outputs):
if self.comm.rank == 0:
outputs["dist_out"] = inputs["serial_in"]

class DistributedSum(om.ExplicitComponent):
def setup(self):
self.add_output("sum", shape=1)

def compute(self, inputs, outputs):
outputs["sum"] = self.comm.bcast(sum(inputs["dist_in"]), root=0)

class SumGroup(om.Group):
def setup(self):
self.add_subsystem("s2d", Serial2Distributed(), promotes_inputs=[("serial_in", "in")])
self.add_subsystem("sum", DistributedSum(), promotes_outputs=["sum"])
self.sum.add_input("dist_in", shape_by_conn=True, distributed=True)
self.connect("s2d.dist_out", "sum.dist_in")

prob = om.Problem()
model = prob.model

model.add_subsystem("ivc", om.IndepVarComp("x", [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]))
parallel = model.add_subsystem('parallel', om.ParallelGroup())
parallel.add_subsystem('sum1', SumGroup())
parallel.add_subsystem('sum2', SumGroup())

model.connect("ivc.x", "parallel.sum1.in", src_indices=om.slicer[:3])
model.connect("ivc.x", "parallel.sum2.in", src_indices=om.slicer[3:])

prob.setup()
prob.run_model()

assert_near_equal(prob.get_val("parallel.sum1.sum", get_remote=True), 3.0)
assert_near_equal(prob.get_val("parallel.sum2.sum", get_remote=True), 12.0)

if __name__ == '__main__':
from openmdao.utils.mpi import mpirun_tests
mpirun_tests()

0 comments on commit b3fd91a

Please sign in to comment.