Added measurements

This commit is contained in:
Nguyen Quy Anh
2026-04-24 16:31:42 +02:00
parent aa1daf9149
commit 3d217e7840
7 changed files with 113 additions and 55 deletions
+30
View File
@@ -2,7 +2,9 @@
#include "forces.hpp"
#include "math.h"
#include "pedestrian.hpp"
#include "tsc_x86.h"
#include "vector2d.hpp"
#include <iostream>
#define BOARD_WIDTH 10.0
#define BOARD_LENGTH 50.0
@@ -50,6 +52,11 @@ int main(int argc, const char *argv[]) {
int n_p = atoi(argv[1]);
int n_iter = atoi(argv[2]);
Pedestrian *pedestrians = init_pedestrians(n_p);
// # Start here or right after function signature
uint64_t start = start_tsc();
// # (8 + 55N - 55 + 144 + 4 + 8 + 4 + 10)*n_p*n_iter
for (int t = 0; t < n_iter; t++) {
for (int i = 0; i < n_p; i++) {
@@ -58,21 +65,44 @@ int main(int argc, const char *argv[]) {
p.f_i.reset();
// # 8 flops
compute_acceleration_term(&p);
// # 55N - 55 flops
compute_repulsive_effects_from_pedestrians(pedestrians, &p, n_p);
// # 144 flops
compute_repulsive_effects_from_borders(board, &p);
// # 4 flops = 2 ADDs, 2 MULTs
Vector2d w_alpha = p.curr_vel + p.f_i * dt;
// # 8 flops = 2 MULTs, 2 DIVs, 1 SQRT, 2 MULTs, 1 ADD
p.curr_vel = w_alpha * g(p.v_max, w_alpha.norm());
// # 4 flops = 2 ADDs, 2 MULTs
p.curr_pos = p.curr_pos + p.curr_vel * dt;
// # 10 flops = 5 ADDs, 2 DIVs, 1 SQRT, 2 MULTs
p.e = (p.destination - p.curr_pos) / (p.destination - p.curr_pos).norm();
}
}
int W = (8 + 55 * n_p - 55 + 144 + 4 + 8 + 4 + 10) * n_p * n_iter;
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;
std::cout << "P(n): ";
std::cout << P;
std::cout << " flops/cycle\n";
delete []pedestrians;
return 0;
}