Skip to content

Implement committed output - #124

Merged
alessandropellegrini merged 15 commits into
developfrom
feat/committed_output
Jul 10, 2026
Merged

Implement committed output#124
alessandropellegrini merged 15 commits into
developfrom
feat/committed_output

Conversation

@AdrianoPi

Copy link
Copy Markdown
Collaborator

This pull request adds a committed output management system to the simulation kernel.

This lets simulation models schedule output operations while handling an event. Scheduled operations are then carried out when the originating event is committed, guaranteeing exactly-once execution.

Implementation changes

  • Added module core/output.c and header core/output.h implementing committed output management.
  • Extended ROOT-Sim.h to expose new function ScheduleOutput(), which lets the user submit data for handling upon event commitment.
  • Extended struct simulation_configuration to take a user-defined handler PerformOutput_t that receives the data submitted via ScheduleOutput() with exactly-once semantics once the generating event is committed.
  • Extended struct lp_msg to store committed output data.
  • Updated message processing, fossil collection, and rollback handling.
  • current_msg is now used by the committed output system and always needs to be set.

Testing

  • Added test (test/core/output.c) that verifies correct output sequence in the presence of straggler messages.

Define code structure and developer contract
Work needs to be done.
Needs testing.

Signed-off-by: AdrianoPi <24545691+AdrianoPi@users.noreply.github.com>
Signed-off-by: AdrianoPi <24545691+AdrianoPi@users.noreply.github.com>
Signed-off-by: AdrianoPi <24545691+AdrianoPi@users.noreply.github.com>
Signed-off-by: AdrianoPi <24545691+AdrianoPi@users.noreply.github.com>
Signed-off-by: AdrianoPi <24545691+AdrianoPi@users.noreply.github.com>
Plus changed some docstring wording

Signed-off-by: AdrianoPi <24545691+AdrianoPi@users.noreply.github.com>
Added test for committed output in presence of stragglers. Requires 2 threads.

Signed-off-by: AdrianoPi <24545691+AdrianoPi@users.noreply.github.com>
Signed-off-by: AdrianoPi <24545691+AdrianoPi@users.noreply.github.com>
@AdrianoPi AdrianoPi added the enhancement New feature or request label Mar 1, 2026
Signed-off-by: Alessandro Pellegrini <a.pellegrini@ing.uniroma2.it>

# Conflicts:
#	src/gvt/fossil.c
#	src/lp/process.c
#	src/mm/msg_allocator.h
This commit avoids accessing output buffers if not necessary. Also, output buffers are initialized upon message creation.

Signed-off-by: Alessandro Pellegrini <a.pellegrini@ing.uniroma2.it>
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.81250% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.41%. Comparing base (d6568f6) to head (d90bbaf).

Files with missing lines Patch % Lines
test/core/output.c 81.96% 30 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #124      +/-   ##
===========================================
- Coverage    85.51%   85.41%   -0.10%     
===========================================
  Files           46       47       +1     
  Lines         1553     1742     +189     
  Branches        39       46       +7     
===========================================
+ Hits          1328     1488     +160     
- Misses         209      235      +26     
- Partials        16       19       +3     

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

Three bugs are fixed in the committed output implementation:

- msg_allocator_alloc() did not initialize msg->outputs to NULL. Since
  mm_alloc() wraps malloc(), freshly allocated messages could contain a
  garbage pointer in that field. All functions guarding on if(!outputs)
  would then skip the NULL check and dereference the garbage value,
  leading to a crash or memory corruption.

- The outputs field in struct lp_msg was placed between pl_size and
  pl[], inside the MPI-transmitted region. When a message was sent to a
  remote node the local pointer value was serialized, and
  the receiving side would overwrite the field with that garbage value
  via MPI_Mrecv. The field is moved into the message preamble (before
  dest) so it is never transmitted.

- fossil_lp_collect() called execute_outputs() on every PES entry,
  including PES_ENTRY_SENT_LOCAL ones. Sent messages do not carry
  outputs; only received messages do. The call is moved after the
  sent-local guard and the already-extracted m pointer is reused to
  avoid a redundant pes_entry_msg() call.

Two additional correctness issues are also addressed in output.c:

- The silent_processing guard in ScheduleOutput() was checked after the
  serial fast-path. This meant that calling ScheduleOutput() during
  LP_FINI in serial mode would incorrectly fire the output callback,
  contrary to what the API documentation states. The guard is now
  checked first.

- The serial mode detection used the deprecated global_config.serial
  boolean instead of global_config.synchronization == SERIAL, leading to lose all
  output: ScheduleOutput() would buffer entries on current_msg->outputs
  that execute_outputs() never flushes in serial mode.

The committed_output test is extended with:

- A serial mode test case, verifying that the output callback fires
  immediately and in causal order.
- A total output count assertion in the Time Warp test that detects any
  phantom outputs from events that were rolled back but whose outputs
  were not correctly suppressed by committed_output_on_rollback().
- Per-invocation output_size verification in the output callback.
- Bounds checking on the output buffer before writing to it.

Signed-off-by: Alessandro Pellegrini <a.pellegrini@ing.uniroma2.it>
In the fixing process, I started adding a store that is now
unnecessary given the other fixes. Remove it.

Signed-off-by: Alessandro Pellegrini <a.pellegrini@ing.uniroma2.it>
@alessandropellegrini

Copy link
Copy Markdown
Member

@AdrianoPi I have rebased the PR againts the current code base. I have made some changes (mostly documented in commit messages), it could be great if you could quickly recheck!

@alessandropellegrini
alessandropellegrini marked this pull request as ready for review June 28, 2026 08:57
@AdrianoPi

Copy link
Copy Markdown
Collaborator Author

Thanks!
The only thing I see is we can avoid the

msg->outputs = NULL;

in common_msg_pack, as msg_allocator_alloc already takes care of that.

The rest looks good!

In the fixing process, I started adding a store that is now
unnecessary given the other fixes. Remove it.

Signed-off-by: Alessandro Pellegrini <a.pellegrini@ing.uniroma2.it>
@alessandropellegrini

Copy link
Copy Markdown
Member

Good catch! I have removed that.
Since I had my hands in this PR, maybe @Piccions should give a final review?

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

LGTM, just a minor change suggested

Comment thread src/gvt/fossil.c Outdated
Reversing the order in which the output messages are materialized upon
fossil collection ensures a per-LP order.

There is no global order yet, as fossil_lp_collect() is executed lazily
and possibly concurrently by multiple workers.

Signed-off-by: Alessandro Pellegrini <a.pellegrini@ing.uniroma2.it>
@alessandropellegrini
alessandropellegrini merged commit 9092c5e into develop Jul 10, 2026
13 of 20 checks passed
@alessandropellegrini
alessandropellegrini deleted the feat/committed_output branch July 10, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants