From c5d97c5df90f2bd705073aa9d2687fe828a735b5 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 10 Jan 2020 16:24:41 -0500 Subject: [PATCH] Finish part1 --- Makefile | 2 +- src/main.rs | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 60a6e56..9a92f64 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ target: mkdir -p target target/nbody.c: target - $(cc) -O3 -fomit-frame-pointer -march=native -funroll-loops \ + $(CC) -O3 -fomit-frame-pointer -march=native -funroll-loops \ nbody.c -o target/nbody.c -lm target/nbody-1: diff --git a/src/main.rs b/src/main.rs index 03f9e73..1303ee1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -189,26 +189,26 @@ unsafe fn advance(bodies: *mut body) { _mm_div_pd(_mm_set1_pd(0.01), distance_Squared), distance_Reciprocal, )); + } - { - let mut k = 0; - for i in 0..BODIES_COUNT - 1 { - for j in i + 1..BODIES_COUNT { - let i_mass_magnitude = (*bodies.add(i)).mass * magnitudes.0[k]; - let j_mass_magnitude = (*bodies.add(j)).mass * magnitudes.0[k]; - for m in 0..3 { - (*bodies.add(i)).velocity[m] -= position_Deltas[m].0[k] * j_mass_magnitude; - (*bodies.add(j)).velocity[m] += position_Deltas[m].0[k] * i_mass_magnitude; - } - k += 1; + { + let mut k = 0; + for i in 0..BODIES_COUNT - 1 { + for j in i + 1..BODIES_COUNT { + let i_mass_magnitude = (*bodies.add(i)).mass * magnitudes.0[k]; + let j_mass_magnitude = (*bodies.add(j)).mass * magnitudes.0[k]; + for m in 0..3 { + (*bodies.add(i)).velocity[m] -= position_Deltas[m].0[k] * j_mass_magnitude; + (*bodies.add(j)).velocity[m] += position_Deltas[m].0[k] * i_mass_magnitude; } + k += 1; } } + } - for i in 0..BODIES_COUNT { - for m in 0..3 { - (*bodies.add(i)).position[m] += 0.01 * (*bodies.add(i)).velocity[m]; - } + for i in 0..BODIES_COUNT { + for m in 0..3 { + (*bodies.add(i)).position[m] += 0.01 * (*bodies.add(i)).velocity[m]; } } }