|
| 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. |
0 commit comments