by Athas · 4y ago · 0 comments
The idea is that a single iteration divides the world into 2x2 squares and then applies effects sequentially within each square, but not between the squares. This means each square can be processed independently. In the next iteration, the division into squares shifts right and down by one cell each direction. This does mean you need more steps than in a sequential implementation, but I found it to be quite a principled approach to parallelizing cellular automata when I first read about it. One interesting side effect of this design is that falling particles end up being separated by blank space, as shown here: https://futhark-lang.org/static/falling-sand-2016.12.04.webm I wonder if that is fixable. (Although at larger scale it's not particularly visible: https://sigkill.dk/junk/diving-beet.webm)
For fun, I've written a Game Of Life implementation in GLSL and even though it is naively implemented it will run at thousands of iterations per second at 4K resolution on a 6 year old desktop gpu.
Unfortunately the demo video in the link you posted seems to be private, so I might be misunderstanding.
There are some diagonal interactions that are not directly expressible in this way, but they can propagate through the non-diagonal neighbours instead.
Thanks for reminding me.
A nice optimization trick is to make the cell buffers 2 cells wider and taller (or two times whatever the neighborhood radius is), and then before each generation you update the "gutter" by copying just the wrapped (or mirrored) pixels. Then your run the rule on the inset rectangle, and the code (in the inner loop) doesn't have to do bounds checking, and can assume there's a valid cell to read in all directions. That saves a hell of a lot of tests and branches in the inner loop.
Also, you you can define the Margolus neighborhood in terms of the Moore neighborhood + horizontal phase (even/odd column x) + vertical phase (even/odd row y) + time phase (even/odd time). With that information the rule can tell if it's at an even or odd step, and which of the four squares of the grid it's in.
That's how the CAM6 worked in hardware: it used the x/y/time phases as additional bits to determine the Margolus neighborhood lookup table index.
https://github.com/SimHacker/CAM6/blob/master/javascript/CAM...
Here's how my CAM6 emulator computes the CAM6-hardware-compatible Margolus lookup table index, based on the 9 Moore neighbors + phaseTime, phaseX, and phaseY:
function getTableIndexUnrotated(
nw, n, ne,
w, c, e,
sw, s, se,
phaseTime,
phaseX,
phaseY) {
// 0 1 2 3 4 5 6 7 8 9
// c0 c1 cw0 ccw0 opp0 cw1 ccw1 opp1 pha0 pha1
// 0x1 0x2 0x4 0x8 0x10 0x20 0x40 0x80 0x100 0x200
var cw, ccw, opp;
if (phaseTime) {
return (
// c c'
(c & 0x03) |
// cw cw'
(cw = (phaseX
? (phaseY
? (e & 0x03)
: (n & 0x03))
: (phaseY
? (s & 0x03)
: (w & 0x03))),
(((cw & 0x01) << 2) |
((cw & 0x02) << 4))) |
// ccw ccw'
(ccw = (phaseX
? (phaseY
? (s & 0x03)
: (e & 0x03))
: (phaseY
? (w & 0x03)
: (n & 0x03))),
(((ccw & 0x01) << 3) |
((ccw & 0x02) << 5))) |
// opp opp'
(opp = (phaseX
? (phaseY
? (se & 0x03)
: (ne & 0x03))
: (phaseY
? (sw & 0x03)
: (nw & 0x03))),
(((opp & 0x01) << 4) |
((opp & 0x02) << 6))) |
// pha pha'
0x200);
} else {
return (
// c c'
(c & 0x03) |
// cw cw'
(cw = (phaseX
? (phaseY
? (w & 0x03)
: (s & 0x03))
: (phaseY
? (n & 0x03)
: (e & 0x03))),
(((cw & 0x01) << 2) |
((cw & 0x02) << 4))) |
// ccw ccw'
(ccw = (phaseX
? (phaseY
? (n & 0x03)
: (w & 0x03))
: (phaseY
? (e & 0x03)
: (s & 0x03))),
(((ccw & 0x01) << 3) |
((ccw & 0x02) << 5))) |
// opp opp'
(opp = (phaseX
? (phaseY
? (nw & 0x03)
: (sw & 0x03))
: (phaseY
? (ne & 0x03)
: (se & 0x03))),
(((opp & 0x01) << 4) |
((opp & 0x02) << 6))) |
// pha pha'
0x100);
}
};edit: I don't have a good video of this atm, but just to demonstrate it: https://www.youtube.com/watch?v=rItnlDmGALU
it's not visualized in the video, but the pixels also have temperature, and materials a sort of stickyness (basically sand that takes longer to form into a pyramid), that's about it.
>the division into squares shifts right and down by one cell each direction.
The MFM non-deterministic equivalent of the Margolus neighborhood's alternating x,y offset is to randomly execute non-overlapping neighborhoods in parallel. That has the same effect of incrementally diffusing information evenly in all directions over time, just not perfectly, synchronously, symmetrically, and deterministically like the Margolus neighborhood does.
Moveable Feast Machine rules make it much easy to implement particle based simulations than with traditional cellular automata rules, which compute just the center cell. Instead, the MFM rules can simply "pick up and move" any number of particles within the wider neighborhood.
They can implement all kinds of interesting chemical and biological behaviors between locally interacting particles, like holding molecules of different particles together with atomic bonds, and constructing membranes like cell walls that separate and contain and transport other particles, and implementing magical computational "force fields" and "tractor beams" and "traffic lights" that route other particles around. They're even good for simulating computational DNA-like behaviors:
https://www.youtube.com/watch?v=DauJ51CTIq8
>Programming the Movable Feast Machine with λ-Codons
>λ-Codons provide a mechanism for describing arbitrary computations in the Movable Feast Machine (MFM). A collection of λ-Codon molecules describe the computation by a series of primitive functions. Evaluator particles carry along a stack of memory (which initially contains the input to the program) and visit the λ-Codons, which they interpret as functions and apply to their stacks. When the program completes, they transmute into output particles and carry the answer to the output terminals (left).
The Moveable Feast Machine is similar to cellular automata, but different in some important ways, that make it extremely robust and fault tolerant:
It's a "Robust First" asynchronous distributed fault tolerant cellular-automata-like computer architecture.
Robust programs running on massively parallel unreliable hardware can actually tolerate hardware failure and repair themselves. The Demon Hoard Sort algorithm is an inherently robust sorting algorithm for the Moveable Feast Machine.
http://movablefeastmachine.org/
The "Distributed City Generation" video demonstrates a Movable Feast Machine rule that builds a self-healing city that fills all available space with urban sprawl, with cars that drive between buildings, and city streets that adaptively learn how to route the cars to their nearest destinations, and the city even repairs itself after disasters!
https://www.youtube.com/watch?v=XkSXERxucPc
Here's some more info:
https://news.ycombinator.com/item?id=14236973
JavaScript implementation:
https://github.com/walpolea/MFM-JS
Robust First Wiki: