Finish part1

This commit is contained in:
Timothy Warren 2020-01-10 16:24:41 -05:00
parent f7198add5e
commit c5d97c5df9
2 changed files with 16 additions and 16 deletions

View File

@ -2,7 +2,7 @@ target:
mkdir -p target mkdir -p target
target/nbody.c: 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 nbody.c -o target/nbody.c -lm
target/nbody-1: target/nbody-1:

View File

@ -189,26 +189,26 @@ unsafe fn advance(bodies: *mut body) {
_mm_div_pd(_mm_set1_pd(0.01), distance_Squared), _mm_div_pd(_mm_set1_pd(0.01), distance_Squared),
distance_Reciprocal, distance_Reciprocal,
)); ));
}
{ {
let mut k = 0; let mut k = 0;
for i in 0..BODIES_COUNT - 1 { for i in 0..BODIES_COUNT - 1 {
for j in i + 1..BODIES_COUNT { for j in i + 1..BODIES_COUNT {
let i_mass_magnitude = (*bodies.add(i)).mass * magnitudes.0[k]; let i_mass_magnitude = (*bodies.add(i)).mass * magnitudes.0[k];
let j_mass_magnitude = (*bodies.add(j)).mass * magnitudes.0[k]; let j_mass_magnitude = (*bodies.add(j)).mass * magnitudes.0[k];
for m in 0..3 { for m in 0..3 {
(*bodies.add(i)).velocity[m] -= position_Deltas[m].0[k] * j_mass_magnitude; (*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; (*bodies.add(j)).velocity[m] += position_Deltas[m].0[k] * i_mass_magnitude;
}
k += 1;
} }
k += 1;
} }
} }
}
for i in 0..BODIES_COUNT { for i in 0..BODIES_COUNT {
for m in 0..3 { for m in 0..3 {
(*bodies.add(i)).position[m] += 0.01 * (*bodies.add(i)).velocity[m]; (*bodies.add(i)).position[m] += 0.01 * (*bodies.add(i)).velocity[m];
}
} }
} }
} }