This is more an exercise in understanding the appropriate way to implement parallelism. I don't necessarily need an optimal program for running elementary cellular automata in particular.
Let's say we have N=10000
cells laid out in 1d. The ECA works by applying a local rule f
at each cell i
, given its neighbour states and it's own state:
c[t][i] = f(c[t-1][i-1], c[t-1][i], c[t-1][i+1])
The brute force way to evolve this for 9999 timesteps would be something like:
N = 10000
c[0] = np.random.randint(2, size=N)
for t in range(1, 9999):
for i in range(N):
temp[i] = f(c[t-1][i-1], c[t-1][i], c[t-1][i+1])
c[t] = temp.copy()
give or take some variable initializations.
Is there a way to parallelize the N=10000
applications at each time step? Should this be done using threads? Or are those local rules too fast and simple to really take advantage of anything? I have very little knowledge of taking advantage of parallelism with code, but this seems like a natural setting for it.
question from:
https://stackoverflow.com/questions/66050227/how-to-take-advantage-of-parallelism-when-implementing-elementary-cellular-autom 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…