Skip to content

Query the thread scheduler's size - #3815

Open
galabovaa wants to merge 2 commits into
latestfrom
issue-3637
Open

galabovaa wants to merge 2 commits into
latestfrom
issue-3637

Conversation

@galabovaa

@galabovaa galabovaa commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Changing the threads option between solves on the same thread fails unless resetThreadScheduler() is called first, but there was no way to check the current scheduler's size. The C# wrapper also had no reset.

Changes:

  • Highs::getThreadSchedulerNumThreads(), returning the calling thread's scheduler size, or 0 if it has none
  • Highs_getThreadSchedulerNumThreads() in the C API
  • getThreadSchedulerNumThreads() and resetThreadScheduler() in the C# wrapper
  • getThreadSchedulerNumThreads() in highspy
  • A "Changing the number of threads" section in docs/src/parallel.md

All changes add new functions; nothing existing changes. Tests are in TestHighsParallel.cpp, TestCAPI.c and test_highspy.py.

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)

Closes #3637

@galabovaa
galabovaa requested review from filikat and jajhall November 26, 2026 18:41
@galabovaa galabovaa changed the title Issue 3637 Query the thread scheduler's size Nov 26, 2026
@filikat
filikat changed the base branch from master to latest November 26, 2026 18:51
@galabovaa galabovaa self-assigned this Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.95%. Comparing base (3e79148) to head (fb20262).
⚠️ Report is 4 commits behind head on latest.

Additional details and impacted files
@@           Coverage Diff           @@
##           latest    #3815   +/-   ##
=======================================
  Coverage   79.94%   79.95%           
=======================================
  Files         508      508           
  Lines      121043   121078   +35     
  Branches    18910    18914    +4     
=======================================
+ Hits        96773    96808   +35     
  Misses      23895    23895           
  Partials      375      375           

☔ 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.

Comment thread docs/src/parallel.md

#### [Changing the number of threads](@id scheduler-change-threads)

`Highs::getThreadSchedulerNumThreads()` returns `N` for the calling thread's scheduler, or 0 if there is none. To solve with a different number of threads on the same thread, compare it with the new value and reset if they differ:

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.

"different number of threads on the same thread" is not very clear. Maybe we can use the terminology introduced in the previous section: "different number of worker threads on the same application thread".

Comment thread highs/Highs.h

/**
* @brief Returns the number of threads used by the scheduler owned by the
* calling thread, or 0 if the calling thread has no scheduler. If the

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.

"the scheduler owned by the calling thread" is not fully correct, as it can be called in a worker thread as well. Maybe say "the scheduler of the calling thread".

void Highs_resetThreadScheduler(const HighsInt blocking);

/**
* Get the number of threads used by the scheduler owned by the calling thread.

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.

Same here, it can be called from a worker thread, so "the scheduler of the calling thread"

@jajhall jajhall added Enhancement New feature or request C# C Python and removed C# labels Nov 27, 2026

This branch has not been deployed

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

Labels

C Enhancement New feature or request Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crash on calling HiGHS with new value for threads option

3 participants