Skip to content

Split chunks based on costs obtained from fragment_stats#663

Closed
ChristopherHogan wants to merge 2 commits intoNanoComp:masterfrom
ChristopherHogan:chogan/split_by_cost
Closed

Split chunks based on costs obtained from fragment_stats#663
ChristopherHogan wants to merge 2 commits intoNanoComp:masterfrom
ChristopherHogan:chogan/split_by_cost

Conversation

@ChristopherHogan
Copy link
Contributor

@ChristopherHogan ChristopherHogan commented Jan 10, 2019

Closes #536. Adds grid_volume::split_by_cost which attempts to divide the cell into chunks that take a similar amount of work. The work estimate is produced by fragment_stats::cost, which was obtained from running linear regression on training data from random simulations. Scheme will fall back to the old grid_volume::split_by_effort method. Additionally, there is a Simulation constructor parameter for Python, split_chunks_evenly, that will force the use of split_by_effort. Here are some benchmark results from the following simulation (a tall skinny cell with an expensive flux plane at the top):

import argparse
import time
import meep as mp

def main(args):
    sx = 2
    sy = 30
    sz = 1
    fcen = 0.15
    df = 0.1

    src = mp.Source(mp.GaussianSource(fcen, fwidth=df), mp.Ey, mp.Vector3())

    sim = mp.Simulation(cell_size=mp.Vector3(sx, sy, sz),
                        sources=[src],
                        resolution=10,
                        split_chunks_evenly=args.split_evenly)

    flux = sim.add_flux(fcen, df, 500, mp.FluxRegion(center=mp.Vector3(0, 12), size=mp.Vector3(2, 1)))
    start = time.time()
    sim.run(until=200)
    print("bench:{},{},{}".format(args.split_evenly, mp.count_processors(), time.time() - start))

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-e', '--split-evenly', action='store_true', default=False,
                                        help='Use the old split_by_effort method to create chunks')
    args = parser.parse_args()
    main(args)

split_by_cost_results

The meep::structure is now created in C++ (create_structure_and_set_materials) instead of Python. Using the geometry in structure::choose_chunkdivision would require making copies, or passing it around, both of which would require more significant changes. create_structure_and_set_materials allows the Python geometry to be converted to C++ once, then deleted when it returns.

Remaining issues

  1. split_by_cost doesn't work with cylindrical coordinates yet so it falls back to split_by_effort
  2. split_by_cost breaks the structure::dump and structure::load features. When you run the initial simulation and dump the structure file, the chunks are split optimally based on the geometry, but when you attempt to load the file, there is no geometry passed in so the chunks are split evenly, resulting in chunk size mismatches. My temporary solution to this is to pass split_chunks_evenly=True to a Simulation when you know you want to dump and reuse a structure file. I guess structure::load needs to recreate the chunks with the correct sizes.

@stevengj
Copy link
Collaborator

I just merged a PR #662 that reformats everything with clang-format, which creates lots of conflicts.

To rebase this PR onto master without having to deal manually with these formatting conflicts, follow the exact procedure given in the instructions of #662.

@stevengj
Copy link
Collaborator

Rebased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants