Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Parallel benchmark Quick sort #342

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions benchmarks/quick-sort/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(executable
(name qsort)
(modules qsort)
(libraries containers))
(alias (name multibench_parallel)
(deps qsort.exe))

48 changes: 48 additions & 0 deletions benchmarks/quick-sort/qsort.ml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions dependencies/packages/containers/containers.3.7/opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
opam-version: "2.0"
maintainer: "[email protected]"
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"
]
}
10 changes: 10 additions & 0 deletions multicore_parallel_run_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,16 @@
"params": "100000"
}
]
},
{
"executable": "benchmarks/quick-sort/qsort.exe",
"name": "qsort",
"tags": ["my_bench"],
"runs": [
{
"params": "", "paramwrapper": "taskset --cpu-list 1"
}
]
}
]
}
1 change: 1 addition & 0 deletions run_all_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down