diff --git a/Makefile b/Makefile index 5e348cb397..8a345872d5 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ START_TIME ?= WRAPPER = $(patsubst run_%,%,$(RUN_BENCH_TARGET)) -PACKAGES = sexplib0 re yojson react uuidm cpdf nbcodec minilight cubicle orun rungen +PACKAGES = sexplib0 re yojson react uuidm cpdf nbcodec minilight cubicle orun rungen containers ifeq ($(findstring multibench,$(BUILD_BENCH_TARGET)),multibench) PACKAGES += lockfree kcas domainslib ctypes diff --git a/benchmarks/quick-sort/dune b/benchmarks/quick-sort/dune new file mode 100644 index 0000000000..6c7879d161 --- /dev/null +++ b/benchmarks/quick-sort/dune @@ -0,0 +1,7 @@ +(executable + (name qsort) + (modules qsort) + (libraries containers)) +(alias (name multibench_parallel) + (deps qsort.exe)) + \ No newline at end of file diff --git a/benchmarks/quick-sort/qsort.ml b/benchmarks/quick-sort/qsort.ml new file mode 100644 index 0000000000..aa34125d38 --- /dev/null +++ b/benchmarks/quick-sort/qsort.ml @@ -0,0 +1,48 @@ +module AS = CCArray +module A = Array + +let swap (arr : 'a AS.t) (i : int) (j : int) = + let temp = AS.get arr i in + AS.set arr i (AS.get arr j); + AS.set arr j temp + +let insert_sort (f : 'a -> 'a -> int) (arr : 'a AS.t) (start : int) (n : int) = + for i = start to n - 2 do + for j = i + 1 to n - 1 do + if f (AS.get arr j) (AS.get arr i) < 0 + then swap arr i j + else () + done + done + +let partition (f : 'a -> 'a -> int) (arr : 'a AS.t) (low : int) (high : int) = + let x = (AS.get arr high) and i = ref (low-1) in + if (high-low > 0) then + begin + for j= low to high - 1 do + if f (AS.get arr j) x <= 0 then + begin + i := !i+1; + swap arr !i j + end + done + end; + swap arr (!i+1) high; + !i+1 + +let rec quicksort (f : 'a -> 'a -> int) (arr : 'a AS.t) (low : int) (high : int) : unit = + if (high - low) <= 0 then () + (* else if (high - low) <= 8 + * then insert_sort f arr low (high+1) *) + else + let q = partition f arr low high in + quicksort f arr low (q-1); + quicksort f arr (q+1) high + +let sortInPlace (f : 'a -> 'a -> int) (arr : 'a AS.t) : unit = + quicksort f arr 0 (AS.length arr - 1) + +let sort (f : 'a -> 'a -> int) (arr : 'a array) : 'a array = + let result = A.copy arr in + quicksort f (A.fill result) 0 (A.length arr - 1) ; + result \ No newline at end of file diff --git a/dependencies/packages/containers/containers.3.7/opam b/dependencies/packages/containers/containers.3.7/opam new file mode 100644 index 0000000000..9700c066c0 --- /dev/null +++ b/dependencies/packages/containers/containers.3.7/opam @@ -0,0 +1,41 @@ +opam-version: "2.0" +maintainer: "simon.cruanes.2007@m4x.org" +license: "BSD-2-Clause" +synopsis: "A modular, clean and powerful extension of the OCaml standard library" +build: [ + ["dune" "build" "-p" name "-j" jobs] + ["dune" "build" "@doc" "-p" name ] {with-doc} + ["dune" "runtest" "-p" name "-j" jobs] {with-test & arch != "x86_32" & arch != "arm32"} +] +depends: [ + "ocaml" { >= "4.03.0" } + "dune" { >= "2.0" } + "dune-configurator" + "seq" # compat + "either" # compat + "qtest" { with-test } + "qcheck" { with-test } + "ounit" { with-test } + "iter" { with-test } + "gen" { with-test } + "csexp" { with-test } + "uutf" { with-test } + "odoc" { with-doc } +] +depopts: [ + "base-unix" + "base-threads" +] +tags: [ "stdlib" "containers" "iterators" "list" "heap" "queue" ] +homepage: "https://github.com/c-cube/ocaml-containers/" +doc: "https://c-cube.github.io/ocaml-containers" +dev-repo: "git+https://github.com/c-cube/ocaml-containers.git" +bug-reports: "https://github.com/c-cube/ocaml-containers/issues/" +authors: "Simon Cruanes" +url { + src: "https://github.com/c-cube/ocaml-containers/archive/v3.7.tar.gz" + checksum: [ + "md5=58298b6d26c5198157e19b583e9eca2c" + "sha512=70f99a062f7696d4ed7a6336532261c93c49a9858a84a12f7f3d60190a5c664198e70be6281dc7c7932c07325dc9c579ff521367e4c7e083566910ba0f9ea760" + ] +} \ No newline at end of file diff --git a/multicore_parallel_run_config.json b/multicore_parallel_run_config.json index ce5f69bc59..c999890aaa 100644 --- a/multicore_parallel_run_config.json +++ b/multicore_parallel_run_config.json @@ -734,6 +734,16 @@ "params": "100000" } ] + }, + { + "executable": "benchmarks/quick-sort/qsort.exe", + "name": "qsort", + "tags": ["my_bench"], + "runs": [ + { + "params": "", "paramwrapper": "taskset --cpu-list 1" + } + ] } ] } diff --git a/run_all_parallel.sh b/run_all_parallel.sh index d8d558b21e..5047fcae15 100644 --- a/run_all_parallel.sh +++ b/run_all_parallel.sh @@ -7,6 +7,7 @@ # TAG='"macro_bench"' make multicore_parallel_run_config_filtered.json +#TAG='"my_bench"' make multicore_parallel_run_config_filtered.json USE_SYS_DUNE_HACK=1 \ RUN_BENCH_TARGET=run_orunchrt \