This is using Nim 0.17.2 on Linux.
The code below works fine when run serially (as shown). When I try to run it in
parallel (uncomment the 3 lines, and comment the other) the compiler throws and
error about the garbage collector. I specifically compile it without using
garbage collection - `--gc:none` to let me (hopefully) do want I want to do.
I have a `nextp[r_row x c_column] array` and I want to load `nextp` on a column
by column basis, as the serial code does, but the compiler won't let me do it
in parallel.
**How do I get the compiler to follow orders and do what I want it to do?**
All memory is thread safe, and each thread only works on memory solely
associated with any individual prime column. Please don't tell my I need to
transpose the array so the columns becomes rows, because the compiler is only
able to work that way (another section of code does parallelize row functions).
Here's the code.
proc column_load(prime, j, k, r: int) =
for ri in residues: # for each prime|residue pair
let prod = r * ri # compute res cross-product
let row = posn[prod mod modpg] * pcnt # compute restrack address
# compute|store resgroup val of 1st prime mult for prime|residue pair
nextp[row + j] = uint(k*(prime + ri) + (prod-2) div modpg)
# Initialize the [rescnt x pcnt] 'nextp' table with resgroup values of the
# 1st prime multiples for each prime r1..sqrt(N) for each PG residue track.
proc nextp_init() =
# load 'nextp' with 1st prime multiples regroups vals on each residue
track
#parallel:
for j, prime in primes: # for each prime r1..sqrt(N)
let k = (prime-2) div modpg # find the resgroup it's in
let r = (prime-2) mod modpg + 2 # and its residue value
#spawn column_load(prime, j, k, r)
column_load(prime, j, k, r)
#sync()
Here's the compiler directive:
$ nim c --cc:gcc --d:release --threads:on --gc:none ssozp11x1e5bparnew64.nim
Here's the compiler output.
➜ nim nim c --cc:gcc --d:release --threads:on --gc:none
ssozp11x1e5bparnew64.nim
Hint: used config file '/home/jzakiya/nim-0.17.2/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: ssozp11x1e5bparnew64 [Processing]
Hint: math [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: algorithm [Processing]
Hint: typetraits [Processing]
Hint: times [Processing]
Hint: os [Processing]
Hint: posix [Processing]
Hint: ospaths [Processing]
Hint: osproc [Processing]
Hint: strtabs [Processing]
Hint: hashes [Processing]
Hint: streams [Processing]
Hint: cpuinfo [Processing]
Hint: linux [Processing]
Hint: threadpool [Processing]
Hint: cpuload [Processing]
Hint: locks [Processing]
generating parameters for P11
lib/system.nim(709, 9) Warning: 'newSeq(result, len)' uses GC'ed memory
[GcMem]
lib/system.nim(709, 9) Warning: 'newSeq(result, len)' uses GC'ed memory
[GcMem]
lib/system.nim(2702, 6) Warning: 'new(e94742)' uses GC'ed memory [GcMem]
lib/pure/strutils.nim(945, 65) Warning: '&("invalid unsigned integer: ",
s)' uses GC'ed memory [GcMem]
lib/system/sysio.nim(138, 16) Warning: 'setLen(string(line), chckRange(sp,
0, 9223372036854775807))' uses GC'ed memory [GcMem]
lib/system/sysio.nim(150, 20) Warning: 'setLen(string(line), chckRange(last
- 1, 0, 9223372036854775807))' uses GC'ed memory [GcMem]
lib/system/sysio.nim(158, 18) Warning: 'setLen(string(line),
chckRange(last, 0, 9223372036854775807))' uses GC'ed memory [GcMem]
lib/system/sysio.nim(166, 16) Warning: 'setLen(string(line), chckRange(pos
+ sp, 0, 9223372036854775807))' uses GC'ed memory [GcMem]
lib/system.nim(2722, 10) Warning: 'new(e)' uses GC'ed memory [GcMem]
lib/system.nim(709, 9) Warning: 'newSeq(result, len)' uses GC'ed memory
[GcMem]
lib/system/sysstr.nim(275, 9) Warning: 'setLen(result, chckRange(base + 32,
0, 9223372036854775807))' uses GC'ed memory [GcMem]
lib/system/sysstr.nim(287, 9) Warning: 'setLen(result, chckRange(base + i,
0, 9223372036854775807))' uses GC'ed memory [GcMem]
ssozp11x1e5bparnew64.nim(207, 39) Warning: 'KB' uses GC'ed memory [GcMem]
ssozp11x1e5bparnew64.nim(213, 31) Warning: 'maxpcs' uses GC'ed memory
[GcMem]
lib/system/repr.nim(39, 14) Warning: '$ buf' uses GC'ed memory [GcMem]
lib/system.nim(709, 9) Warning: 'newSeq(result, len)' uses GC'ed memory
[GcMem]
ssozp11x1e5bparnew64.nim(120, 13) Warning: '[]' uses GC'ed memory [GcMem]
ssozp11x1e5bparnew64.nim(125, 31) Warning: 'add(primes, modk + res[r])'
uses GC'ed memory [GcMem]
lib/system.nim(709, 9) Warning: 'newSeq(result, len)' uses GC'ed memory
[GcMem]
ssozp11x1e5bparnew64.nim(144, 24) Error: 'spawn' takes a GC safe call
expression
➜ nim