This is a library version of rayon-nbody-demo. Thanks to wasm-bindgen-rayon, it can be compiled into wasm.
โ Using: cargo-make and Python
cargo make build-pkg
The packages created in the working directory are
pkg
for the multi-thread versionpkg-single
for the single-thread version
import { threads } from "wasm-feature-detect";
let rayonNbodyDemo;
if (await threads()) {
rayonNbodyDemo = await import("rayon-nbody-demo");
await rayonNbodyDemo.default();
await rayonNbodyDemo.initThreadPool(navigator.hardwareConcurrency);
} else {
rayonNbodyDemo = await import("rayon-nbody-demo_single");
await rayonNbodyDemo.default();
}
rayonNbodyDemo.logging_init();
let numBodies = 1500;
// ExecutionMode
// Par : 0
// ParReduce : 1
// Seq : 2
let mode = 0;
// Nbody
// If rayonNbodyDemo is single version then second arg is ignored
// therefore always Seq mode.
const nbody = new rayonNbodyDemo.NBody(numBodies, mode);
const gotNBodyConditions = nbody.init_conditions();
/*Make meshs using nbody init conditions*/
const nextNbodyPositions = nbody.next_positions();
/*Update world position of meshs*/
You can do original demo and bench.
cargo make nbody visualize
cargo make nbody bench
cargo make nbody --help
cargo make bench