Skip to content

Examples: add isolated parallel execution cookbook program (#12) - #315

Merged
guillermomolina merged 3 commits into
guillermomolina:mainfrom
jabrailkhalil:issue-12-parallel-example
Sep 11, 2026
Merged

guillermomolina merged 3 commits into
guillermomolina:mainfrom
jabrailkhalil:issue-12-parallel-example

Conversation

@jabrailkhalil

Copy link
Copy Markdown
Contributor

Closes #12

Summary

Adds a standalone cookbook program protos/examples/concurrency/parallel-execution.protos teaching the public isolated-parallel (P) model, and lists it in protos/examples/README.md.

The example demonstrates:

  • explicit inputs to closure.parallel(...) (the projected closure has no lexical edge back to the caller, so data is passed as arguments rather than captured);
  • observation through the returned Future with value();
  • deterministic output despite parallel physical execution: parallelMap and parallelFilter preserve source order, parallelFindIndex selects the lowest logical matching index (null when nothing matches), parallelReduce uses the canonical reduction tree (null for an empty source), and parallelSort is stable;
  • only public Protos operations; no public P/worker/executor object, no scheduler timing, and a reminder that the snapshot is established before parallel(...) returns.

The new source carries the exact APL Part 5 notice. Existing parallel/concurrency tests remain green.

Validation

  • mvn -q -DskipTests package (JDK 22.0.2 + Maven 3.9.9): PASS.
  • java -jar target/protos-0.2.344-SNAPSHOT.jar protos/examples/concurrency/parallel-execution.protos: exit 0, clean stderr, deterministic output:
    42 / [9, 1, 16, 1, 25, 81, 4, 36] / [4, 2, 6] / 2 / null / 31 / null / [1, 1, 2, 3, 4, 5, 6, 9]
  • mvn test -Dtest=ProtosCliLearningMaterialsTest: 50/50 pass (the suite auto-discovers every print-dependent example, including the new one, and runs it through the standalone CLI without stderr).
  • mvn test -Dtest=ProtosParallelExecutionTest: 7/7 pass.
  • scripts/source_style_guard.py --base upstream/main --head HEAD: PASS.
  • git diff --check: clean.
  • Known environment caveat: one unrelated ProtosCliTest case (testSubcommandRunsBundledProtosToolThroughCommonBootstrap) fails on this machine both with and without this change: the Truffle runtime 25.3.4.1 version check requires JDK 25, and this machine runs JDK 22. The failure reproduces on a clean upstream/main checkout and does not touch the changed files.

AI assistance: this contribution was authored with the help of an AI coding agent (implementation, tests and PR description); the audit, execution, and validation evidence above were performed and recorded by the agent.

@guillermomolina guillermomolina left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the contribution — this is well scoped and matches the public isolated-parallel model. CI is green and the example looks good overall.

I only have two small polish requests before merging:

  1. Please add the final newline to protos/examples/concurrency/parallel-execution.protos.

  2. Please tweak the parallelReduce comment so it reflects the stronger Protos contract: determinism comes from the canonical logical reduction tree, not from requiring the reducer to be associative/commutative.

Suggested wording:

parallelReduce uses one canonical logical reduction tree, so scheduling does not choose the parenthesization. Do not assume sequential left-fold semantics.

Thanks — nice first contribution!

Copy link
Copy Markdown
Contributor Author

Addressed both polish requests in c1ee86c: added the final newline and updated the parallelReduce comment to describe the canonical logical reduction tree without implying an associativity/commutativity requirement. Ready for another look.

@guillermomolina

Copy link
Copy Markdown
Owner

Thanks! The requested changes look good.

The new CI failure is unrelated to your contribution. The PR is currently based on an older main, where ProtosCliPolyglotRoutingArchitectureTest still had an overly strict source-text assertion. That test has already been fixed on current main.

Could you please update/rebase issue-12-parallel-example onto the latest main and push the updated branch?

Once the new CI run is green, this should be ready to merge. Thanks!

@guillermomolina guillermomolina left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks — the requested polish changes are in, the branch has been updated onto current main, and the new CI run is green. Approved for merge.