Skip to content

Commit 79db105

Browse files
Chaitanya Kumarloonatick-src
authored andcommitted
refactor: loop interchange for contiguous access
1 parent 81f2dcb commit 79db105

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Benchmarks/ShallowWaterPDE/Solution.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ struct Solution: Differentiable {
4343
func evolve() -> Self {
4444
var newWaterLevel = currentWaterLevel
4545

46-
for x in 1 ..< resolution - 1 {
47-
for y in 1 ..< resolution - 1 {
46+
for y in 1 ..< resolution - 1 {
47+
for x in 1 ..< resolution - 1 {
4848
// FIXME: Should be u2[x][y] = ...
4949
let newValue: Float = 2 * currentWaterLevel[x, y] + (c * c * dt * dt + c * a * dt) * currentWaterLevel.laplace(x, y) * Float(resolution * resolution) - previousWaterLevel[x, y] - c * a * dt * previousWaterLevel.laplace(x, y) * Float(resolution * resolution)
5050
newWaterLevel[x, y] = newValue

Benchmarks/ShallowWaterPDE/Storage+Float.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ extension Array2DStorage where Element == Float {
1616
func meanSquaredError(to target: Array2DStorage<Float>) -> Float {
1717
var mse: Float = 0.0
1818

19-
for x in 0 ..< withoutDerivative(at: width) {
20-
for y in 0 ..< withoutDerivative(at: height) {
19+
for y in 0 ..< withoutDerivative(at: height) {
20+
for x in 0 ..< withoutDerivative(at: width) {
2121
let error = target[x, y] - self[x, y]
2222
mse += error * error
2323
}

0 commit comments

Comments
 (0)