nx_pardemo_heavy.nx source
↩ module page · 23 lines · 659 B
1// compute-heavy parallel_for via the (now-buildable) thread_pool: 4 workers, 32 indices, each a 2e6 LCG loop.
2// Probe should read ~4 cores. Proves the ERGONOMIC pool API delivers real multi-core.
3import "nx_parallel.nx"
4
5static g_out: *i64
6
7func heavy_body(i: i64) -> i64 {
8 var s: i64 = i + 1
9 var j: i64 = 0
10 while j < 60000000 { s = (s * 1103515245 + 12345) & 2147483647; j = j + 1 }
11 g_out[i] = s
12 return 0
13}
14
15func main() -> i64 {
16 let N: i64 = 32
17 g_out = sys_mmap(N * 8) as *i64
18 let pool: *NxThreadPool = nx_pool_new(4, 64)
19 nx_parallel_for(pool, 0, N, heavy_body)
20 nx_pool_shutdown(pool)
21 sys_exit(0)
22 return 0
23}