mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-01 02:42:05 +00:00
* defaults to Orc * bootstrap using refc * use gc * init orc defines * unregister orc * fix gc * fix commands * add prepareMutation for orc * enable deepcopy for orc * prepareMutation * more fixes * some cases * bug #20081 * partial fixes * partial fixes * fixes command line * more fixes * build Nim with refc * use gc * more fixes * rstore * orc doesn't support threadpool * more shallowCopy * more fixes * fixes unsafeNew * workarounds * small * more fixes * fixes some megatest * tcodegenbugs1 refc * fxies megatest * build nimble with refc * workaround tensordsl tests * replace shallowCopy with move * fixes action * workaround * add todo * fixes important packages * unpublic unregisterArcOrc * fixes cpp * enable windows Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
61 lines
1.5 KiB
Nim
61 lines
1.5 KiB
Nim
discard """
|
|
matrix: "--mm:refc"
|
|
output: '''
|
|
'''
|
|
"""
|
|
|
|
# parallel convex hull for Nim bigbreak
|
|
# nim c --threads:on -d:release pconvex_hull.nim
|
|
import algorithm, sequtils, threadpool
|
|
|
|
type Point = tuple[x, y: float]
|
|
|
|
proc cmpPoint(a, b: Point): int =
|
|
result = cmp(a.x, b.x)
|
|
if result == 0:
|
|
result = cmp(a.y, b.y)
|
|
|
|
template cross[T](o, a, b: T): untyped =
|
|
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
|
|
|
template pro(): untyped =
|
|
while lr1 > 0 and cross(result[lr1 - 1], result[lr1], p[i]) <= 0:
|
|
discard result.pop
|
|
lr1 -= 1
|
|
result.add(p[i])
|
|
lr1 += 1
|
|
|
|
proc half[T](p: seq[T]; upper: bool): seq[T] =
|
|
var i, lr1: int
|
|
result = @[]
|
|
lr1 = -1
|
|
if upper:
|
|
i = 0
|
|
while i <= high(p):
|
|
pro()
|
|
i += 1
|
|
else:
|
|
i = high(p)
|
|
while i >= low(p):
|
|
pro()
|
|
i -= 1
|
|
discard result.pop
|
|
|
|
proc convex_hull[T](points: var seq[T], cmp: proc(x, y: T): int {.closure.}) : seq[T] =
|
|
if len(points) < 2: return points
|
|
points.sort(cmp)
|
|
var ul: array[2, FlowVar[seq[T]]]
|
|
parallel:
|
|
for k in 0..ul.high:
|
|
ul[k] = spawn half[T](points, k == 0)
|
|
result = concat(^ul[0], ^ul[1])
|
|
|
|
var s = map(toSeq(0..9999), proc(x: int): Point = (float(x div 100), float(x mod 100)))
|
|
# On some runs, this pool size reduction will set the "shutdown" attribute on the
|
|
# worker thread that executes our spawned task, before we can read the flowvars.
|
|
setMaxPoolSize 2
|
|
|
|
for i in 0..2:
|
|
doAssert convex_hull[Point](s, cmpPoint) ==
|
|
@[(0.0, 0.0), (99.0, 0.0), (99.0, 99.0), (0.0, 99.0)]
|