Skip to content

Commit 66df73f

Browse files
CopilotWenyinWei
andcommitted
Complete simplified parallelism interface and fix compilation issues
Co-authored-by: WenyinWei <[email protected]>
1 parent 4b2e7b8 commit 66df73f

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

PARALLELISM_USAGE.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Simplified Parallelism Usage in diffeq
2+
3+
The diffeq library now provides a much simpler parallelism interface alongside the advanced facade system.
4+
5+
## Quick Start (Simple Interface)
6+
7+
For most users, parallel execution is now as simple as:
8+
9+
```cpp
10+
#include <diffeq.hpp>
11+
12+
// Parallel execution of ODE integration for multiple initial conditions
13+
std::vector<std::vector<double>> initial_conditions = /* your data */;
14+
15+
diffeq::execution::parallel_for_each(initial_conditions, [](std::vector<double>& state) {
16+
auto integrator = diffeq::RK4Integrator<std::vector<double>>(your_system);
17+
integrator.step(state, dt);
18+
});
19+
```
20+
21+
## Simple API Reference
22+
23+
### Free Functions (Global)
24+
```cpp
25+
// Execute function on each element in parallel
26+
diffeq::execution::parallel_for_each(container, lambda);
27+
28+
// Async execution with future
29+
auto future = diffeq::execution::parallel_async(lambda);
30+
31+
// Configure global parallel settings
32+
diffeq::execution::set_parallel_workers(8);
33+
diffeq::execution::enable_gpu_acceleration();
34+
diffeq::execution::enable_cpu_only();
35+
```
36+
37+
### Parallel Class (Custom Instances)
38+
```cpp
39+
// Create custom parallel executor
40+
auto parallel = diffeq::execution::Parallel(4); // 4 workers
41+
42+
// Execute on each element
43+
parallel.for_each(container, lambda);
44+
45+
// Async execution
46+
auto future = parallel.async(lambda);
47+
48+
// Configuration
49+
parallel.set_workers(8);
50+
parallel.use_gpu();
51+
parallel.use_cpu();
52+
53+
// Information
54+
size_t workers = parallel.worker_count();
55+
bool gpu_available = parallel.gpu_available();
56+
```
57+
58+
## Advanced Usage
59+
60+
For complex scenarios requiring fine-grained control, real-time priorities, hardware-specific optimizations, etc., the full ParallelismFacade and builder pattern are still available:
61+
62+
```cpp
63+
auto facade = diffeq::execution::parallel_execution()
64+
.target_gpu()
65+
.use_thread_pool()
66+
.workers(1024)
67+
.realtime_priority()
68+
.enable_load_balancing()
69+
.build();
70+
```
71+
72+
## Migration Guide
73+
74+
**Before (complex):**
75+
```cpp
76+
diffeq::execution::ParallelismFacade facade;
77+
facade.parallel_for_each(container, lambda);
78+
```
79+
80+
**Now (simple):**
81+
```cpp
82+
diffeq::execution::parallel_for_each(container, lambda);
83+
```
84+
85+
The simplified interface makes parallelism accessible to all users while maintaining full backward compatibility.

include/diffeq.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <execution/parallel.hpp> // Simplified parallel execution interface
4141
#include <execution/parallelism_facade_clean.hpp> // Advanced parallelism interface (Facade pattern)
4242
#include <execution/parallel_builder.hpp> // Fluent interface for configuration (Builder pattern)
43-
#include <execution/modern_executor.hpp> // Modern C++ executor support with coroutines
43+
// #include <execution/modern_executor.hpp> // Modern C++ executor support with coroutines (disabled due to std::execution compatibility)
4444
#include <execution/hardware_support.hpp> // Hardware-specific execution (CUDA, OpenCL, FPGA, MPI)
4545

4646
/**

test_simplified_parallelism

-436 KB
Binary file not shown.

0 commit comments

Comments
 (0)