Skip to content

Make CUTEST_initialize_workspace linear in number of element–variable incidences - #119

Merged
nimgould merged 1 commit into
ralna:masterfrom
cvanaret:initialize_workspace
Nov 7, 2026
Merged

nimgould merged 1 commit into
ralna:masterfrom
cvanaret:initialize_workspace

Conversation

@cvanaret

@cvanaret cvanaret commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

CUTEST_initialize_workspace builds, for each variable, a linked list of the nonlinear elements that use it (LINK_elem_uses_var / LIST_elements). Each new entry is appended by walking the list from its head to its end (the GO TO 30 and GO TO 110 loops). For a variable used by $k$ elements, that costs $O(k^2)$. On problems where a few variables appear in many elements, csetup and usetup end up dominating the whole run. For instance, csetup takes about 64s on CATMIX.

Proposed fix: keep the tail of each list in an automatic array LINK_TAIL( n ):

  • when a list is started, LINK_TAIL( ivar ) = ivar;
  • each append goes straight to LINK_TAIL( ivar ), writes the new entry there, then sets LINK_TAIL( ivar ) = iielts.

Appending becomes $O(1)$. Entries are still appended in the same order.
This brings the cost of csetup on CATMIX from 64s to 0.3s.

Fixes #118

@nimgould nimgould 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.

This looks very sensible ... I have no idea why I didn't do this!!

@nimgould
nimgould merged commit b2cf27b into ralna:master Nov 7, 2026
30 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CUTEST_initialize_workspace quadratic in the number of elements per variable

2 participants