Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

multithreading - How to take advantage of parallelism when implementing elementary cellular automata in python?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...