mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +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>
30 lines
711 B
Nim
30 lines
711 B
Nim
discard """
|
|
matrix: "--mm:refc"
|
|
output: "500"
|
|
"""
|
|
|
|
import threadpool, sequtils
|
|
|
|
{.experimental: "parallel".}
|
|
|
|
proc linearFind(a: openArray[int]; x, offset: int): int =
|
|
for i, y in a:
|
|
if y == x: return i+offset
|
|
result = -1
|
|
|
|
proc parFind(a: seq[int]; x: int): int =
|
|
var results: array[4, int]
|
|
parallel:
|
|
if a.len >= 4:
|
|
let chunk = a.len div 4
|
|
results[0] = spawn linearFind(a[0 ..< chunk], x, 0)
|
|
results[1] = spawn linearFind(a[chunk ..< chunk*2], x, chunk)
|
|
results[2] = spawn linearFind(a[chunk*2 ..< chunk*3], x, chunk*2)
|
|
results[3] = spawn linearFind(a[chunk*3 ..< a.len], x, chunk*3)
|
|
result = max(results)
|
|
|
|
|
|
let data = toSeq(0..1000)
|
|
echo parFind(data, 500)
|
|
|