veda_rs/
lib.rs

1// VEDA - parallel runtime for Rust
2// High-performance work-stealing task scheduler with intuitive parallel iterator API
3#![allow(dead_code)]
4pub mod config;
5pub mod error;
6pub mod executor;
7pub mod iter;
8pub mod prelude;
9pub mod runtime;
10pub mod runtime_manager;
11pub mod scheduler;
12pub mod scope;
13pub mod telemetry;
14pub mod util;
15
16#[cfg(feature = "async")]
17pub mod async_bridge;
18
19#[cfg(feature = "gpu")]
20pub mod gpu;
21
22#[cfg(feature = "custom-allocators")]
23pub mod memory;
24
25pub use config::{Config, ConfigBuilder, SchedulingPolicy};
26pub use error::{Error, Result};
27pub use iter::{IntoParallelIterator, ParallelIterator, ParallelSlice};
28pub use runtime::{init, init_with_config, init_thread_local, init_thread_local_with_config, shutdown, set_lazy_init};
29pub use runtime_manager::RuntimeManager;
30pub use executor::task::Priority;
31pub use util::{BackpressureController, BackpressureConfig};
32
33#[cfg(feature = "telemetry")]
34pub use telemetry::{Metrics, MetricsSnapshot, MetricsExporter, JsonExporter};
35
36#[cfg(feature = "async")]
37pub use async_bridge::{spawn_async, block_on, ParStreamExt};
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn test_basic_parallel_sum() {
45        shutdown();
46        init().unwrap();
47        
48        let sum: i32 = (0i32..100i32).into_par_iter().sum();
49        assert_eq!(sum, 4950);
50        
51        shutdown();
52    }
53    
54    #[test]
55    fn test_parallel_map() {
56        shutdown();
57        init().unwrap();
58        
59        let result: Vec<i32> = (0i32..10i32)
60            .into_par_iter()
61            .map(|x| x * 2)
62            .collect();
63        
64        assert_eq!(result.len(), 10);
65        assert!(result.contains(&0));
66        assert!(result.contains(&18));
67        
68        shutdown();
69    }
70    
71    #[test]
72    fn test_scope_simple() {
73        shutdown();
74        init().unwrap();
75        
76        use std::sync::Arc;
77        use parking_lot::Mutex;
78        
79        let counter = Arc::new(Mutex::new(0));
80        
81        scope::scope(|s| {
82            for _ in 0..10 {
83                let counter = counter.clone();
84                s.spawn(move || {
85                    *counter.lock() += 1;
86                });
87            }
88        });
89        
90        assert_eq!(*counter.lock(), 10);
91        
92        shutdown();
93    }
94}