From 49e96e85a1a71e110f3cf8a7e7b18a05d82597af Mon Sep 17 00:00:00 2001 From: lbaumberger Date: Sat, 25 Apr 2026 20:57:50 +0200 Subject: [PATCH] created two passes Pass1: compute all forces Pass2: integrate the forces and do the updates If we dont separate it, we will have some inter pedestrian forces calculated on a mix of new and updated values --- main.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index ffbc725..6e00475 100644 --- a/main.cpp +++ b/main.cpp @@ -58,7 +58,7 @@ int main(int argc, const char *argv[]) { // # (8 + 55N - 55 + 144 + 4 + 8 + 4 + 10)*n_p*n_iter for (int t = 0; t < n_iter; t++) { - + // Pass1: conmpute all forces from the current state for (int i = 0; i < n_p; i++) { Pedestrian &p = pedestrians[i]; @@ -73,7 +73,10 @@ int main(int argc, const char *argv[]) { // # 144 flops compute_repulsive_effects_from_borders(board, &p); - + } + // Pass2: integrate the forces and update the current state + for (int i = 0; i < n_p; i++) { + Pedestrian &p = pedestrians[i]; // # 4 flops = 2 ADDs, 2 MULTs Vector2d w_alpha = p.curr_vel + p.f_i * dt; @@ -91,18 +94,18 @@ int main(int argc, const char *argv[]) { std::cout << "W(n): "; std::cout << W; std::cout << " flops\n"; - + double T = stop_tsc(start); std::cout << "T(n): "; std::cout << T; std::cout << " cycles\n"; - double P = W/T; + double P = W / T; std::cout << "P(n): "; std::cout << P; std::cout << " flops/cycle\n"; - delete []pedestrians; + delete[] pedestrians; return 0; }