Skip to content

Preserve first error's diagnostic code in op->naTime during parallel solve#994

Merged
mattfidler merged 2 commits intoparallel-updatesfrom
copilot/sub-pr-992
Mar 17, 2026
Merged

Preserve first error's diagnostic code in op->naTime during parallel solve#994
mattfidler merged 2 commits intoparallel-updatesfrom
copilot/sub-pr-992

Conversation

Copy link
Contributor

Copilot AI commented Mar 16, 2026

In parallel mode, op->naTime was unconditionally overwritten on every NA error via #pragma omp atomic write, making the diagnostic code (used to generate the final error message in rxode2_df.cpp) non-deterministic — it would reflect whichever thread wrote last, not the first error encountered.

Changes

  • inst/include/rxode2parseGetTime.hgetLag, getRate, getDur, handleInfusionItem: replace unconditional atomic write of op->naTime with a read-check-write pattern
  • inst/include/rxode2parseHandleEvid.hgetAmt: same fix

op->badSolve remains an unconditional atomic write (any thread setting it to 1 is correct).

Before

int newNaTime = 1 + 10*cmt;
#pragma omp atomic write
op->naTime = newNaTime;  // overwrites every time — last writer wins

After

int curNaTime;
#pragma omp atomic read
curNaTime = op->naTime;
if (curNaTime == 0) {
  int newNaTime = 1 + 10*cmt;
#pragma omp atomic write
  op->naTime = newNaTime;  // only set if not yet recorded
}

This restores the intent of the original if (op->naTime == 0) guard while keeping writes thread-safe.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…-write pattern

Co-authored-by: mattfidler <514778+mattfidler@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on thread safety improvements for rxode2 Preserve first error's diagnostic code in op->naTime during parallel solve Mar 16, 2026
Copilot AI requested a review from mattfidler March 16, 2026 18:12
@mattfidler mattfidler marked this pull request as ready for review March 17, 2026 03:39
@mattfidler mattfidler merged commit 48a3212 into parallel-updates Mar 17, 2026
@mattfidler mattfidler deleted the copilot/sub-pr-992 branch March 17, 2026 03:39
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.

2 participants