This code works as desired in parallel. Thanks for the instructions.
proc column_load(prime, j, k, r: int) {.gcsafe.} =
{.gcsafe.}:
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 for each row the resgroup vals for prime in column j
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: # do in 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) # load column resgroups for
prime
sync()
I guess it was surprising that even when I turned off compiling with garbage
collection (`--gc:none`) it still applied gc rules to this structure. Well, I
learned a little bit more about Nim.