Store Each Field in Its Own Array and the Group Reads Next-Door Bytes
Last timeNeighbouring Workers, Neighbouring Bytes
Records kept whole put a worker's field 32 bytes from its neighbour's. Keeping each field in its own array puts them 4 bytes apart, and the fetches saved can be counted in advance.
The last lesson ended with a rule: worker reads item , so that the group reads next-door bytes. Whether a job can follow it is decided before the function runs, by the order in which the data was written down.
Two ways to lay out records
Suppose the data is a million particles, each with eight properties of four bytes: three for position, three for velocity, a mass and a charge. A record is 32 bytes.
records kept whole (the vendor's term: array of structures)
x0 y0 z0 u0 v0 w0 m0 q0 x1 y1 z1 u1 v1 w1 m1 q1 x2 y2 ...
each field in its own array (the vendor's term: structure of arrays)
x0 x1 x2 x3 ... y0 y1 y2 y3 ... ... m0 m1 m2 m3 ... q0 q1 ...Now run a function in which worker reads the mass of particle , to add up the total mass, say.
The lesson stops here
4 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents