Skip to content

y3km21/rayon-nbody-demo

Repository files navigation

Wasm-Rayon-Nbody-Demo

About

This is a library version of rayon-nbody-demo. Thanks to wasm-bindgen-rayon, it can be compiled into wasm.

Demo

Demo ( source )

Usage

⚠ Using: cargo-make and Python

Build

cargo make build-pkg     

The packages created in the working directory are

  • pkg for the multi-thread version
  • pkg-single for the single-thread version

Simple Usage

  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*/

Original Demo

You can do original demo and bench.

nbody-visualize

cargo make nbody visualize

nbody-bench

cargo make nbody bench

nbody-help

cargo make nbody --help

cargo bench

cargo make bench

About

Rayon nbody demo for wasm.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published