Open
Description
First, I have just tried the parallelForStaged example of the README.md file.
the statement sync(Weave)
fails to compile with
parallelForStagedSC.nim(16, 7) Error: type mismatch: got <typedesc[Weave]>
but expected one of:
proc sync[T](fv: Flowvar[T]): T
first type mismatch at position: 1
required type for fv: Flowvar[sync.T]
but expression 'Weave' is of type: typedesc[Weave]
expression: sync(Weave)
Then, I have introduced an awaitable: MyLoop
statement, and I have replaced the failing sync(Weave) with
sync(MyLoop)
(note the missing discard here)
This gives a horrible error message
weave/cross_thread_com/scoped_barriers.nim(66, 12) Warning: Moving a shared resource (an atomic type). [User]
.................................................
/home/jarausch/Nim_My/Par/parallelForStaged.nim(17, 7) Error: type mismatch: got 'bool' for '
let res = addr(result)
type
CapturedTy = (typeof(res))
discard
proc weaveParallelStagedAwaitableSection(
weaveParallelStagedSectionClosureEnv_: ptr (typeof(res))) {.nimcall, gcsafe,
inline.} =
let res = weaveParallelStagedSectionClosureEnv_[]
loadBalance(Weave)
var localSum = 0
let this`gensym6 = workerContext.worker.currentTask
block:
{.noSideEffect.}:
const
loc`gensym17 = (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim",
line: 86, column: 14)
ploc`gensym17 = "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim(86, 15)"
{.line: (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim",
line: 86, column: 14).}:
if not this`gensym6.isLoop:
failedAssertImpl("/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim(86, 15) `\nthis`gensym6.isLoop` " &
("\n Contract violated for transient condition at parallel_for_staged.nim:69\n this`gensym6.isLoop\n The following values are contrary to expectations:\n " &
$ $this`gensym6.isLoop &
" [Worker " &
"N/A" &
"]\n"))
{.noSideEffect.}:
const
loc`gensym24 = (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim",
line: 86, column: 14)
ploc`gensym24 = "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim(86, 15)"
{.line: (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim",
line: 86, column: 14).}:
if not (this`gensym6.start == this`gensym6.cur):
failedAssertImpl("/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim(86, 15) `\nthis`gensym6.start == this`gensym6.cur` " &
("\n Contract violated for transient condition at parallel_for_staged.nim:70\n this`gensym6.start == this`gensym6.cur\n The following values are contrary to expectations:\n " &
$`&`(`&`(`$`($this`gensym6.start), " == "), `$`($this`gensym6.cur)) &
" [Worker " &
"N/A" &
"]\n"))
var i = this`gensym6.start
this`gensym6.cur += this`gensym6.stride
while i < this`gensym6.stop:
localSum += i
echo [getThreadId(Weave), " -> ", i]
i += this`gensym6.stride
this`gensym6.cur += this`gensym6.stride
loadBalance(Weave)
echo ["Thread ", getThreadId(Weave), ": localsum = ", localSum]
atomicInc(res[], localSum)
block:
while not isNil(this`gensym6.futures):
let fvNode`gensym6 = cast[FlowvarNode](this`gensym6.futures)
this`gensym6.futures = cast[pointer](fvNode`gensym6.next)
let dummyFV`gensym6 = cast[Flowvar[bool]](fvNode`gensym6.chan)
let isLastIter`gensym6 = sync(dummyFV`gensym6)
{.noSideEffect.}:
const
loc`gensym69 = (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim",
line: 86, column: 14)
ploc`gensym69 = "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim(86, 15)"
{.line: (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim",
line: 86, column: 14).}:
if not not isLastIter`gensym6:
failedAssertImpl("/home/jarausch/.nimble/pkgs/weave-#master/weave/instrumentation/contracts.nim(86, 15) `\nnot isLastIter`gensym6` \n Contract violated for transient condition at parallel_for_staged.nim:96\n not isLastIter`gensym6\n The following values are contrary to expectations:\n not isLastIter`gensym6 [Worker N/A]\n")
recycleFVN(fvNode`gensym6)
proc weaveTask_ParallelStagedAwaitable_(param`gensym2: pointer) {.nimcall,
gcsafe.} =
let this`gensym2 = workerContext.worker.currentTask
const
loc`gensym74 = (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/parallel_for_staged.nim",
line: 191, column: 8)
ploc`gensym74 = "/home/jarausch/.nimble/pkgs/weave-#master/weave/parallel_for_staged.nim(191, 9)"
{.line: (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/parallel_for_staged.nim",
line: 191, column: 8).}:
if not not isNil(this`gensym2.parent):
failedAssertImpl("/home/jarausch/.nimble/pkgs/weave-#master/weave/parallel_for_staged.nim(191, 9) `not isRootTask(this`gensym2)` ")
let lastLoopIter`gensym2 = cast[ptr Flowvar[bool]](param`gensym2)
let offset`gensym2 = cast[pointer](cast[ByteAddress](param`gensym2) +% 8)
let weaveParallelStagedSectionClosureEnv_ = cast[ptr CapturedTy](offset`gensym2)
weaveParallelStagedAwaitableSection(weaveParallelStagedSectionClosureEnv_)
readyWith(lastLoopIter`gensym2[], this`gensym2.isInitialIter)
var MyLoop: Flowvar[bool]
const
loc`gensym86 = (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/parallel_macros.nim",
line: 292, column: 6)
ploc`gensym86 = "/home/jarausch/.nimble/pkgs/weave-#master/weave/parallel_macros.nim(292, 7)"
{.line: (filename: "/home/jarausch/.nimble/pkgs/weave-#master/weave/parallel_macros.nim",
line: 292, column: 6).}:
if not not isSpawned(MyLoop):
failedAssertImpl("/home/jarausch/.nimble/pkgs/weave-#master/weave/parallel_macros.nim(292, 7) `not isSpawned(MyLoop)` Trying to override an allocated Flowvar.")
MyLoop = newFlowVar(globalCtx.mempools[workerContext.worker.ID], T)
if (
when nimvm:
not (`+`(n, 1) - 0 == 0)
else:
likelyProc:
not (`+`(n, 1) - 0 == 0)
):
block enq_deq_task`gensym3:
let task = newTaskFromCache()
task.parent = workerContext.worker.currentTask
task.fn = weaveTask_ParallelStagedAwaitable_
registerDescendant(workerContext.worker.currentScope)
task.scopedBarrier = workerContext.worker.currentScope
task.start = 0
task.cur = 0
task.stop = `+`(n, 1)
task.stride = 1
task.futureSize = uint8(1)
task.hasFuture = true
task.isLoop = true
task.isInitialIter = true
cast[ptr (Flowvar[bool], CapturedTy)](addr(task.data))[] = (MyLoop, res)
schedule(task)
else:
readyWith(MyLoop, default(T))
sync(MyLoop)' but expected 'int'