Skip to content

Commit c24e1e5

Browse files
Update step.h
1 parent 3dafb94 commit c24e1e5

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/gravity/step.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919
#ifdef NEXT_MPI
2020
#include <mpi.h>
2121
#endif
22+
#include <chrono>
23+
#include <fstream>
2224

2325
inline void Step(ParticleSystem &ps, real dt) {
2426
if (ps.size() == 0) return;
2527

28+
#ifdef NEXT_BENCHMARK
29+
auto t_start = std::chrono::high_resolution_clock::now();
30+
#endif
31+
2632
const real theta = real(0.5);
2733
const real half = dt * real(0.5);
2834
const int N = static_cast<int>(ps.size());
@@ -181,4 +187,18 @@ inline void Step(ParticleSystem &ps, real dt) {
181187
MPI_Waitall(3, reqs4, MPI_STATUSES_IGNORE);
182188
#endif
183189
}
190+
191+
#ifdef NEXT_BENCHMARK
192+
auto t_end = std::chrono::high_resolution_clock::now();
193+
double elapsed_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();
194+
195+
int rank = 0;
196+
#ifdef NEXT_MPI
197+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
198+
#endif
199+
if (rank == 0) {
200+
std::ofstream log("log.txt", std::ios::app);
201+
log << "Step time: " << elapsed_ms << " ms" << std::endl;
202+
}
203+
#endif
184204
}

0 commit comments

Comments
 (0)