structopt.tools

structopt.tools.parallel.root(method=None, broadcast=True)

A decorator to make the function only run on the root node. The returned data from the root is then broadcast to all the other nodes and each node returns the root’s data.

structopt.tools.parallel.single_core(method)

A place holder decorator that does nothing except document that the function is designed to be run on a single core.

structopt.tools.parallel.parallel(method)

A decorator that does nothing except document that the function is designed to run in parallel.

structopt.tools.parallel.allgather(stuff, stuffs_per_core)

Performs an MPI.allgather on a selection of data and uses stuffs_per_core to parse out the correct information and return it.

Parameters:
  • stuff (any) – any piece of data (e.g. fitnesses), some of which have been updated on their respective cores and some of which haven’t. each piece of data should be of the same length
  • stuffs_per_core (dict<int, list<int>>) – a dictionary containing a mapping of the cores that contain the correct information to the corresponding indices in the pieces of data
Returns:

the correct stuff is returned on each core

Return type:

type(stuff)

Example

This is going to take the values:

values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

and convert each of them to strings.

In this example there are 5 cores, so stuffs_per_core looks like:

stuffs_per_core = {0: [0, 5], 1: [1, 6], 2: [2, 7], 3: [3, 8], 4: [4, 9]}

Now for the code that precedes allgather() and then calls allgather():

# This for-loop modifies different parts of `values` on each core by
# converting some elements in `values` from an int to a str.
# We then want to collect the values that each core independently updated
# and allgather them so that every core has all of the updated values,
# even though each core only did part of the work.
for i in stuffs_per_core[rank]:
    values[i] = str(inds[i])
x = allgather(values, stuffs_per_core)
print(x)  # returns:  ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']