diff --git a/Make.inc b/Make.inc index c64e299e0d747..267a0c2ecddc8 100644 --- a/Make.inc +++ b/Make.inc @@ -17,6 +17,7 @@ USE_SYSTEM_LIBM=0 USE_SYSTEM_OPENLIBM=0 UNTRUSTED_SYSTEM_LIBM=0 USE_SYSTEM_OPENSPECFUN=0 +USE_SYSTEM_DSFMT=0 USE_SYSTEM_BLAS=0 USE_SYSTEM_LAPACK=0 USE_SYSTEM_FFTW=0 diff --git a/Makefile b/Makefile index e345e99ead3ea..550c21a65e824 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ $(build_bindir)/stringpatch: $(build_bindir) contrib/stringpatch.c JL_LIBS = julia julia-debug # private libraries, that are installed in $(prefix)/lib/julia -JL_PRIVATE_LIBS = random suitesparse_wrapper grisu Rmath +JL_PRIVATE_LIBS = suitesparse_wrapper grisu Rmath ifeq ($(USE_SYSTEM_FFTW),0) JL_PRIVATE_LIBS += fftw3 fftw3f fftw3_threads fftw3f_threads endif @@ -119,6 +119,9 @@ endif ifeq ($(USE_SYSTEM_OPENSPECFUN),0) JL_PRIVATE_LIBS += openspecfun endif +ifeq ($(USE_SYSTEM_DSFMT),0) +JL_PRIVATE_LIBS += dSFMT +endif ifeq ($(USE_SYSTEM_BLAS),0) JL_PRIVATE_LIBS += openblas else ifeq ($(USE_SYSTEM_LAPACK),0) diff --git a/base/librandom.jl b/base/dSFMT.jl similarity index 98% rename from base/librandom.jl rename to base/dSFMT.jl index 5f4be6aed0ce7..41dd81c20088a 100644 --- a/base/librandom.jl +++ b/base/dSFMT.jl @@ -1,4 +1,4 @@ -module LibRandom +module dSFMT export DSFMT_state, dsfmt_get_min_array_size, dsfmt_get_idstring, dsfmt_init_gen_rand, dsfmt_gv_init_gen_rand, @@ -9,22 +9,20 @@ export DSFMT_state, dsfmt_get_min_array_size, dsfmt_get_idstring, randmtzig_randn, randmtzig_exprnd, win32_SystemFunction036! -## DSFMT - type DSFMT_state val::Vector{Int32} DSFMT_state() = new(Array(Int32, 770)) end function dsfmt_get_idstring() - idstring = ccall((:dsfmt_get_idstring,:librandom), + idstring = ccall((:dsfmt_get_idstring,:libdSFMT), Ptr{Uint8}, ()) return bytestring(idstring) end function dsfmt_get_min_array_size() - min_array_size = ccall((:dsfmt_get_min_array_size,:librandom), + min_array_size = ccall((:dsfmt_get_min_array_size,:libdSFMT), Int32, ()) end @@ -32,68 +30,68 @@ end const dsfmt_min_array_size = dsfmt_get_min_array_size() function dsfmt_init_gen_rand(s::DSFMT_state, seed::Uint32) - ccall((:dsfmt_init_gen_rand,:librandom), + ccall((:dsfmt_init_gen_rand,:libdSFMT), Void, (Ptr{Void}, Uint32,), s.val, seed) end function dsfmt_gv_init_gen_rand(seed::Uint32) - ccall((:dsfmt_gv_init_gen_rand,:librandom), + ccall((:dsfmt_gv_init_gen_rand,:libdSFMT), Void, (Uint32,), seed) end function dsfmt_init_by_array(s::DSFMT_state, seed::Vector{Uint32}) - ccall((:dsfmt_init_by_array,:librandom), + ccall((:dsfmt_init_by_array,:libdSFMT), Void, (Ptr{Void}, Ptr{Uint32}, Int32), s.val, seed, length(seed)) end function dsfmt_gv_init_by_array(seed::Vector{Uint32}) - ccall((:dsfmt_gv_init_by_array,:librandom), + ccall((:dsfmt_gv_init_by_array,:libdSFMT), Void, (Ptr{Uint32}, Int32), seed, length(seed)) end function dsfmt_genrand_close_open(s::DSFMT_state) - ccall((:dsfmt_genrand_close_open, :librandom), + ccall((:dsfmt_genrand_close_open, :libdSFMT), Float64, (Ptr{Void},), s.val) end function dsfmt_gv_genrand_close_open() - ccall((:dsfmt_gv_genrand_close_open, :librandom), + ccall((:dsfmt_gv_genrand_close_open, :libdSFMT), Float64, ()) end function dsfmt_genrand_close1_open2(s::DSFMT_state) - ccall((:dsfmt_genrand_close1_open2, :librandom), + ccall((:dsfmt_genrand_close1_open2, :libdSFMT), Float64, (Ptr{Void},), s.val) end function dsfmt_gv_genrand_close1_open2() - ccall((:dsfmt_gv_genrand_close1_open2, :librandom), + ccall((:dsfmt_gv_genrand_close1_open2, :libdSFMT), Float64, ()) end function dsfmt_genrand_uint32(s::DSFMT_state) - ccall((:dsfmt_genrand_uint32,:librandom), + ccall((:dsfmt_genrand_uint32,:libdSFMT), Uint32, (Ptr{Void},), s.val) end function dsfmt_gv_genrand_uint32() - ccall((:dsfmt_gv_genrand_uint32,:librandom), + ccall((:dsfmt_gv_genrand_uint32,:libdSFMT), Uint32, ()) end diff --git a/base/random.jl b/base/random.jl index b7b73cf3c3735..05b51a8192fee 100644 --- a/base/random.jl +++ b/base/random.jl @@ -1,6 +1,6 @@ module Random -using Base.LibRandom +using Base.dSFMT export srand, rand, rand!, diff --git a/base/sysimg.jl b/base/sysimg.jl index a4241988dbf72..2a114c7a4b9a8 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -181,7 +181,7 @@ big(z::Complex) = complex(big(real(z)),big(imag(z))) include("hashing2.jl") # random number generation -include("librandom.jl") +include("dSFMT.jl") include("random.jl") importall .Random diff --git a/deps/Makefile b/deps/Makefile index 5d7662e062ca9..89705a08f80c1 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -24,7 +24,7 @@ MAKE_COMMON = DESTDIR="" prefix=$(build_prefix) bindir=$(build_bindir) libdir=$( # prevent installing libs into usr/lib64 on opensuse unexport CONFIG_SITE -STAGE1_DEPS = random double-conversion +STAGE1_DEPS = double-conversion STAGE2_DEPS = Rmath STAGE3_DEPS = suitesparse-wrapper @@ -63,6 +63,10 @@ ifeq ($(USE_SYSTEM_OPENSPECFUN), 0) STAGE1_DEPS += openspecfun endif +ifeq ($(USE_SYSTEM_DSFMT), 0) +STAGE1_DEPS += random +endif + ifeq ($(USE_SYSTEM_LLVM), 0) STAGE1_DEPS += llvm endif @@ -635,20 +639,24 @@ compile-openspecfun: $(OPENSPECFUN_OBJ_SOURCE) check-openspecfun: compile-openspecfun install-openspecfun: $(OPENSPECFUN_OBJ_TARGET) -## LIBRANDOM ## +## DSFMT ## + +ifeq ($(USE_SYSTEM_DSFMT),0) +DSFMT_FAKE_TARGET = $(DSFMT_OBJ_TARGET) +endif -LIBRANDOM_OBJ_TARGET = $(build_shlibdir)/librandom.$(SHLIB_EXT) -LIBRANDOM_OBJ_SOURCE = librandom.$(SHLIB_EXT) +DSFMT_OBJ_TARGET = $(build_shlibdir)/libdSFMT.$(SHLIB_EXT) +DSFMT_OBJ_SOURCE = libdSFMT.$(SHLIB_EXT) -LIBRANDOM_CFLAGS = $(CFLAGS) -DNDEBUG -DDSFMT_MEXP=19937 $(fPIC) -DDSFMT_DO_NOT_USE_OLD_NAMES +DSFMT_CFLAGS = $(CFLAGS) -DNDEBUG -DDSFMT_MEXP=19937 $(fPIC) -DDSFMT_DO_NOT_USE_OLD_NAMES ifneq ($(USEMSVC), 1) -LIBRANDOM_CFLAGS += -O3 -finline-functions -fomit-frame-pointer -fno-strict-aliasing \ +DSFMT_CFLAGS += -O3 -finline-functions -fomit-frame-pointer -fno-strict-aliasing \ --param max-inline-insns-single=1800 -Wmissing-prototypes -Wall -std=c99 -shared else -LIBRANDOM_CFLAGS += -Wl,-dll +DSFMT_CFLAGS += -Wl,-dll endif ifeq ($(ARCH), x86_64) -LIBRANDOM_CFLAGS += -msse2 -DHAVE_SSE2 +DSFMT_CFLAGS += -msse2 -DHAVE_SSE2 endif dsfmt-$(DSFMT_VER).tar.gz: @@ -660,22 +668,22 @@ dsfmt-$(DSFMT_VER)/config.status: dsfmt-$(DSFMT_VER).tar.gz $(TAR) -C dsfmt-$(DSFMT_VER) --strip-components 1 -xf dsfmt-$(DSFMT_VER).tar.gz && \ cd dsfmt-$(DSFMT_VER) && patch < ../dSFMT.h.patch && patch < ../dSFMT.c.patch echo 1 > $@ -$(LIBRANDOM_OBJ_SOURCE): dsfmt-$(DSFMT_VER)/config.status - $(CC) $(CPPFLAGS) $(LIBRANDOM_CFLAGS) $(LDFLAGS) dsfmt-$(DSFMT_VER)/dSFMT.c -o librandom.$(SHLIB_EXT) && \ - $(INSTALL_NAME_CMD)librandom.$(SHLIB_EXT) librandom.$(SHLIB_EXT) -$(LIBRANDOM_OBJ_TARGET): $(LIBRANDOM_OBJ_SOURCE) +$(DSFMT_OBJ_SOURCE): dsfmt-$(DSFMT_VER)/config.status + $(CC) $(CPPFLAGS) $(DSFMT_CFLAGS) $(LDFLAGS) dsfmt-$(DSFMT_VER)/dSFMT.c -o libdSFMT.$(SHLIB_EXT) && \ + $(INSTALL_NAME_CMD)libdSFMT.$(SHLIB_EXT) libdSFMT.$(SHLIB_EXT) +$(DSFMT_OBJ_TARGET): $(DSFMT_OBJ_SOURCE) cp $< $@ clean-random: - -rm -f librandom.$(SHLIB_EXT) + -rm -f libdSFMT.$(SHLIB_EXT) distclean-random: clean-random -rm -rf *.tar.gz dsfmt-$(DSFMT_VER) get-random: dsfmt-$(DSFMT_VER).tar.gz configure-random: dsfmt-$(DSFMT_VER)/config.status -compile-random: $(LIBRANDOM_OBJ_SOURCE) +compile-random: $(DSFMT_OBJ_SOURCE) check-random: compile-random -install-random: $(LIBRANDOM_OBJ_TARGET) +install-random: $(DSFMT_OBJ_TARGET) ## Rmath ## @@ -685,8 +693,8 @@ RMATH_OBJ_SOURCE = Rmath/src/libRmath-julia.$(SHLIB_EXT) RMATH_FLAGS += CC="$(CC)" USECLANG=$(USECLANG) USEGCC=$(USEGCC) \ OS="$(OS)" ARCH="$(ARCH)" \ - USE_LIBRANDOM=1 LIBRANDOM_PATH="$(build_shlibdir)" \ - DSFMT_PATH=$(JULIAHOME)/deps/dsfmt-$(DSFMT_VER) + USE_DSFMT=1 DSFMT_libdir="$(build_shlibdir)" \ + DSFMT_includedir="$(build_shlibdir)" Rmath/Make.inc: (cd .. && git submodule init && git submodule update) @@ -696,7 +704,7 @@ endif ifeq (exists, $(shell [ -d $(JULIAHOME)/.git/modules/deps/Rmath ] && echo exists )) $(RMATH_OBJ_SOURCE): $(JULIAHOME)/.git/modules/deps/Rmath/HEAD endif -$(RMATH_OBJ_SOURCE): Rmath/Make.inc $(LIBRANDOM_OBJ_TARGET) +$(RMATH_OBJ_SOURCE): Rmath/Make.inc $(DSFMT_OBJ_TARGET) $(MAKE) -C Rmath/src $(RMATH_FLAGS) $(MAKE_COMMON) touch -c $@ $(RMATH_OBJ_TARGET): $(RMATH_OBJ_SOURCE) | $(build_shlibdir) diff --git a/deps/Rmath b/deps/Rmath index e432b0c4b01c5..92e95839702a2 160000 --- a/deps/Rmath +++ b/deps/Rmath @@ -1 +1 @@ -Subproject commit e432b0c4b01c560353412b3f097d179eef5c0ba2 +Subproject commit 92e95839702a2f4c54e189d8e0a9942c366f238c diff --git a/doc/stdlib/profile.rst b/doc/stdlib/profile.rst index 140649dce19e3..679b02a357507 100644 --- a/doc/stdlib/profile.rst +++ b/doc/stdlib/profile.rst @@ -70,7 +70,7 @@ we'll use the text-based display that comes with the standard library:: 23 client.jl; eval_user_input; line: 91 23 profile.jl; anonymous; line: 14 8 none; myfunc; line: 2 - 8 librandom.jl; dsfmt_gv_fill_array_close_open!; line: 128 + 8 dSFMT.jl; dsfmt_gv_fill_array_close_open!; line: 128 15 none; myfunc; line: 3 2 reduce.jl; max; line: 35 2 reduce.jl; max; line: 36 @@ -113,7 +113,7 @@ rather than putting it in a file; if we had used a file, this would show the file name. Line 2 of ``myfunc()`` contains the call to ``rand``, and there were 8 (out of 23) backtraces that occurred at this line. Below that, you can see a call to -``dsfmt_gv_fill_array_close_open!`` inside ``librandom.jl``. You might be surprised not to see the +``dsfmt_gv_fill_array_close_open!`` inside ``dSFMT.jl``. You might be surprised not to see the ``rand`` function listed explicitly: that's because ``rand`` is *inlined*, and hence doesn't appear in the backtraces. @@ -140,7 +140,7 @@ more samples:: 3121 client.jl; eval_user_input; line: 91 3121 profile.jl; anonymous; line: 1 848 none; myfunc; line: 2 - 842 librandom.jl; dsfmt_gv_fill_array_close_open!; line: 128 + 842 dSFMT.jl; dsfmt_gv_fill_array_close_open!; line: 128 1510 none; myfunc; line: 3 74 reduce.jl; max; line: 35 122 reduce.jl; max; line: 36 @@ -163,7 +163,7 @@ dump, which accumulates counts independent of their nesting:: 3121 client.jl _start 373 3121 client.jl eval_user_input 91 3121 client.jl run_repl 166 - 842 librandom.jl dsfmt_gv_fill_array_close_open! 128 + 842 dSFMT.jl dsfmt_gv_fill_array_close_open! 128 848 none myfunc 2 1510 none myfunc 3 3121 profile.jl anonymous 1 diff --git a/test/random.jl b/test/random.jl index 911c3af8bc844..f64c03bf9e977 100644 --- a/test/random.jl +++ b/test/random.jl @@ -122,12 +122,12 @@ function randmtzig_fill_ziggurat_tables() # Operates on the global arrays return nothing end randmtzig_fill_ziggurat_tables() -@test all(ki == Base.LibRandom.ki) -@test all(wi == Base.LibRandom.wi) -@test all(fi == Base.LibRandom.fi) -@test all(ke == Base.LibRandom.ke) -@test all(we == Base.LibRandom.we) -@test all(fe == Base.LibRandom.fe) +@test all(ki == Base.dSFMT.ki) +@test all(wi == Base.dSFMT.wi) +@test all(fi == Base.dSFMT.fi) +@test all(ke == Base.dSFMT.ke) +@test all(we == Base.dSFMT.we) +@test all(fe == Base.dSFMT.fe) #same random numbers on for small ranges on all systems