Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create generic asynchronous parallel runtime #25

Open
maxfierrog opened this issue Apr 24, 2024 · 0 comments
Open

Create generic asynchronous parallel runtime #25

maxfierrog opened this issue Apr 24, 2024 · 0 comments
Labels
feature New feature or request help wanted Extra attention is needed

Comments

@maxfierrog
Copy link
Member

maxfierrog commented Apr 24, 2024

Create a wrapper for a generic runtime backed by an opaque implementation of a parallel computation model, like MPI (multi-process), Tokio (async), or Rayon (multi-thread).

The internals of the Runtime can be implemented with Tokio. That is, a Tokio runtime will be encapsulated in a custom Runtime type, and the Tokio runtime will be the coordinator of the parallel implementation's workers. All Runtime calls should be synchronous and blocking, but internally, the Tokio runtime might make asynchronous / non-blocking calls to the underlying model.

In this sense, this is the first part of four things:

  1. Synchronous runtime wrapper
  2. Asynchronous generic coordinator
  3. Bindings to parallel impls. (OpenMPI, rayon, more Tokio, etc.)
  4. Thread-safe database implementation

Example

/// Available types of runtime. All of these assume a shared file system.
enum Runtime {
  ThreadPool { threads: u32 },
  Async { tasks: u32 },
  MPI { nodes: u32 },
}

/// Arguments to job functions.
struct Args<G, D> {
  game: &G,
  db: &mut D,
}

/// Solve the game.
fn solve<G: ..., D: ...>(game: &G, db: &mut D) -> Result<()> {
  let rt = Runtime::initialize(Runtime::MPI(30))?;
  rt.dashboard(Interface::Web)?;
  rt.route_logs(LOG_FILE)?;
  
  let mut graph = Graph::<JobID>::new(); // Partition solving jobs (JobID = Partition #)
  let mut set = Vec::<JobID>::new(); // Exploration jobs (JobID = State)
  
  starts = stochastic_exploration(game, db);
  graph = rt.independent(
    ExploreArgs { game, db },
    explore_job::<G, D>,
    jobs: set,
  )?;
  
  rt.dependent(
    SolveArgs { game, db },
    solve_job::<G, D>,
    jobs: graph,
  )?;
}

/// Explore the game tree.
fn explore_job<G: ..., D: ...>(args: Args<G, D>, target: JobID) -> Result<()> { ... }

/// Solve a single partition.
fn solve_job<G: ..., D: ...>(args: Args<G, D>, target: JobID) -> Result<()> { ... }

/// Sample random states in the game tree.
fn stochastic_exploration<G: ..., D: ...>(args: Args<G, D>) -> Result<()> { ... }

Recommended Courses (UC Berkeley)

If you can't tell whether this is out of your scope, we recommend the following experience:

  • CS 61B (minimum)
  • CS 61C (minimum)
  • CS 162
  • CS 267
@maxfierrog maxfierrog added the feature New feature or request label Apr 24, 2024
@maxfierrog maxfierrog self-assigned this Apr 24, 2024
@maxfierrog maxfierrog added the help wanted Extra attention is needed label Apr 24, 2024
@maxfierrog maxfierrog removed their assignment Apr 25, 2024
@maxfierrog maxfierrog changed the title Create generic asynchronous solving runtime Create generic asynchronous computational runtime Apr 25, 2024
@maxfierrog maxfierrog changed the title Create generic asynchronous computational runtime Create generic asynchronous parallel runtime Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant