Eight Useful Bytes

struct particle {
    double x, y, z;
    double vx, vy, vz;
    unsigned id;
};
static struct particle p[100000];

double centroid_x(void) {
    double t = 0.0;
    for (int i = 0; i < 100000; i++) t += p[i].x;
    return t / 100000.0;
}

sizeof(struct particle) is 56 (six doubles, one unsigned, four bytes of tail padding for 8-byte alignment). Cache lines are 64 bytes and the array is far larger than any cache.

Every 64-byte line carries at least one x field, so the whole array is fetched line 0 (64 B) line 1 line 2 p[0] (56 B) p[1] p[2] p[3] shaded = the 8-byte x field the loop reads

How many bytes does centroid_x pull in from memory?

A

1,600,000

B

5,600,000

C

800,000, since only the x fields are read

D

6,400,000, one full 64-byte line per particle