Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ build_*/
# Generated benchmark and documentation artifacts
# The final v1.1 real-world CSV/Markdown results are intentionally versioned.
validation/output/*.csv
!validation/output/v1.4.0_parallel_algorithms.csv
!validation/output/v1.4.0_parallel_algorithms_raw.csv
validation/output/plots/
docs/generated/

Expand Down
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,51 @@

All notable public changes to SmartParallel are documented here. Detailed internal milestone history is retained in [`docs/archive/v1.1-development/CHANGELOG_DEVELOPMENT_HISTORY.md`](docs/archive/v1.1-development/CHANGELOG_DEVELOPMENT_HISTORY.md).

## [1.4.0] — Parallel algorithm expansion

### Added

- `parallel_for_each`, unary/binary `parallel_transform`, `parallel_copy`, `parallel_fill`, and indexed `parallel_generate`.
- `parallel_reduce` and unary/binary `parallel_transform_reduce` with ordered chunk combination.
- `parallel_count`, `parallel_count_if`, `parallel_any_of`, `parallel_all_of`, and `parallel_none_of`.
- `parallel_find` and `parallel_find_if` with earliest-index result semantics.
- Dedicated cross-backend correctness, nested execution, exception, sanitizer, installed-package, and benchmark validation.
- A versioned v1.4 benchmark matrix with sequential, automatic, ThreadPool, StaticThread, and oneTBB modes.

### Fixed

- Added a scheduler-approved direct sequential range path for v1.4 algorithms. When automatic scheduling selects sequential execution, the algorithm now uses one-pass standard-library or iterator traversal instead of executing logical chunks through per-chunk dispatch, partial-result storage, or search/predicate atomics.
- Deferred per-chunk callable copies and reduction partial storage until a chunk is actually executed, keeping the cached sequential path close to the direct sequential baseline without changing parallel plans or backend behavior.
- Added deterministic validation that cached automatic sequential plans preserve correctness for reduce, count, and search.
- Added an Auto-only, root-only algorithm hot-dispatch cache for `parallel_reduce`, `parallel_count`, `parallel_find`, `parallel_find_if`, `parallel_any_of`, `parallel_all_of`, `parallel_none_of`, and `parallel_copy`. It learns from separate real complete scheduled and sequential invocations, then bypasses chunk construction and scheduler entry when direct sequential execution wins.
- Added bounded, sharded dispatch retention, workload/byte buckets, policy and profile-cache epoch invalidation, single-flight probes, hysteresis, and periodic revalidation.
- Corrected `parallel_copy` learning by measuring actual sequential copy time instead of inferring it from a bandwidth-limited parallel execution; scheduled chunks now use `std::copy` so contiguous iterators retain standard-library optimizations.
- Reduced search and predicate coordination overhead with relaxed atomics while retaining scheduler-completion synchronization.
- Cached Windows hardware topology discovery for the process lifetime, matching the existing Linux and macOS behavior.

### Architecture

- All algorithms reuse the existing adaptive scheduler, backend abstraction, runtime learning, nested coordinator, concurrency budgets, ThreadPool helping, StaticThread engine, and oneTBB arenas.
- Algorithms submit bounded contiguous logical chunks through one internal scheduler adapter; no second execution model was introduced.
- Existing `parallel_for`, scheduler policy, backend logic, and v1.1 benchmark algorithms remain unchanged.

### Semantics

- v1.4 algorithms require random-access iterators.
- Reduction operations must be associative; chunk and input ordering are preserved but parenthesization may differ from a sequential fold.
- Predicate and search algorithms use best-effort short-circuiting, and search returns the earliest match.
- User callables may execute concurrently and must synchronize shared mutable state.

### Validation

- GCC Release passed the complete 17-test deterministic suite.
- Clang Release and Clang ASan+UBSan passed the v1.4 algorithm validation.
- The installed CMake package consumer compiled and executed v1.4 transform and reduction APIs.
- Local GCC and Clang benchmark matrices passed checksum validation for every API.
- The accepted Windows/MSVC Release snapshot passed all 80 summary rows and 560 raw samples with checksum correctness and backend authentication.
- The eight parallel-selected automatic cases achieved a 3.30× geometric-mean speedup; all eight corrected cheap-dispatch families were within 3.5% of direct sequential latency or faster.
- Added a versioned v1.4 benchmark report, reproduction guide, PNG/SVG figures, generated metrics, and source hashes.

## [1.3.0] — Cross-platform CI and portability

### Added
Expand Down Expand Up @@ -77,6 +122,7 @@ All notable public changes to SmartParallel are documented here. Detailed intern
- Added ThreadPool, StaticThread, oneTBB, and sequential execution paths.
- Added bounded runtime experience, diagnostics, validation programs, and the original OpenCV/scientific benchmark suite.

[1.4.0]: docs/v1.4/release-notes.md
[1.3.0]: docs/v1.3/release-notes.md
[1.1.0]: docs/v1.1/release-notes.md
[1.0.0]: docs/v1.0/README.md
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endif()

project(
SmartParallel
VERSION 1.3.0
VERSION 1.4.0
DESCRIPTION "Adaptive parallel scheduling for modern C++"
LANGUAGES CXX
)
Expand Down Expand Up @@ -74,6 +74,10 @@ option(SMARTPARALLEL_BUILD_PARALLEL_FOR_HARDENING
"Build parallel_for hardening tests" OFF)
option(SMARTPARALLEL_BUILD_PARALLEL_FOR_OVERHEAD
"Build parallel_for overhead benchmark" OFF)
option(SMARTPARALLEL_BUILD_V140_ALGORITHM_VALIDATION
"Build v1.4 parallel algorithm correctness validation" OFF)
option(SMARTPARALLEL_BUILD_V140_ALGORITHM_BENCHMARKS
"Build v1.4 parallel algorithm benchmark suite" OFF)
option(SMARTPARALLEL_BUILD_SCIENTIFIC_TEST1
"Build scientific Test 1: numerical integration" OFF)
option(SMARTPARALLEL_BUILD_SCIENTIFIC_TEST2
Expand Down
24 changes: 24 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@
"SMARTPARALLEL_BUILD_ALL": "ON"
}
},
{
"name": "v14-algorithms",
"displayName": "v1.4 algorithm Release validation and benchmarks",
"inherits": "release",
"binaryDir": "${sourceDir}/build/v14-algorithms",
"cacheVariables": {
"SMARTPARALLEL_BUILD_VALIDATION": "ON",
"SMARTPARALLEL_BUILD_V140_ALGORITHM_BENCHMARKS": "ON",
"SMARTPARALLEL_BUILD_BENCHMARKS": "OFF",
"SMARTPARALLEL_ENABLE_TBB": "ON",
"SMARTPARALLEL_INSTALL": "ON"
}
},
{
"name": "ci-debug-no-tbb",
"displayName": "CI Debug validation without oneTBB",
Expand Down Expand Up @@ -131,6 +144,10 @@
"name": "ci-debug-no-tbb",
"configurePreset": "ci-debug-no-tbb"
},
{
"name": "v14-algorithms",
"configurePreset": "v14-algorithms"
},
{
"name": "ci-release-tbb",
"configurePreset": "ci-release-tbb"
Expand Down Expand Up @@ -175,6 +192,13 @@
"output": {
"outputOnFailure": true
}
},
{
"name": "v14-algorithms",
"configurePreset": "v14-algorithms",
"output": {
"outputOnFailure": true
}
}
]
}
45 changes: 37 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ SmartParallel is a C++17 library that chooses and coordinates CPU parallel-loop

The fastest way to execute a loop depends on callback cost, iteration count, irregularity, backend overhead, and whether the loop is already inside parallel work. Hard-coding one strategy everywhere can make small loops slower and nested loops unsafe or wasteful.

SmartParallel provides one public loop API, two generations of runtime policy, and a cross-platform portability release. The final v1.3 pull-request validation passed all six GitHub Actions jobs across Windows, Linux, and macOS:
SmartParallel provides an adaptive loop runtime, coordinated nested execution, cross-platform validation, and a v1.4 parallel-algorithm layer. The stabilized runtime continues to run across Windows, Linux, and macOS:

- **SmartParallel v1.0 — Automatic Loop Optimization:** selects a sequential or parallel execution strategy and improves repeated decisions using runtime observations.
- **SmartParallel v1.1 — Nested Parallelism Coordination:** coordinates nested loops through a shared root session, bounded worker leases, automatic frontier selection, and stable-plan reuse.
- **SmartParallel v1.3 — Cross-Platform CI and Portability:** validates the same scheduler and API on Windows/MSVC, Linux/GCC and Clang, and macOS/Apple Clang, including installed-package consumers and oneTBB on/off builds.
- **SmartParallel v1.4 — Parallel Algorithm Expansion:** adds adaptive elementwise, reduction, counting, predicate, and search algorithms, including pre-scheduler hot dispatch for cheap operations.

## Minimal example

Expand All @@ -36,6 +37,18 @@ int main()

Nested calls use the same API. SmartParallel coordinates them under the active root budget instead of creating independent teams at every depth.

The v1.4 algorithms are available from:

```cpp
#include <smart/execution/algorithms.hpp>

#include <functional>

auto total = smart::parallel_transform_reduce(
values.begin(), values.end(), 0.0, std::plus<>{},
[](double value) { return value * value; });
```

## Capabilities

- Runtime selection between sequential, ThreadPool, StaticThread, and oneTBB execution.
Expand All @@ -45,8 +58,22 @@ Nested calls use the same API. SmartParallel coordinates them under the active r
- Cooperative ThreadPool helping and constrained oneTBB arenas.
- Exception propagation, cooperative cancellation, exactly-once validation, and structured trace export.
- Native Windows, Linux, and macOS CPU-topology/cache discovery with conservative fallbacks.
- Fourteen adaptive v1.4 algorithms covering transforms, reductions, counting, predicates, and search, with a direct one-pass path when automatic scheduling selects sequential execution.
- CMake package installation as `SmartParallel::smart_parallel`.

## v1.4 algorithm results

The accepted Windows/MSVC Release snapshot covers sixteen algorithm cases across sequential, automatic, ThreadPool, StaticThread, and oneTBB modes:

- all **80 summary rows** and **560 raw samples** passed correctness and backend authentication;
- automatic selected ThreadPool for eight compute-heavy cases and direct sequential execution for eight cheap or bandwidth-sensitive cases;
- the parallel-selected group achieved a **3.30× geometric-mean speedup**, ranging from **2.67× to 3.53×**;
- every corrected cheap-dispatch family stayed within **3.5%** of direct sequential latency or faster.

![SmartParallel v1.4 automatic speedup](docs/v1.4/assets/benchmarks/automatic-speedup-by-algorithm.png)

The results are machine-specific. See the [complete v1.4 benchmark report](docs/v1.4/benchmarks.md), [methodology](docs/v1.4/benchmark-methodology.md), and [reproduction guide](docs/v1.4/benchmark-reproduction.md).

## Real-world v1.1 results

The final recorded suite covers OpenCV image pipelines, LZ4 batch compression, custom BVH construction, and a custom particle simulation. On the recorded four-worker Windows/MSVC machine:
Expand All @@ -60,7 +87,7 @@ The results are machine-specific measurements, not universal guarantees. See the

## Build

Requirements: CMake 3.20+, a C++17 compiler, and oneTBB only when the oneTBB backend is enabled. SmartParallel v1.3 is continuously validated with MSVC, GCC, Clang, and Apple Clang. The repository includes a vcpkg manifest for oneTBB and optional real-world benchmark dependencies.
Requirements: CMake 3.20+, a C++17 compiler, and oneTBB only when the oneTBB backend is enabled. SmartParallel v1.4 is continuously validated with MSVC, GCC, Clang, and Apple Clang. The repository includes a vcpkg manifest for oneTBB and optional real-world benchmark dependencies.

```text
cmake --preset release
Expand All @@ -78,18 +105,20 @@ find_package(SmartParallel CONFIG REQUIRED)
target_link_libraries(my_application PRIVATE SmartParallel::smart_parallel)
```

Windows users can run the complete real-world validation suite with:
Windows users can build, test, and benchmark every v1.4 algorithm with:

```bat
set "VCPKG_ROOT=D:\Tools\vcpkg" && scripts\benchmarks\run_real_world_complete.bat 31
set "VCPKG_ROOT=D:\Tools\vcpkg" && scripts\validation\run_v14_algorithm_release_validation.bat 7
```

See the [v1.3 cross-platform installation guide](docs/v1.3/installation.md), [GitHub Actions setup](docs/v1.3/ci-and-github-setup.md), [native hardware discovery](docs/v1.3/native-hardware-discovery.md), [release checklist](docs/v1.3/release-checklist.md), and [benchmark reproduction](docs/v1.1/benchmark-reproduction.md) for the complete workflows.
The historical v1.1 real-world suite remains available through `scripts\benchmarks\run_real_world_complete.bat`. See the [v1.4 API](docs/v1.4/api.md), [architecture](docs/v1.4/architecture.md), [benchmark results](docs/v1.4/benchmarks.md), [v1.4 reproduction guide](docs/v1.4/benchmark-reproduction.md), [v1.3 cross-platform installation guide](docs/v1.3/installation.md), [GitHub Actions setup](docs/v1.3/ci-and-github-setup.md), [native hardware discovery](docs/v1.3/native-hardware-discovery.md), and [release checklist](docs/v1.3/release-checklist.md).

## Documentation

- [v1.3 documentation](docs/v1.3/README.md) — current portability and CI release
- [v1.1 runtime documentation](docs/v1.1/README.md) — scheduler and nested-parallelism behavior retained by v1.3
- [v1.4 documentation](docs/v1.4/README.md) — current parallel-algorithm release
- [v1.4 benchmark results](docs/v1.4/benchmarks.md) — accepted automatic/forced backend matrix and graphs
- [v1.3 documentation](docs/v1.3/README.md) — portability and CI release
- [v1.1 runtime documentation](docs/v1.1/README.md) — scheduler and nested-parallelism behavior retained by v1.4
- [Getting started](docs/v1.1/getting-started.md)
- [API reference](docs/v1.1/api.md)
- [Architecture](docs/v1.1/architecture.md)
Expand All @@ -102,7 +131,7 @@ See the [v1.3 cross-platform installation guide](docs/v1.3/installation.md), [Gi

## Project status

**Current release: v1.3.0.** v1.3 keeps the stabilized v1.1 scheduler and public semantics while adding automated cross-platform build, test, install, oneTBB on/off, and external-consumer validation. Real-world performance benchmarks remain manual and the checked-in v1.1 results remain the current performance evidence.
**Current release: v1.4.0.** v1.4 keeps the stabilized scheduler and nested runtime while adding adaptive elementwise, reduction, counting, predicate, and search APIs. The repository now includes accepted v1.4 algorithm measurements and the retained v1.1 real-world integration results; performance benchmarks remain manual and machine-specific.

Important boundaries remain: admission is per root rather than process-wide, global configuration must not be mutated concurrently, traces add overhead, experience is in-memory by default, and automatic scheduling is not guaranteed to beat the best manually selected strategy on every workload.

Expand Down
2 changes: 2 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Versioned benchmark suites.
add_subdirectory(v1.0.0)
add_subdirectory(v1.1.0)

add_subdirectory(v1.4.0)
10 changes: 10 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# SmartParallel benchmark suites

## v1.4.0 parallel algorithm suite

[`benchmarks/v1.4.0/`](v1.4.0/README.md) benchmarks every v1.4 public algorithm against a sequential reference and the available SmartParallel backends. Each repetition is checksum validated.

```bat
set "VCPKG_ROOT=D:\Tools\vcpkg" && scripts\validation\run_v14_algorithm_release_validation.bat 7
```

Results are written to `validation/output/v1.4.0_parallel_algorithms.csv` and the matching `_raw.csv` file. The suite is manual and is not a CI merge gate.

## Current performance suite: v1.1.0 (retained for v1.3)

The current recorded performance suite is [`benchmarks/v1.1.0/`](v1.1.0/README.md). Its real-world integrations cover OpenCV image pipelines, LZ4 compression, custom BVH construction, and a custom particle simulation.
Expand Down
11 changes: 11 additions & 0 deletions benchmarks/v1.4.0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if(SMARTPARALLEL_BUILD_V140_ALGORITHM_BENCHMARKS)
add_executable(
smartparallel_v140_algorithm_benchmarks
src/parallel_algorithm_benchmarks.cpp
)
target_link_libraries(
smartparallel_v140_algorithm_benchmarks
PRIVATE SmartParallel::smart_parallel
)
smartparallel_copy_tbb_runtime(smartparallel_v140_algorithm_benchmarks)
endif()
17 changes: 17 additions & 0 deletions benchmarks/v1.4.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SmartParallel v1.4.0 algorithm benchmarks

`smartparallel_v140_algorithm_benchmarks` benchmarks all fourteen v1.4 API families through sixteen unary/binary cases against sequential references and available SmartParallel backends. Every repetition is checksum validated.

Build directly with:

```text
-DSMARTPARALLEL_BUILD_V140_ALGORITHM_BENCHMARKS=ON
```

The recommended complete Windows workflow is:

```bat
set "VCPKG_ROOT=D:\Tools\vcpkg" && scripts\validation\run_v14_algorithm_release_validation.bat 7
```

See [`docs/v1.4/benchmark-methodology.md`](../../docs/v1.4/benchmark-methodology.md) for the schema and measurement rules.
Loading
Loading