Skip to content

Query the maximum available parallelism #31

@abrown

Description

@abrown

For some algorithms, in order to partition work on several threads, we need to know how many threads are available. WebAssembly hosts may decide to limit the amount of parallelism available to a wasi-threads module; in other words, the host could stop spawning threads at some threshold as a way to limit a module's resource consumption. In this scenario, I can think of two options for discovering how many threads are possible:

  • spawn as many threads as possible, putting them in a wait state, until the host returns an error code indicating that no more threads can be created
  • call some function to discover beforehand how many threads to spawn.

This second option seems to me to be more flexible (doesn't require spawn-ing and the associated counting machinery). Now, it could be nice to differentiate between a) the "maximum number of threads spawn-able" and b) the "number of threads that will run concurrently." One could imagine a host allowing many spawned threads but only allocating a limited number of cores on which to run them. To accommodate both a) and b) we could expose two functions instead of one; I'm not sure how useful a) is, though, since b) is likely what one wants to know to properly partition work.

A function implementing a) could look like:

/// Return the maximum number of threads that will run concurrently on this host. This threshold
/// is provided for optimal partitioning of parallel work and could be artificially limited by the
/// host.
max-concurrency: func() -> u32

Any thoughts on adding such a function? Or should we query limits via "spawn until error"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions