From 2580d153d3bc6640cd22428e7a8a83b13ce4738a Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Wed, 21 Feb 2018 15:20:15 -0800 Subject: [PATCH] Remove the examples/ folder --- Makefile | 17 +- README.md | 1 - contrib/add_license_to_files.jl | 2 - contrib/windows/appveyor_build.sh | 2 +- doc/src/manual/embedding.md | 2 +- doc/src/manual/parallel-computing.md | 7 +- examples/Makefile | 13 - examples/ModInts.jl | 27 -- examples/bubblesort.jl | 19 -- examples/clustermanager/0mq/README | 27 -- examples/clustermanager/0mq/ZMQCM.jl | 282 ------------------ examples/clustermanager/0mq/broker.jl | 4 - examples/clustermanager/0mq/head.jl | 11 - examples/clustermanager/0mq/worker.jl | 5 - examples/clustermanager/simple/README | 12 - .../clustermanager/simple/UnixDomainCM.jl | 95 ------ examples/clustermanager/simple/head.jl | 7 - examples/clustermanager/simple/test_simple.jl | 13 - examples/dictchannel.jl | 34 --- examples/lru.jl | 130 -------- examples/lru_test.jl | 47 --- examples/ndgrid.jl | 52 ---- examples/queens.jl | 28 -- examples/quine.jl | 4 - examples/staged.jl | 61 ---- examples/time.jl | 45 --- examples/typetree.jl | 154 ---------- examples/wordcount.jl | 86 ------ .../InteractiveUtils/src/InteractiveUtils.jl | 2 +- test/choosetests.jl | 4 - test/cmdlineargs.jl | 2 +- test/examples.jl | 81 ----- 32 files changed, 11 insertions(+), 1265 deletions(-) delete mode 100644 examples/Makefile delete mode 100644 examples/ModInts.jl delete mode 100644 examples/bubblesort.jl delete mode 100644 examples/clustermanager/0mq/README delete mode 100644 examples/clustermanager/0mq/ZMQCM.jl delete mode 100644 examples/clustermanager/0mq/broker.jl delete mode 100644 examples/clustermanager/0mq/head.jl delete mode 100644 examples/clustermanager/0mq/worker.jl delete mode 100644 examples/clustermanager/simple/README delete mode 100644 examples/clustermanager/simple/UnixDomainCM.jl delete mode 100644 examples/clustermanager/simple/head.jl delete mode 100644 examples/clustermanager/simple/test_simple.jl delete mode 100644 examples/dictchannel.jl delete mode 100644 examples/lru.jl delete mode 100644 examples/lru_test.jl delete mode 100644 examples/ndgrid.jl delete mode 100644 examples/queens.jl delete mode 100644 examples/quine.jl delete mode 100644 examples/staged.jl delete mode 100644 examples/time.jl delete mode 100644 examples/typetree.jl delete mode 100644 examples/wordcount.jl delete mode 100644 test/examples.jl diff --git a/Makefile b/Makefile index 5a0fa8dd62270..9a06e0570109c 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ all: debug release # sort is used to remove potential duplicates DIRS := $(sort $(build_bindir) $(build_depsbindir) $(build_libdir) $(build_private_libdir) $(build_libexecdir) $(build_includedir) $(build_includedir)/julia $(build_sysconfdir)/julia $(build_datarootdir)/julia $(build_datarootdir)/julia/site $(build_man1dir)) ifneq ($(BUILDROOT),$(JULIAHOME)) -BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src ui doc deps test test/embedding test/perf examples) +BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src ui doc deps test test/embedding test/perf) BUILDDIRMAKE := $(addsuffix /Makefile,$(BUILDDIRS)) DIRS := $(DIRS) $(BUILDDIRS) $(BUILDDIRMAKE): | $(BUILDDIRS) @@ -61,15 +61,6 @@ CLEAN_TARGETS += clean-docdir clean-docdir: @-rm -fr $(abspath $(build_docdir)) -$(build_prefix)/.examples: $(wildcard $(JULIAHOME)/examples/*.jl) \ - $(shell find $(JULIAHOME)/examples/clustermanager) - @echo Copying in usr/share/doc/julia/examples - @-rm -fr $(build_docdir)/examples - @mkdir -p $(build_docdir)/examples - @cp -R $(JULIAHOME)/examples/*.jl $(build_docdir)/examples/ - @cp -R $(JULIAHOME)/examples/clustermanager $(build_docdir)/examples/ - @echo 1 > $@ - julia-symlink: julia-ui-$(JULIA_BUILD_MODE) ifneq ($(OS),WINNT) ifndef JULIA_VAGRANT_BUILD @@ -92,7 +83,7 @@ julia-src-release julia-src-debug : julia-src-% : julia-deps julia_flisp.boot.in julia-ui-release julia-ui-debug : julia-ui-% : julia-src-% @$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/ui julia-$* -julia-base-compiler : julia-base julia-ui-$(JULIA_BUILD_MODE) $(build_prefix)/.examples +julia-base-compiler : julia-base julia-ui-$(JULIA_BUILD_MODE) @$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) $(build_private_libdir)/basecompiler.ji JULIA_BUILD_MODE=$(JULIA_BUILD_MODE) julia-sysimg-release : julia-base-compiler julia-ui-release @@ -503,7 +494,6 @@ clean: | $(CLEAN_TARGETS) @-$(MAKE) -C $(BUILDROOT)/src clean @-$(MAKE) -C $(BUILDROOT)/ui clean @-$(MAKE) -C $(BUILDROOT)/test clean - @-$(MAKE) -C $(BUILDROOT)/examples clean -rm -f $(BUILDROOT)/julia -rm -f $(BUILDROOT)/*.tar.gz -rm -f $(build_depsbindir)/stringreplace \ @@ -512,7 +502,6 @@ clean: | $(CLEAN_TARGETS) -rm -fr $(build_private_libdir) # Teporarily add this line to the Makefile to remove extras -rm -fr $(build_datarootdir)/julia/extras - -rm -f $(build_prefix)/.examples cleanall: clean @-$(MAKE) -C $(BUILDROOT)/src clean-flisp clean-support @@ -530,7 +519,7 @@ distcleanall: cleanall test testall testall1 test clean distcleanall cleanall clean-* \ run-julia run-julia-debug run-julia-release run \ install binary-dist light-source-dist.tmp light-source-dist \ - dist full-source-dist source-dist examples + dist full-source-dist source-dist test: check-whitespace $(JULIA_BUILD_MODE) @$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/test default JULIA_BUILD_MODE=$(JULIA_BUILD_MODE) diff --git a/README.md b/README.md index e7a59800c60a8..f0bd058006191 100644 --- a/README.md +++ b/README.md @@ -387,7 +387,6 @@ The Julia source code is organized as follows: deps/ external dependencies doc/src/manual source for the user manual doc/src/stdlib source for standard library function reference - examples/ example Julia programs src/ source for Julia language core test/ test suites test/perf benchmark suites diff --git a/contrib/add_license_to_files.jl b/contrib/add_license_to_files.jl index b74fa66587f3f..5b461dc8615bd 100644 --- a/contrib/add_license_to_files.jl +++ b/contrib/add_license_to_files.jl @@ -16,7 +16,6 @@ const print_result = true # prints files which where not processed. const rootdirs = [ "../base", "../contrib", - "../examples", "../src", "../stdlib", "../test", @@ -59,7 +58,6 @@ const skipfiles = [ "../src/support/utf8.c", "../test/perf/micro/randmtzig.c", "../src/crc32c.c", - "../examples/quine.jl", # has license text in code ] const ext_prefix = Dict([ diff --git a/contrib/windows/appveyor_build.sh b/contrib/windows/appveyor_build.sh index 33f101cf18eb6..da550643e82db 100755 --- a/contrib/windows/appveyor_build.sh +++ b/contrib/windows/appveyor_build.sh @@ -207,6 +207,6 @@ echo 'FORCE_ASSERTIONS = 1' >> Make.user cat Make.user make -j3 VERBOSE=1 all make -j3 VERBOSE=1 install -make VERBOSE=1 -C examples +make VERBOSE=1 -C test/embedding release cp usr/bin/busybox.exe julia-*/bin make build-stats diff --git a/doc/src/manual/embedding.md b/doc/src/manual/embedding.md index 54cabebd07c6f..496d0f1b425fd 100644 --- a/doc/src/manual/embedding.md +++ b/doc/src/manual/embedding.md @@ -44,7 +44,7 @@ gcc -o test -fPIC -I$JULIA_DIR/include/julia -L$JULIA_DIR/lib test.c -ljulia $JU Then if the environment variable `JULIA_BINDIR` is set to `$JULIA_DIR/bin`, the output `test` program can be executed. -Alternatively, look at the `embedding.c` program in the Julia source tree in the `examples/` folder. +Alternatively, look at the `embedding.c` program in the Julia source tree in the `test/embedding/` folder. The file `ui/repl.c` program is another simple example of how to set `jl_options` options while linking against `libjulia`. diff --git a/doc/src/manual/parallel-computing.md b/doc/src/manual/parallel-computing.md index 195d039f152f2..5cec90cf768df 100644 --- a/doc/src/manual/parallel-computing.md +++ b/doc/src/manual/parallel-computing.md @@ -727,7 +727,8 @@ Methods [`put!`](@ref), [`take!`](@ref), [`fetch`](@ref), [`isready`](@ref) and on a [`RemoteChannel`](@ref) are proxied onto the backing store on the remote process. [`RemoteChannel`](@ref) can thus be used to refer to user implemented `AbstractChannel` objects. -A simple example of this is provided in `examples/dictchannel.jl` which uses a dictionary as its +A simple example of this is provided in `dictchannel.jl` in the +[Examples repository](https://github.com/JuliaArchive/Examples), which uses a dictionary as its remote store. ## Channels and RemoteChannels @@ -1246,7 +1247,7 @@ transport and Julia's in-built parallel infrastructure. A `BufferStream` is an in-memory [`IOBuffer`](@ref) which behaves like an `IO`--it is a stream which can be handled asynchronously. -Folder `examples/clustermanager/0mq` contains an example of using ZeroMQ to connect Julia workers +The folder `clustermanager/0mq` in the Examples repository contains an example of using ZeroMQ to connect Julia workers in a star topology with a 0MQ broker in the middle. Note: The Julia processes are still all *logically* connected to each other--any worker can message any other worker directly without any awareness of 0MQ being used as the transport layer. @@ -1268,7 +1269,7 @@ When using custom transports: the corresponding `IO` objects must be closed by the implementation to ensure proper cleanup. The default implementation simply executes an `exit()` call on the specified remote worker. -`examples/clustermanager/simple` is an example that shows a simple implementation using UNIX domain +The Examples folder `clustermanager/simple` is an example that shows a simple implementation using UNIX domain sockets for cluster setup. ## Network Requirements for LocalManager and SSHManager diff --git a/examples/Makefile b/examples/Makefile deleted file mode 100644 index 08e2ff962966e..0000000000000 --- a/examples/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -## this is a simple wrapper just to forward on known commands to the -## embedding example with values pulled from Make.inc -SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -JULIAHOME := $(abspath $(SRCDIR)/..) -BUILDDIR := . -include $(JULIAHOME)/Make.inc - -release: # default target -# forward all variables expected by the embedding example -JULIA:=$(call spawn,$(JULIA_EXECUTABLE)) -BIN:=$(BUILDDIR)/embedding -CC:=$(CC) -include $(SRCDIR)/embedding/Makefile diff --git a/examples/ModInts.jl b/examples/ModInts.jl deleted file mode 100644 index 01fa574a4188a..0000000000000 --- a/examples/ModInts.jl +++ /dev/null @@ -1,27 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -module ModInts -export ModInt - -import Base: +, -, *, /, inv - -struct ModInt{n} <: Integer - k::Int - ModInt{n}(k) where {n} = new(mod(k,n)) -end - -Base.show(io::IO, k::ModInt{n}) where {n} = - print(io, get(io, :typeinfo, Any) == typeof(k) ? k.k : "$(k.k) mod $n") - -(+)(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k+b.k) -(-)(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k-b.k) -(*)(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k*b.k) -(-)(a::ModInt{n}) where {n} = ModInt{n}(-a.k) - -inv(a::ModInt{n}) where {n} = ModInt{n}(invmod(a.k, n)) -(/)(a::ModInt{n}, b::ModInt{n}) where {n} = a*inv(b) # broaden for non-coprime? - -Base.promote_rule(::Type{ModInt{n}}, ::Type{Int}) where {n} = ModInt{n} -Base.convert(::Type{ModInt{n}}, i::Int) where {n} = ModInt{n}(i) - -end # module diff --git a/examples/bubblesort.jl b/examples/bubblesort.jl deleted file mode 100644 index 6b7c244da1fa9..0000000000000 --- a/examples/bubblesort.jl +++ /dev/null @@ -1,19 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -import Base.Sort -struct BubbleSortAlg <: Sort.Algorithm end -const BubbleSort = BubbleSortAlg() - -function Base.sort!(v::AbstractVector, lo::Int, hi::Int, ::BubbleSortAlg, o::Sort.Ordering) - while true - clean = true - for i = lo:hi-1 - if Sort.lt(o, v[i+1], v[i]) - v[i+1], v[i] = v[i], v[i+1] - clean = false - end - end - clean && break - end - return v -end diff --git a/examples/clustermanager/0mq/README b/examples/clustermanager/0mq/README deleted file mode 100644 index c6bb2cfcfb7ff..0000000000000 --- a/examples/clustermanager/0mq/README +++ /dev/null @@ -1,27 +0,0 @@ -This is a proof-of-concept that uses ZeroMQ as transport. -It uses a star topology as opposed to the native mesh network. - -Package ZMQ must be installed. All workers only run on localhost. - -All Julia nodes only connect to a "broker" process that listens on known ports -8100 and 8101 via ZMQ sockets. - - -All commands must be run from `examples/clustermanager/0mq` directory - -First, start the broker. In a new console type: - julia broker.jl - -This does not return. - -Next, start a Julia REPL and type: - include("ZMQCM.jl") - ZMQCM.start_master(4) # start with four workers - - -Alternatively, head.jl, a test script could be run. It just launches the requested number of workers, -executes a simple command on all of them and exits. - julia head.jl 4 - -NOTE: As stated this is a proof-of-concept. A real Julia cluster using ZMQ will probably use -different ZMQ socket types and optimize the transport. diff --git a/examples/clustermanager/0mq/ZMQCM.jl b/examples/clustermanager/0mq/ZMQCM.jl deleted file mode 100644 index 1a049161fec35..0000000000000 --- a/examples/clustermanager/0mq/ZMQCM.jl +++ /dev/null @@ -1,282 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -# the 0mq clustermanager depends on package ZMQ. For testing purposes, at least -# make sure the code loads without it. -try - using ZMQ -end - -using Distributed -import Distributed: launch, manage, connect, kill - -const BROKER_SUB_PORT = 8100 -const BROKER_PUB_PORT = 8101 - -const SELF_INITIATED = 0 -const REMOTE_INITIATED = 1 - -const PAYLOAD_MSG = "J" -const CONTROL_MSG = "Z" - -const REQUEST_ACK = "R" -const ACK_MSG = "A" -const KILL_MSG = "K" - -mutable struct ZMQCMan <: ClusterManager - map_zmq_julia::Dict{Int, Tuple} - c::Condition - isfree::Bool - ctx - pub - sub - zid_self - ZMQCMan() = new(Dict{Int, Tuple}(), Condition(), true) -end - -const manager = ZMQCMan() - -function lock_for_send() - if manager.isfree == true - manager.isfree = false - else - while manager.isfree == false - wait(manager.c) - if manager.isfree == true - manager.isfree = false - return - end - end - end -end - -function release_lock_for_send() - manager.isfree = true - notify(manager.c, all=true) -end - -function init_node(zid=0) - manager.ctx = Context(1) - pub=Socket(manager.ctx, PUB) # Outbound - connect(pub, "tcp://127.0.0.1:$BROKER_SUB_PORT") - - sub=Socket(manager.ctx, SUB) # In bound - connect(sub, "tcp://127.0.0.1:$BROKER_PUB_PORT") - ZMQ.set_subscribe(sub, string(zid)) - - manager.pub = pub - manager.sub = sub - manager.zid_self = zid - - (pub, sub) -end - -function send_data(zid, mtype, data) - lock_for_send() - ZMQ.send(manager.pub, Message(string(zid)), SNDMORE) - ZMQ.send(manager.pub, Message(string(manager.zid_self)), SNDMORE) - #println("Sending message of type $mtype to $zid") - ZMQ.send(manager.pub, Message(mtype), SNDMORE) - ZMQ.send(manager.pub, Message(data)) - release_lock_for_send() -end - -function setup_connection(zid, initiated_by) - try - read_stream=BufferStream() - write_stream=BufferStream() - - if initiated_by == REMOTE_INITIATED - test_remote = false - else - test_remote = true - end - - manager.map_zmq_julia[zid] = (read_stream, write_stream, test_remote) - - @schedule begin - while true - (r_s, w_s, do_test_remote) = manager.map_zmq_julia[zid] - if do_test_remote - send_data(zid, CONTROL_MSG, REQUEST_ACK) - sleep(0.5) - else - break - end - end - (r_s, w_s, do_test_remote) = manager.map_zmq_julia[zid] - - while true - data = readavailable(w_s) - send_data(zid, PAYLOAD_MSG, data) - end - end - (read_stream, write_stream) - catch e - Base.show_backtrace(STDOUT,catch_backtrace()) - println(e) - rethrow(e) - end -end - -# BROKER -function start_broker() - ctx=Context(1) - xpub=Socket(ctx, XPUB) - xsub=Socket(ctx, XSUB) - - ZMQ.bind(xsub, "tcp://127.0.0.1:$(BROKER_SUB_PORT)") - ZMQ.bind(xpub, "tcp://127.0.0.1:$(BROKER_PUB_PORT)") - - ccall((:zmq_proxy, :libzmq), Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), xsub.data, xpub.data, C_NULL) -# proxy(xsub, xpub) - - # control never comes here - ZMQ.close(xpub) - ZMQ.close(xsub) - ZMQ.close(ctx) -end - -function recv_data() - try - #println("On $(manager.zid_self) waiting to recv message") - zid = parse(Int,String(ZMQ.recv(manager.sub))) - assert(zid == manager.zid_self) - - from_zid = parse(Int,String(ZMQ.recv(manager.sub))) - mtype = String(ZMQ.recv(manager.sub)) - - #println("$zid received message of type $mtype from $from_zid") - - data = ZMQ.recv(manager.sub) - if mtype == CONTROL_MSG - cmsg = String(data) - if cmsg == REQUEST_ACK - #println("$from_zid REQUESTED_ACK from $zid") - # send back a control_msg - send_data(from_zid, CONTROL_MSG, ACK_MSG) - elseif cmsg == ACK_MSG - #println("$zid got ACK_MSG from $from_zid") - (r_s, w_s, test_remote) = manager.map_zmq_julia[from_zid] - manager.map_zmq_julia[from_zid] = (r_s, w_s, false) - elseif cmsg == KILL_MSG - exit(0) - else - error("Unknown control message : ", cmsg) - end - data = "" - end - - (from_zid, data) - catch e - Base.show_backtrace(STDOUT,catch_backtrace()) - println(e) - rethrow(e) - end - -end - -# MASTER -function start_master(np) - init_node() - @schedule begin - try - while true - (from_zid, data) = recv_data() - - #println("master recv data from $from_zid") - - (r_s, w_s, t_r) = manager.map_zmq_julia[from_zid] - unsafe_write(r_s, pointer(data), length(data)) - end - catch e - Base.show_backtrace(STDOUT,catch_backtrace()) - println(e) - rethrow(e) - end - end - - addprocs(manager; np=np) -end - - -function launch(manager::ZMQCMan, params::Dict, launched::Array, c::Condition) - #println("launch $(params[:np])") - for i in 1:params[:np] - io, pobj = open(`$(params[:exename]) worker.jl $i $(cluster_cookie())`, "r") - - wconfig = WorkerConfig() - wconfig.userdata = Dict(:zid=>i, :io=>io) - push!(launched, wconfig) - notify(c) - end -end - -function connect(manager::ZMQCMan, pid::Int, config::WorkerConfig) - #println("connect_m2w") - if myid() == 1 - zid = config.userdata[:zid] - config.connect_at = zid # This will be useful in the worker-to-worker connection setup. - - print_worker_stdout(config.userdata[:io], pid) - else - #println("connect_w2w") - zid = config.connect_at - config.userdata = Dict{Symbol, Any}(:zid=>zid) - end - - streams = setup_connection(zid, SELF_INITIATED) - - udata = config.userdata - udata[:streams] = streams - - streams -end - -# WORKER -function start_worker(zid, cookie) - #println("start_worker") - init_worker(cookie, ZMQCMan()) - init_node(zid) - - while true - (from_zid, data) = recv_data() - - #println("worker recv data from $from_zid") - - streams = get(manager.map_zmq_julia, from_zid, nothing) - if streams === nothing - # First time.. - (r_s, w_s) = setup_connection(from_zid, REMOTE_INITIATED) - process_messages(r_s, w_s) - else - (r_s, w_s, t_r) = streams - end - - unsafe_write(r_s, pointer(data), length(data)) - end -end - -function manage(manager::ZMQCMan, id::Int, config::WorkerConfig, op) - nothing -end - -function kill(manager::ZMQCMan, pid::Int, config::WorkerConfig) - send_data(config.userdata[:zid], CONTROL_MSG, KILL_MSG) - (r_s, w_s) = config.userdata[:streams] - close(r_s) - close(w_s) - - # remove from our map - delete!(manager.map_zmq_julia, config.userdata[:zid]) - - nothing -end - - -function print_worker_stdout(io, pid) - @schedule while !eof(io) - line = readline(io) - println(" From worker $(pid):\t$line") - end -end - diff --git a/examples/clustermanager/0mq/broker.jl b/examples/clustermanager/0mq/broker.jl deleted file mode 100644 index 87d2849046356..0000000000000 --- a/examples/clustermanager/0mq/broker.jl +++ /dev/null @@ -1,4 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -include("ZMQCM.jl") -start_broker() diff --git a/examples/clustermanager/0mq/head.jl b/examples/clustermanager/0mq/head.jl deleted file mode 100644 index ff0f718eb10b5..0000000000000 --- a/examples/clustermanager/0mq/head.jl +++ /dev/null @@ -1,11 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -include("ZMQCM.jl") - -# @spawn run(`julia broker.jl`) - -start_master(parse(Int,ARGS[1])) - -resp = pmap(x -> myid() *2, [1:nworkers()]) - -println(resp) diff --git a/examples/clustermanager/0mq/worker.jl b/examples/clustermanager/0mq/worker.jl deleted file mode 100644 index bbb2ebca60a85..0000000000000 --- a/examples/clustermanager/0mq/worker.jl +++ /dev/null @@ -1,5 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -include("ZMQCM.jl") - -start_worker(parse(Int,ARGS[1]), ARGS[2]) diff --git a/examples/clustermanager/simple/README b/examples/clustermanager/simple/README deleted file mode 100644 index b14d0699d4bc2..0000000000000 --- a/examples/clustermanager/simple/README +++ /dev/null @@ -1,12 +0,0 @@ -This is a simple proof-of-concept that uses UNIX domain sockets as transport. - -All commands must be run from `examples/clustermanager/simple` directory - -Start a Julia REPL and type: - include("UnixDomainCM.jl") - addprocs(UnixDomainCM(4)) # start with four workers - -Alternatively, head.jl, a test script could be run. It just launches the requested number of workers, -executes a simple command on all of them and exits. - julia head.jl 4 - diff --git a/examples/clustermanager/simple/UnixDomainCM.jl b/examples/clustermanager/simple/UnixDomainCM.jl deleted file mode 100644 index 29eb4f1975720..0000000000000 --- a/examples/clustermanager/simple/UnixDomainCM.jl +++ /dev/null @@ -1,95 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -using Distributed -import Distributed: launch, manage, connect, exit - -mutable struct UnixDomainCM <: ClusterManager - np::Integer -end - -function launch(manager::UnixDomainCM, params::Dict, launched::Array, c::Condition) -# println("launch $(manager.np)") - cookie = cluster_cookie() - for i in 1:manager.np - sockname = tempname() - try - __file__ = @__FILE__ - cmd = `$(params[:exename]) --startup-file=no $__file__ udwrkr $sockname $cookie` - pobj = open(cmd) - - wconfig = WorkerConfig() - wconfig.userdata = Dict(:sockname=>sockname, :io=>pobj.out, :process=>pobj) - push!(launched, wconfig) - notify(c) - catch e - println(e) - end - end -end - -function connect(manager::UnixDomainCM, pid::Int, config::WorkerConfig) - if myid() == 1 -# println("connect_m2w") - # This will be useful in the worker-to-worker connection setup. - config.connect_at = config.userdata[:sockname] - - print_worker_stdout(config.userdata[:io], pid) - else -# println("connect_w2w") - sockname = config.connect_at - config.userdata = Dict{Symbol, Any}(:sockname=>sockname) - end - - t = time() - while true - try - address = config.userdata[:sockname] - if isa(address, Tuple) - sock = connect(address...) - else - sock = connect(address) - end - return (sock, sock) - catch e - if (time() - t) > 30.0 - rethrow(e) - else - sleep(0.1) - end - end - end - -end - -# WORKER -function start_worker(sockname, cookie) - init_worker(cookie, UnixDomainCM(0)) - - srvr = listen(sockname) - while true - sock = accept(srvr) - process_messages(sock, sock) - end -end - -function manage(manager::UnixDomainCM, id::Int, config::WorkerConfig, op) - # Does not seem to be required, filesystem entry cleanup is happening automatically on process exit -# if op == :deregister -# try -# rm(config.userdata[:sockname]) -# end -# end - nothing -end - -function print_worker_stdout(io, pid) - @schedule while !eof(io) - line = readline(io) - println(" From worker $(pid):\t$line") - end -end - -if (length(ARGS) > 0) && (ARGS[1] == "udwrkr") - # script has been launched as a worker - start_worker(ARGS[2], ARGS[3]) -end diff --git a/examples/clustermanager/simple/head.jl b/examples/clustermanager/simple/head.jl deleted file mode 100644 index cb16b8eb4d740..0000000000000 --- a/examples/clustermanager/simple/head.jl +++ /dev/null @@ -1,7 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -include("UnixDomainCM.jl") - -addprocs(UnixDomainCM(parse(Int,ARGS[1]))) -resp = pmap(x -> myid() *2, [1:nworkers()]) -println(resp) diff --git a/examples/clustermanager/simple/test_simple.jl b/examples/clustermanager/simple/test_simple.jl deleted file mode 100644 index 1f4adb60214f5..0000000000000 --- a/examples/clustermanager/simple/test_simple.jl +++ /dev/null @@ -1,13 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -using Distributed -cmanpath = joinpath(@__DIR__, "UnixDomainCM.jl") -include(cmanpath) - -npids = addprocs(UnixDomainCM(2)) -assert(length(npids) == 2) -test_pids = [remotecall_fetch(myid, x) for x in npids] -assert(npids == test_pids) -rmprocs(npids; waitfor=1.0) - -exit(0) diff --git a/examples/dictchannel.jl b/examples/dictchannel.jl deleted file mode 100644 index f1b9bfd68a6ca..0000000000000 --- a/examples/dictchannel.jl +++ /dev/null @@ -1,34 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -import Base: put!, wait, isready, take!, fetch - -mutable struct DictChannel <: AbstractChannel - d::Dict - cond_take::Condition # waiting for data to become available - DictChannel() = new(Dict(), Condition()) -end - -function put!(D::DictChannel, k, v) - D.d[k] = v - notify(D.cond_take) - D -end - -function take!(D::DictChannel, k) - v=fetch(D,k) - delete!(D.d, k) - v -end - -isready(D::DictChannel) = length(D.d) > 1 -isready(D::DictChannel, k) = haskey(D.d,k) -function fetch(D::DictChannel, k) - wait(D,k) - D.d[k] -end - -function wait(D::DictChannel, k) - while !isready(D, k) - wait(D.cond_take) - end -end diff --git a/examples/lru.jl b/examples/lru.jl deleted file mode 100644 index 7703f078469a3..0000000000000 --- a/examples/lru.jl +++ /dev/null @@ -1,130 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -module LRUExample -# An LRU (Least Recently Used) cache is an associative data structure which -# maintains its contents in an order such that the most recently used item -# is at the beginning of the structure, and the least recently used at the end. -# -# This file specifies two types of LRU caches, both with and without a size -# limit. BoundedLRU has a limit and evicts the LRU item if a new item is added -# after that bound is reached. UnboundedLRU does not have a maximum size, but -# can be used as a basis for more complex LRUs. -# -# LRUs should follow the interfaces for general collections, indexable -# collections, and associative collections. - -# The standard implementation of an LRU backs a hash table with a doubly-linked -# list for O(1) operations when reordering on access and eviction. The Julia -# implementation instead backs the table with a Vector. For moderately-sized -# collections, the difference in performance is small, and this implmentation -# is simpler and easier to understand. - -import Base.isempty, Base.length, Base.sizeof -import Base.start, Base.next, Base.done -import Base.haskey, Base.get -import Base.setindex!, Base.getindex, Base.delete!, Base.empty! -import Base.show - -abstract type LRU{K,V} <: AbstractDict{K,V} end - -# Default cache size -const __MAXCACHE = 1024 - -mutable struct CacheItem{K,V} - k::K - v::V -end - -mutable struct UnboundedLRU{K,V} <: LRU{K,V} - ht::Dict - q::Vector{CacheItem} - - UnboundedLRU{K,V}() where {K,V} = new(Dict(), similar(Vector{CacheItem}(uninitialized, 1), 0)) -end -UnboundedLRU() = UnboundedLRU{Any, Any}() - -mutable struct BoundedLRU{K,V} <: LRU{K,V} - ht::Dict - q::Vector{CacheItem} - maxsize::Int - - BoundedLRU{K,V}(m) where {K,V} = new(Dict(), similar(Vector{CacheItem}(uninitialized, 1), 0), m) - BoundedLRU{K,V}() where {K,V} = BoundedLRU(__MAXCACHE) -end -BoundedLRU(m) = BoundedLRU{Any, Any}(m) -BoundedLRU() = BoundedLRU{Any, Any}() - -## collections ## - -isempty(lru::LRU) = isempty(lru.q) -length(lru::LRU) = length(lru.q) - -## associative ## - -# Should this check count as an access? -haskey(lru::LRU, key) = haskey(lru.ht, key) - -get(lru::LRU, key, default) = haskey(lru, key) ? lru[key] : default - -function empty!(lru::LRU) - empty!(lru.ht) - empty!(lru.q) -end - - -show(io::IO, lru::UnboundedLRU) = print(io,"UnboundedLRU()") -show(io::IO, lru::BoundedLRU) = print(io,"BoundedLRU($(lru.maxsize))") - -## indexable ## - -# Method to do the second, slow lookup in the list with early return. -function locate(q, x) - for i = 1:length(q) - if q[i] == x - return i - end - end - error("Item not found.") -end - -function getindex(lru::LRU, key) - item = lru.ht[key] - idx = locate(lru.q, item) - splice!(lru.q, idx) - pushfirst!(lru.q, item) - item.v -end - -function setindex!(lru::LRU, v, key) - if haskey(lru, key) - item = lru.ht[key] - idx = locate(lru.q, item) - item.v = v - splice!(lru.q, idx) - else - item = CacheItem(key, v) - lru.ht[key] = item - end - pushfirst!(lru.q, item) -end - -# Eviction -function setindex!(lru::BoundedLRU, v::V, key::K) where {V,K} - invoke(setindex!, Tuple{LRU,V,K}, lru, v, key) - nrm = length(lru) - lru.maxsize - for i in 1:nrm - rm = pop!(lru.q) - delete!(lru.ht, rm.k) - end -end - -## associative ## - -function delete!(lru::LRU, key) - item = lru.ht[key] - idx = locate(lru.q, item) - delete!(lru.ht, key) - delete!(lru.q, idx) -end - -end # module diff --git a/examples/lru_test.jl b/examples/lru_test.jl deleted file mode 100644 index 5c797c2a57906..0000000000000 --- a/examples/lru_test.jl +++ /dev/null @@ -1,47 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -using .LRUExample - -TestLRU = LRUExample.UnboundedLRU{String, String}() -TestBLRU = LRUExample.BoundedLRU{String, String}(1000) - -get_str(i) = String(vcat(map(x->[x>>4; x&0x0F], reinterpret(UInt8, [Int32(i)]))...)) - -isbounded(::Type{L}) where {L<:LRUExample.LRU} = any(map(n->n==:maxsize, fieldnames(L))) -isbounded(l::L) where {L<:LRUExample.LRU} = isbounded(L) - -nmax = map(x->round(Int, exp10(x)), range(2, stop=5, length=4)) - -function lrutest() - #println("LRU consistency tests") - for lru in (TestLRU,TestBLRU) - for n in nmax - empty!(lru) - #@printf(" %s, %d items\n", lru, n) - #print(" Simple eviction: ") - for i in 1:n - str = get_str(i) - lru[str] = str - @assert lru.q[1].v == str - if isbounded(lru) && length(lru) >= lru.maxsize - tailstr = get_str(i-lru.maxsize+1) - @assert lru.q[end].v == tailstr - end - end - #println("pass") - - #print(" Lookup, random access: ") - for i in 1:n - str = get_str(rand(1:n)) - if haskey(lru, str) # the bounded LRUs can have cache misses - blah = lru[str] - @assert lru.q[1].v == blah - end - end - #println("pass") - end - empty!(lru) - end -end - -lrutest() diff --git a/examples/ndgrid.jl b/examples/ndgrid.jl deleted file mode 100644 index f5fce291c4636..0000000000000 --- a/examples/ndgrid.jl +++ /dev/null @@ -1,52 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -ndgrid(v::AbstractVector) = copy(v) - -function ndgrid(v1::AbstractVector{T}, v2::AbstractVector{T}) where T - m, n = length(v1), length(v2) - v1 = reshape(v1, m, 1) - v2 = reshape(v2, 1, n) - (repeat(v1, 1, n), repeat(v2, m, 1)) -end - -function ndgrid_fill(a, v, s, snext) - for j = 1:length(a) - a[j] = v[div(rem(j-1, snext), s)+1] - end -end - -function ndgrid(vs::AbstractVector{T}...) where T - n = length(vs) - sz = map(length, vs) - out = ntuple(i->Array{T}(uninitialized, sz), n) - s = 1 - for i=1:n - a = out[i]::Array - v = vs[i] - snext = s*size(a,i) - ndgrid_fill(a, v, s, snext) - s = snext - end - out -end - -meshgrid(v::AbstractVector) = meshgrid(v, v) - -function meshgrid(vx::AbstractVector{T}, vy::AbstractVector{T}) where T - m, n = length(vy), length(vx) - vx = reshape(vx, 1, n) - vy = reshape(vy, m, 1) - (repeat(vx, m, 1), repeat(vy, 1, n)) -end - -function meshgrid(vx::AbstractVector{T}, vy::AbstractVector{T}, - vz::AbstractVector{T}) where T - m, n, o = length(vy), length(vx), length(vz) - vx = reshape(vx, 1, n, 1) - vy = reshape(vy, m, 1, 1) - vz = reshape(vz, 1, 1, o) - om = fill(1, m) - on = fill(1, n) - oo = fill(1, o) - (vx[om, :, oo], vy[:, on, oo], vz[om, on, :]) -end diff --git a/examples/queens.jl b/examples/queens.jl deleted file mode 100644 index e44e2fd2c083b..0000000000000 --- a/examples/queens.jl +++ /dev/null @@ -1,28 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -# n-queens (nqueens) solver, for nsquaresx-by-nsquaresy board - -struct Queen - x::Int - y::Int -end -hitshorz(queena, queenb) = queena.x == queenb.x -hitsvert(queena, queenb) = queena.y == queenb.y -hitsdiag(queena, queenb) = abs(queena.x - queenb.x) == abs(queena.y - queenb.y) -hitshvd(qa, qb) = hitshorz(qa, qb) || hitsvert(qa, qb) || hitsdiag(qa, qb) -hitsany(testqueen, queens) = any(q -> hitshvd(testqueen, q), queens) - -function trysolve(nsquaresx, nsquaresy, nqueens, presqueens = ()) - nqueens == 0 && return presqueens - for xsquare in 1:nsquaresx - for ysquare in 1:nsquaresy - testqueen = Queen(xsquare, ysquare) - if !hitsany(testqueen, presqueens) - tryqueens = (presqueens..., testqueen) - maybesol = trysolve(nsquaresx, nsquaresy, nqueens - 1, tryqueens) - maybesol !== nothing && return maybesol - end - end - end - return nothing -end diff --git a/examples/quine.jl b/examples/quine.jl deleted file mode 100644 index aae47e3dbfdbf..0000000000000 --- a/examples/quine.jl +++ /dev/null @@ -1,4 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -x="println(\"# This file is a part of Julia. License is MIT: https://julialang.org/license\\n\\nx=\$(repr(x))\\n\$x\")" -println("# This file is a part of Julia. License is MIT: https://julialang.org/license\n\nx=$(repr(x))\n$x") diff --git a/examples/staged.jl b/examples/staged.jl deleted file mode 100644 index 96f3ebb6aa6c6..0000000000000 --- a/examples/staged.jl +++ /dev/null @@ -1,61 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -function add_method(gf, an, at, body) - argexs = [Expr(Symbol("::"), an[i], at[i]) for i=1:length(an)] - def = quote - let __F__=($gf) - function __F__($(argexs...)) - $body - end - end - end - eval(def) -end - -macro staged(fdef) - if !isa(fdef,Expr) || fdef.head !== :function - error("@staged: expected method definition") - end - fname = fdef.args[1].args[1] - argspec = fdef.args[1].args[2:end] - argnames = map(x->(isa(x,Expr) ? x.args[1] : x), argspec) - qargnames = map(x->Expr(:quote,x), argnames) - fbody = fdef.args[2] - @gensym gengf argtypes expander genbody - quote - let ($gengf) - global ($fname) # should be "outer" - local ($expander) - function ($expander)($(argnames...)) - $fbody - end - ($gengf)() = 0 # should be initially empty GF - function ($fname)($(argspec...)) - ($argtypes) = typeof(tuple($(argnames...))) - if !hasmethod($gengf, $argtypes) - ($genbody) = apply(($expander), ($argtypes)) - add_method($gengf, Any[$(qargnames...)], - $argtypes, $genbody) - end - return ($gengf)($(argnames...)) - end - end - end -end - -# example - -@staged function nloops(dims::Tuple) - names = map(x->gensym(), dims) - ex = quote - println([$(names...)]) - end - for i = 1:length(dims) - ex = quote - for $(names[i]) in dims[$i] - $ex - end - end - end - ex -end diff --git a/examples/time.jl b/examples/time.jl deleted file mode 100644 index 2ffb69dcaabbd..0000000000000 --- a/examples/time.jl +++ /dev/null @@ -1,45 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -module Time -export TimeDelta - -import Base.show, Base.+, Base.-, Base.convert, Base.promote_rule - -struct TimeDelta{p} - v::Int64 -end - -const PREFIXES = [ - "yocto", "zepto", "atto", "femto", "pico", "nano", "micro", "milli", - "", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta", -] -const ZERO_INDEX = 9 -const MAX_INDEX = 17 - -function show(io::IO, x::TimeDelta{p}) where p - k = max(1,min(MAX_INDEX,fld(p,3)+ZERO_INDEX)) - r = p-3(k-ZERO_INDEX) - prefix = PREFIXES[k] - if r == 0 - s = x.v == 1 ? "" : "s" - print(io, "$(x.v) $(prefix)second$s") - elseif r > 0 - print(io, "$(x.v*10^r) $(prefix)seconds") - else - print(io, "$(x.v/10^-r) $(prefix)seconds") - end -end - -convert(::Type{TimeDelta{p}}, x::TimeDelta{q}) where {p,q} = - TimeDelta{p}(p <= q ? x.v*10^(q-p) : div(x.v,10^(p-q))) - -promote_rule(::Type{TimeDelta{p}}, ::Type{TimeDelta{q}}) where {p,q} = TimeDelta{min(p,q)} - -(-)(x::TimeDelta{p}) where {p} = TimeDelta{p}(-x.v) -(+)(x::TimeDelta{p}, y::TimeDelta{p}) where {p} = TimeDelta{p}(x.v+y.v) -(-)(x::TimeDelta{p}, y::TimeDelta{p}) where {p} = TimeDelta{p}(x.v-y.v) - -(+)(x::TimeDelta, y::TimeDelta) = +(promote(x,y)...) -(-)(x::TimeDelta, y::TimeDelta) = -(promote(x,y)...) - -end # module diff --git a/examples/typetree.jl b/examples/typetree.jl deleted file mode 100644 index 1735f32a01c02..0000000000000 --- a/examples/typetree.jl +++ /dev/null @@ -1,154 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -module TypeTrees -## -# Generate a text graphic of Julia modules type tree -## - -struct Binding - mod::Module - sym::Symbol -end -Binding(tn::TypeName) = Binding(tn.module, tn.name) -Base.isless(a::Binding, b::Binding) = isless(a.sym, b.sym) - -# The node type holds the type of the current node and a dict of subtypes -struct TTNode - typ # ::Type - subtypes::Dict{Binding, TTNode} - - TTNode(@nospecialize t) = new(t, Dict{Binding, TTNode}()) -end - -# Add a node to a dict if not added -function add_ttnode(subtypes::Dict{Binding, TTNode}, sname::Binding, tnode::TTNode) - return get!(subtypes, sname, tnode) -end - -function add_ttnode(subtypes::Dict{Binding, TTNode}, sname::Binding, t::Type) - return get!(subtypes, sname, TTNode(t)) -end - -# Store a type and its type hierarchy chain -# Recurse till we reach the top level type -function store_type(sname::Binding, t::Union) - suptype = Union - tnode = TTNode(t) - - # store unions under Union type - subtypes = store_type(Binding(suptype.name), suptype) - add_ttnode(subtypes, sname, tnode) - store_union(sname, tnode, t) - - # unions are also in a sense related to the types of their components - - return tnode.subtypes -end -function store_union(sname::Binding, tnode::TTNode, @nospecialize t) - t = Base.unwrap_unionall(t) - if isa(t, Union) - store_union(sname, tnode, t.a) - store_union(sname, tnode, t.b) - elseif isa(t, DataType) - binding = Binding(t.name) - subtypes = store_type(binding, t) - add_ttnode(subtypes, sname, tnode) - end - nothing -end - -function store_type(sname::Binding, t::UnionAll) - suptype = Base.unwrap_unionall(t) - binding = isa(suptype, DataType) ? Binding(suptype.name) : Binding(Main, string(suptype::Union)) - subtypes = store_type(binding, suptype) - tnode = add_ttnode(subtypes, sname, t) - return tnode.subtypes -end - -function store_type(sname::Binding, t::DataType) - suptype = supertype(t) - subtypes = (suptype != t) ? store_type(Binding(suptype.name), suptype) : types_tree - tnode = add_ttnode(subtypes, sname, t) - return tnode.subtypes -end - -# examine all symbols in module and store those that are types -function store_all_from(m::Module) - for s in names(m, all = true) - if isdefined(m, s) && !Base.isdeprecated(m, s) - t = getfield(m, s) - if isa(t, Type) && t !== Union{} - store_type(Binding(m, s), t) - elseif isa(t, Module) && nameof(t) === s && parentmodule(t) === m && t !== m - store_all_from(t) - end - end - end -end - -type_props(typ) = "" -type_props(typ::DataType) = string("<<", - typ.abstract ? " abstract" : " concrete", - typ.mutable ? " mutable" : " immutable", - typ.layout != C_NULL ? string( - Base.datatype_pointerfree(typ) ? " pointerfree" : "", - Base.datatype_haspadding(typ) ? " haspadding" : "", - " nfields:", Core.nfields(typ), - " size:", typ.size, - ", align:", Base.datatype_alignment(typ)) : "", - " >>") - -function print_tree(subtypes::Dict{Binding, TTNode}, pfx::String="") - for b in sort!(collect(keys(subtypes))) - v = subtypes[b] - ishidden = unsafe_load(Base.unsafe_convert(Ptr{UInt8}, b.sym)) == UInt8('#') - if ishidden && supertype(v.typ) === Function - continue - end - if b.mod === Main - n = string(b.sym) - elseif !isa(v.typ, DataType) || v.typ.name.module != b.mod || v.typ.name.name != b.sym - n_io = IOBuffer() - print(n_io, b.mod, '.', b.sym) - ua = v.typ - if isa(ua, UnionAll) - print(n_io, "{") - while true - print(n_io, ua.var) - ua = ua.body - if isa(ua, UnionAll) - print(n_io, ", ") - else - break - end - end - print(n_io, "}") - end - n = String(take!(n_io)) - else - n = string(v.typ) - end - if n == string(v.typ) - println(pfx, "+- ", n, " ", type_props(v.typ)) - else - println(pfx, "+- ", n, " = ", v.typ, " ", type_props(v.typ)) - end - v.typ === Function && println(pfx, ". ## hiding implicit Function subtypes ##") - print_tree(v.subtypes, pfx * ". ") - end -end - - -# TODO: optionally take module names in command line -# TODO: option to list subtrees of type tree, or other symbol types -const types_tree = Dict{Binding, TTNode}() - -store_all_from(Main) - -# print_tree(types_tree) - -end # module - -if !isinteractive() - TypeTrees.print_tree(TypeTrees.types_tree) -end diff --git a/examples/wordcount.jl b/examples/wordcount.jl deleted file mode 100644 index f93dd84e2893d..0000000000000 --- a/examples/wordcount.jl +++ /dev/null @@ -1,86 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -# wordcount.jl -# -# Implementation of parallelized "word-count" of a text, inspired by the -# Hadoop WordCount example. Uses @spawn and fetch() to parallelize -# the "map" task. Reduce is currently done single-threaded. -# -# To run in parallel on a string stored in variable `text`: -# julia -p -# julia> require("/examples/wordcount.jl") -# julia> ...(define text)... -# julia> counts=parallel_wordcount(text) -# -# Or to run on a group of files, writing results to an output file: -# julia -p -# julia> require("/examples/wordcount.jl") -# julia> wordcount_files("/tmp/output.txt", "/tmp/input1.txt","/tmp/input2.txt",...) - -# "Map" function. -# Takes a string. Returns a Dict with the number of times each word -# appears in that string. -function wordcount(text) - words=split(text,[' ','\n','\t','-','.',',',':',';'];keep=false) - counts=Dict() - for w = words - counts[w]=get(counts,w,0)+1 - end - return counts -end - -# "Reduce" function. -# Takes a collection of Dicts in the format returned by wordcount() -# Returns a Dict in which words that appear in multiple inputs -# have their totals added together. -function wcreduce(wcs) - counts=Dict() - for c in wcs, (k,v) in c - counts[k] = get(counts,k,0)+v - end - return counts -end - -# Splits input string into nprocs() equal-sized chunks (last one rounds up), -# and @spawns wordcount() for each chunk to run in parallel. Then fetch()s -# results and performs wcreduce(). -function parallel_wordcount(text) - lines=split(text,'\n';keep=false) - np=nprocs() - unitsize=ceil(length(lines)/np) - wcounts=[] - rrefs=[] - # spawn procs - for i=1:np - first=unitsize*(i-1)+1 - last=unitsize*i - if last>length(lines) - last=length(lines) - end - subtext=join(lines[Int(first):Int(last)],"\n") - push!(rrefs, @spawn wordcount( subtext ) ) - end - # fetch results - while length(rrefs)>0 - push!(wcounts,fetch(pop!(rrefs))) - end - # reduce - count=wcreduce(wcounts) - return count -end - -# Takes the name of a result file, and a list of input file names. -# Combines the contents of all files, then performs a parallel_wordcount -# on the resulting string. Writes the results to result_file. -function wordcount_files(result_file,inputs...) - text = "" - for file in inputs - text *= read(file, String) - end - wc = parallel_wordcount(text) - open(result_file,"w") do f - for (k,v) in wc - println(f, k,"=",v) - end - end -end diff --git a/stdlib/InteractiveUtils/src/InteractiveUtils.jl b/stdlib/InteractiveUtils/src/InteractiveUtils.jl index 192d78df35dca..32dd46168e947 100644 --- a/stdlib/InteractiveUtils/src/InteractiveUtils.jl +++ b/stdlib/InteractiveUtils/src/InteractiveUtils.jl @@ -258,7 +258,7 @@ julia> subtypes(Integer) subtypes(x::Type) = _subtypes_in(Base.loaded_modules_array(), x) # dumptype is for displaying abstract type hierarchies, -# based on Jameson Nash's examples/typetree.jl +# based on Jameson Nash's typetree.jl in JuliaArchive/Examples function dumptype(io::IO, @nospecialize(x), n::Int, indent) print(io, x) n == 0 && return # too deeply nested diff --git a/test/choosetests.jl b/test/choosetests.jl index 86212f2fcba4a..7019bb98811c6 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -57,10 +57,6 @@ function choosetests(choices = []) "reinterpretarray", "syntax", "logging", "missing", "asyncmap" ] - if isdir(joinpath(Sys.BINDIR, Base.DOCDIR, "examples")) - push!(testnames, "examples") - end - tests = [] skip_tests = [] exit_on_error = false diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index 16d6346ce886c..41adeb4e53d80 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -269,7 +269,7 @@ let exename = `$(Base.julia_cmd()) --sysimage-native-code=yes --startup-file=no` end # --worker takes default / custom as argument (default/custom arguments - # tested in test/parallel.jl, test/examples.jl) + # tested in test/parallel.jl) @test !success(`$exename --worker=true`) # test passing arguments diff --git a/test/examples.jl b/test/examples.jl deleted file mode 100644 index 74c75030d300e..0000000000000 --- a/test/examples.jl +++ /dev/null @@ -1,81 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -using Random - -dir = joinpath(Sys.BINDIR, Base.DOCDIR, "examples") - -include(joinpath(dir, "bubblesort.jl")) -a = rand(1:100,100) -@test issorted(sort!(a;alg=BubbleSort)) - -include(joinpath(dir, "lru.jl")) -include(joinpath(dir, "lru_test.jl")) - -include(joinpath(dir, "ModInts.jl")) -b = ModInts.ModInt{10}(2) -c = ModInts.ModInt{10}(4) -@test b + c == ModInts.ModInt{10}(6) -@test c - b == ModInts.ModInt{10}(2) -x = ModInts.ModInt{256}(13) -y = inv(x) -@test y == ModInts.ModInt{256}(197) -@test x*y == ModInts.ModInt{256}(1) -@test_throws DomainError inv(ModInts.ModInt{8}(4)) - -include(joinpath(dir, "ndgrid.jl")) -r = repeat(1:10,1,10) -r1, r2 = ndgrid(1:10, 1:10) -@test r1 == r -@test r2 == r' -r3, r4 = meshgrid(1:10,1:10) -@test r3 == r' -@test r4 == r - -include(joinpath(dir, "queens.jl")) -@test trysolve(8, 8, 1) == (Queen(1,1),) -@test trysolve(8, 8, 7) == - (Queen(1,1), Queen(2,3), Queen(3,5), Queen(4,2), Queen(5,8), Queen(7,4), Queen(8,7)) - -# Different cluster managers do not play well together. Since -# the test infrastructure already uses LocalManager, we will test the simple -# cluster manager example through a new Julia session. -if Sys.isunix() - script = joinpath(dir, "clustermanager/simple/test_simple.jl") - cmd = `$(Base.julia_cmd()) --startup-file=no $script` - if !success(pipeline(cmd; stdout=STDOUT, stderr=STDERR)) && ccall(:jl_running_on_valgrind,Cint,()) == 0 - error("UnixDomainCM failed test, cmd : $cmd") - end -end - -using Distributed -dc_path = joinpath(dir, "dictchannel.jl") -# Run the remote on pid 1, since runtests may terminate workers -# at any time depending on memory usage -main_ex = quote - myid() == 1 || include($dc_path) - remotecall_fetch(1, $dc_path) do f - include(f) - nothing - end - RemoteChannel(()->DictChannel(), 1) -end -dc = eval(Main, main_ex) -@test typeof(dc) == RemoteChannel{Main.DictChannel} - -@test isready(dc) == false -put!(dc, 1, 2) -put!(dc, "Hello", "World") -@test isready(dc) == true -@test isready(dc, 1) == true -@test isready(dc, "Hello") == true -@test isready(dc, 2) == false -@test fetch(dc, 1) == 2 -@test fetch(dc, "Hello") == "World" -@test take!(dc, 1) == 2 -@test isready(dc, 1) == false - - -# At least make sure code loads -include(joinpath(dir, "wordcount.jl")) - -include(joinpath(dir, "clustermanager/0mq/ZMQCM.jl"))