#!/usr/bin/env python # coding: utf-8 # In[1]: import ipyparallel as ipp rc = ipp.Client() e_all = rc[:] # Create groups of size 8 # In[91]: get_ipython().run_cell_magic('px', '', 'import mpi4py\nfrom mpi4py import MPI\n\nworld = MPI.COMM_WORLD\nworld_group = world.Get_group()\n\n# setup sub comms/groups\n\nN = 8 # number of processes per group\nmy_root = world.rank - (world.rank % N)\ngroup = world_group.Incl(range(my_root, my_root + N))\n\n# identify groups by their rank 0 root node\nmy_root = group.Translate_ranks(group, [0], world_group)[0]\n# create a comm for the group\ncomm = world.Create(group)\n"{}/{} root={}".format(group.rank, group.size, my_root)\n') # Get roots from all engines to identify the groups, and create a DirectView for each group of engines: # In[92]: roots = e_all.apply_async(lambda : my_root).get_dict() roots # In[95]: groups = {} for eid, root in roots.items(): if root not in groups: groups[root] = [] groups[root].append(eid) views = [ rc[group] for group in groups.values() ] views # Activate magics with integer suffixes for each sub-view: # In[100]: for i, view in enumerate(views): view.activate(str(i)) # In[101]: get_ipython().run_cell_magic('px0', '--block', 'print("{}/{} (world: {}/{})".format(group.rank, group.size, world.rank, world.size))\n') # In[102]: get_ipython().run_cell_magic('px1', '--block', 'print("{}/{} (world: {}/{})".format(group.rank, group.size, world.rank, world.size))\n') # In[103]: get_ipython().run_cell_magic('px', '', 'comm.rank, comm.size\n')