Skip to content

Parallel scheduler documentation - #3449

Merged
jajhall merged 12 commits into
latestfrom
parallel-docs
Oct 23, 2026
Merged

jajhall merged 12 commits into
latestfrom
parallel-docs

Conversation

@filikat

@filikat filikat commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Add documentation about the parallel scheduler, in particular about initialisation, shutdown and thread safety.
  • Update comments related to thread safety of resetGlobalScheduler in C and Cpp API.
  • Change name of resetGlobalScheduler to resetThreadScheduler, since the scheduler is not global but is owned by the thread that created it. I am open to other names if people have better ideas. resetGlobalScheduler is retained for compatibility, but I put it in the list of deprecated methods. I cannot give a deprecationMessage though, as it's a static function.
  • Add a test checking that different threads have independent schedulers.

There is a large diff because many tests call resetGlobalScheduler.
@galabovaa I added resetThreadScheduler to the python binding in the same way as resetGlobalScheduler. I'm not sure if something else is needed.

Checklist

  • I have read the contributing guidelines
  • This PR targets the latest branch
  • Tests are passing
  • Documentation was updated where relevant
  • This PR is not primarily AI-generated (per the AI contributions policy in CONTRIBUTING.md)

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.20359% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.14%. Comparing base (d5e8e73) to head (b3e7094).
⚠️ Report is 76 commits behind head on latest.

Files with missing lines Patch % Lines
check/TestHighsParallel.cpp 95.58% 3 Missing ⚠️
highs/interfaces/highs_c_api.cpp 50.00% 2 Missing ⚠️
highs/lp_data/Highs.cpp 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           latest    #3449      +/-   ##
==========================================
+ Coverage   75.10%   75.14%   +0.04%     
==========================================
  Files         460      460              
  Lines      112008   112233     +225     
  Branches    17757    17792      +35     
==========================================
+ Hits        84125    84341     +216     
- Misses      27601    27610       +9     
  Partials      282      282              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Opt-Mucca Opt-Mucca left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new documentation! It's clear and addresses everything that I imagine a user would be interested in. Thanks for fixing some outdated lines on parallel MIP too.

@galabovaa galabovaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you, @filikat

Comment thread highs/interfaces/highs_c_api.h Outdated
* undefined behavior and may cause crashes, but cannot be detected and hence
* is fully in the callers responsibility.
* this function while on a worker thread or during the execution of a Highs
* function may cause crashes, but cannot be detected and hence is fully in the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better and correct: "fully the caller's resonsibility."

Comment thread docs/src/parallel.md Outdated

- The first time an application thread calls `run()` or `presolve()`, HiGHS creates a scheduler for that thread. The thread becomes its owning thread.
- All `Highs` instances used on the same application thread share that thread's scheduler.
- Application threads never share a scheduler. If several application threads each use HiGHS, each gets its own scheduler and its own worker threads. They do not interfere with each other.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better "If several application threads use HiGHS, each gets ..." or (possibly) "If each of several application threads uses HiGHS, each gets..." or

@jajhall jajhall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unable to create the documentation locally to see how it looks in a browser, but I've previewed the changes to partallel.md and solvers.md in GitHub.

Other than the couple of grammatical corrections, I thought that just presenting the general documentation for the scheduler might be intimidating for someone whose code is serial and they are simply calling run() for a single Highs instance. Perhaps there could be a documentation section explaining the use of the scheduler in this simplest (but common) special case.

@filikat

filikat commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Other than the couple of grammatical corrections, I thought that just presenting the general documentation for the scheduler might be intimidating for someone whose code is serial and they are simply calling run() for a single Highs instance. Perhaps there could be a documentation section explaining the use of the scheduler in this simplest (but common) special case.

Yes, it is indeed a bit daunting to see so many details.
I split the documentation in two. The first section is for the average user and it tells them that they don't need to do anything about the scheduler, apart from potentially choosing the number of threads. The second section is labelled as advanced, with a list of reasons why a user may be interested. I made the second section shorter, since it is intended only for advanced users, so we can use more advanced terminology.

@fwesselm fwesselm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @filikat!

Comment thread docs/src/parallel.md Outdated

- An **application thread** is any thread not created by HiGHS. A **worker thread** is created by HiGHS as part of a scheduler. The **owning thread** is the application thread that created a scheduler, and it participates in the parallel work.
- The scheduler is `thread_local`. It is created lazily by the first `run()` or `presolve()` on an application thread, and is shared by all `Highs` instances used on that thread. It is never visible to other application threads.
- A scheduler of size `N` consists of the owning thread and `N - 1` workers. `N` is fixed at creation, so later changes to the `threads` option have no effect until the scheduler is reset. The default is the number of physical cores in the process's CPU affinity mask.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... changes to the threads option have no effect ...

If threads is changed, doesn't the code print a log message and return an error?

def readSolution(self, file_path: str, style: int) -> HighsStatus: ...
@staticmethod
def resetThreadScheduler(blocking: bool) -> None: ...
def resetGlobalScheduler(blocking: bool) -> None: ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the line @staticmethod has be repeated for the resetGlobalScheduler?

@filikat
filikat requested a review from jajhall October 23, 2026 09:02
Comment thread docs/src/parallel.md Outdated

All of this applies to the C API and to other languages as well.

You only need the advanced section below if you run HiGHS from several threads of your own, or if you need to stop HiGHS's threads explicitly, for example before unloading a library.

@jajhall jajhall Oct 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HiGHS': no s after the apostrophe when a singular noun ends in "s"

Otherwise this is great!

I think we'll see the benefit of taking time over composing this documentation

@filikat
filikat marked this pull request as ready for review October 23, 2026 11:10
@filikat

filikat commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

Great.
Not sure if we want to merge it now and have it in the next release, or discuss this more at the next meeting.
@jajhall I leave the choice to you.

@jajhall
jajhall merged commit dfbd76a into latest Oct 23, 2026
603 of 607 checks passed
@jajhall
jajhall deleted the parallel-docs branch October 23, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants