Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

sfmt-erlang: SIMD-oriented Fast Mersenne Twister (SFMT) for Erlang

rebar.config: comment out exotic C compiler options

* Most of these exotic C compiler options will not work on clang
* Some people will use the compiler options anyway
  so these are still documented
latest commit 89adc0e4e3
Kenji Rikitake authored
Octocat-spinner-32 c_src
Octocat-spinner-32 priv
Octocat-spinner-32 reference_texts modified sfmt.app.src to include sfmt module to the modules variable
Octocat-spinner-32 src Change sfmt.app.src vsn to 0.9.0
Octocat-spinner-32 support
Octocat-spinner-32 test_scripts
Octocat-spinner-32 Doxyfile Doxyfile input set to c_src directory (for all C source files there)
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md Update README.md for 0.9.0
Octocat-spinner-32 rebar.config
README.md

sfmt-erlang: SIMD-oriented Fast Mersenne Twister (SFMT) for Erlang

  • Version 0.9.0_BETA 10-APR-2014
  • Edited and written by Kenji Rikitake (k2r.org, formerly Kyoto University)
  • Email contact: kenji.rikitake@acm.org

Copyright (c) 2010-2014 Kenji Rikitake and Kyoto University. All rights reserved.

Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima University. All rights reserved.

See the file LICENSE for the license (new/simplified BSD license). (Note: license of rebar is Apache 2.0 License.)

This software is based on SFMT ver. 1.3.3 (SIMD oriented Fast Mersenne Twister(SFMT)) by Mutsuo Saito (Hiroshima University) and Makoto Matsumoto (Hiroshima University)

Details of SFMT algorithm

See http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html

  • Note: only (2^19937 - 1) period is supported
  • Pure SFMT module now added as working code by request (from 0.8.0_RELEASE)

Seeding algorithm changed for seed(integer()) functions

  • The old seed/1 function called init_gen_rand/1 (up to 0.8.0_RELEASE)
  • The internal state generated by init_gen_rand/1 is predictable, especially when the value of the 1st element of the state list is very close to the given seed value. (Michael Gebetsroither discovered this behavior)
  • The new seed/1 function calls init_by_list32/1 (from 0.8.1_RELEASE) and the seed is given as [integer()], to reduce predictability of the 1st element of the state list.

Supported SFMT PRNG periods

  • sfmt: (2^19937 - 1) (also on sfmt_pure)

C NIFs based on SFMT 1.3.3 added (from 0.3.0_RELEASE)

Removed code

  • Wichmann-Hill 2006 RNG code is removed
  • netpbm test code is removed

Notable bugfixes

  • gen_rand_all/1 is now properly applied in sfmt_pure module when gen_rand32/1 was first invoked (from 0.8.2_RELEASE)
  • Catched up with the latest rebar configuration file (from 0.7.0_RELEASE)
  • Dynamically building ebin/sfmt.app (from 0.7.0_RELEASE)
  • PDIC_SEED now named differently for each period (bugfix, from 0.5.2_RELEASE)

Tested platforms

  • FreeBSD/amd64 10-STABLE with Erlang/OTP 17.0
  • OS X 10.9.1 Mavericks with Erlang/OTP 17.0

Building

  • Use GNU/BSD make and then

    make compile

The build script is Basho's rebar at https://github.com/basho/rebar, which will be automatically fetched under the directory support/.

Documentation

  • For the HTML documentation files of the Erlang source

    make doc

    The documentation will be accessible at doc/index.html.

  • For the HTML documentation files of the C NIF source (Note: Doxygen required)

    make c_doc

    The documentation will be accessible at c_doc/index.html.

Testing

  • For unit testing with EUnit, do

    make eunit

  • For testing the speed of 100 times of invoking 100000 gen_rand32/1 function, do

    make speed

    (Previously this was 1000 times x 100000 invocations, but that was practically too slow.)

API compatible with the random module

seed0, seed/0, seed/3, uniform/0, uniform/1, uniform_s/1, uniform_s/3 

TODO

  • No more new feature; more load testing needed
  • More documentation
  • Code upgrading/reloading behavior check

Code authors:

  • Kenji Rikitake
  • Mutsuo Saito
  • Makoto Matsumoto
  • Dan Gudmundsson
  • Michael Truog

THANKS to:

  • Dave "dizzyd" Smith
  • Tuncer Ayaz
  • Tim Bates (random_mt.erl implementator of Mersenne Twister)
  • Dan Gudmundsson
  • Richard O'Keefe
  • Yurii Rashkovskii
  • Kostis Sagonas
  • Michael Gebetsroither
  • Shunichi Shinohara

ACKNOWLEDGMENTS

During the compatibility test of this software, Kenji Rikitake used the supercomputer service provided by Academic Center for Computing and Media Studies (ACCMS), Kyoto University.

Erlang Solutions kindly gave Kenji Rikitake an opportunity to give a presentation about this software at Erlang Factory SF Bay 2011.

Notes on refactoring

  • Speedup by NIF: ~40 times faster than the pure Erlang code (when fully inline-optimized (see rebar.config))
  • For the pure-Erlang code: writing ++ (append) operators by ring buffer loops (as a pair of lists consuming the head elements, and the corresponding accumulators) made the code ~50% faster; the pure Erlang code available under reference_texts/
  • gen_rand32/1, gen_rand32_max/2, and gen_rand_float/1 use Erlang lists (Dan Gudmudsson showed the list version is faster)
  • SSE2 code and options in sfmt-extstate were removed due to causing crash of Erlang BEAM (and even if the SSE2 code was enabled the performance increase would be minimal)
Something went wrong with that request. Please try again.