Why are elementwise additions much faster in separate loops than in a combined loop?

后端 未结 10 565
旧巷少年郎
旧巷少年郎 2020-11-22 09:49

Suppose a1, b1, c1, and d1 point to heap memory and my numerical code has the following core loop.

const i         


        
10条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 09:57

    The first loop alternates writing in each variable. The second and third ones only make small jumps of element size.

    Try writing two parallel lines of 20 crosses with a pen and paper separated by 20 cm. Try once finishing one and then the other line and try another time by writting a cross in each line alternately.

提交回复
热议问题