Skip to content

Multithreading #177

Description

@djukic14

Hi @krcools,
I’ve pushed a PR that introduces (a preliminary version of) basis function coloring for the multi-threaded assembly of system matrices.
If you're interested in incorporating this, I’d be happy to discuss the best approach for integration. Currently, the coloring is offered as a third option alongside the existing single-threaded and multi-threaded assemble! Multi-threading is enabled by passing a scheduler from OhMyThreads.jl to the threading argument:

T = assemble(op, X, X; threading=DynamicScheduler())

This also allows for more control, such as using only a subset of the available threads. When using SerialScheduler, no coloring is applied, and assembly proceeds in a single thread.
The coloring itself is performed using GraphsColoring.jl with the WorkstreamDSATUR algorithm, which aims to produce balanced colors.
Additionally, I’ve added a new progress bar and parallelized the computation of the potential!
I’d be glad to refine this further (and eliminate any potential bugs I introduced) based on your feedback.
Best regards,
Danijel

Activity

  1. krcools commented on Dec 4, 2025

    @krcools
    Owner

    This looks really great. I am happy to merge this as is. Will add a test to make sure the matrices assembled with different multi-threading strategies always give the same result.

    The main reason I held on to my poor man's progress bar is that is works well with both output to the terminal and logging into a file. But tbh never used the latter so happy to move towards this more advanced solution...

    Maybe the threading option should represent that a coloring strategy is being used...

    T = assemble(op, X, X; threading=:cellcoloring, scheduler=DynamicScheduler())
    

    What do you think? The current algorithm could then be

    T = assemble(op, X, X; threading=:dofsplitting, scheduler=DynamicScheduler())
    
  2. djukic14 commented on Dec 4, 2025

    @djukic14
    ContributorAuthor

    I am glad to hear you like the approach.
    If the new progress bar proves inconvenient in practice, I can revert it to the old version.

    I can also update the PR to reflect the API change you suggested, but I would then propose dropping the dedicated “single‑threaded” variant altogether. The pure single‑threaded path would simply be

    assemble(op, X, X; threading=:cellcoloring, scheduler=SerialScheduler())

    and

    assemble(op, X, X; threading=:dofsplitting, scheduler=SerialScheduler())

    If there’s anything else you’d like to tweak or any other detail, just let me know. I can incorporate this into the PR. Of course, if you’d prefer to make the adjustments yourself, that works for me as well.

  3. krcools commented on Dec 4, 2025

    @krcools
    Owner

    I still would like to have the

    assemble(T, X, X; threading=:single)
    

    option, both for debugging, and clarity purposes. I'll take a look and push onto your PR branch.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions