Skip to content

Incorrect AoS initialization indices in CPU cache AoS vs SoA article #390

@marvinthang

Description

@marvinthang

Hi, I think there is a small bug in the AoS initialization code in the AoS vs SoA article.

Current code:

for (int i = 0; i < M; i++)
    q[k][0] = p[i];
    
    for (int j = 1; j < D; j++)
        q[i][0] ^= (q[j][i] = rand()); 
        
    k = q[k][0]; 
}

I believe the intended logic is to initialize row q[k], so the inner loop should write to q[k][j], not q[j][i].

Also, after xoring random fields into q[k][0], q[k][0] no longer directly stores the next pointer. So k = q[k][0] is not correct here. The next pointer should still be p[i].

Suggested fix:

for (int i = 0; i < M; i++) {
    q[k][0] = p[i];

    for (int j = 1; j < D; j++) {
        q[k][0] ^= (q[k][j] = rand());
    }

    k = p[i];
}

Thanks for the great article!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions