Dynamic scheduling of threads
This commit is contained in:
24
src/sims.cpp
24
src/sims.cpp
@@ -53,9 +53,11 @@ void run_simulation(std::vector<Experiment *> experiments,
|
|||||||
auto &local_dynamics = *thread_dynamics[tid];
|
auto &local_dynamics = *thread_dynamics[tid];
|
||||||
auto &local_experiments = thread_experiments[tid];
|
auto &local_experiments = thread_experiments[tid];
|
||||||
|
|
||||||
#pragma omp for schedule(static)
|
Trajectory traj;
|
||||||
|
|
||||||
|
#pragma omp for schedule(dynamic, 16)
|
||||||
for (int mol_i = 0; mol_i < num_walker; mol_i++) {
|
for (int mol_i = 0; mol_i < num_walker; mol_i++) {
|
||||||
auto traj = make_trajectory(local_dynamics, tmax, local_rng);
|
make_trajectory(traj, local_dynamics, tmax, local_rng);
|
||||||
const double init_omega = local_dynamics.getInitOmega();
|
const double init_omega = local_dynamics.getInitOmega();
|
||||||
|
|
||||||
for (auto &exp : local_experiments) {
|
for (auto &exp : local_experiments) {
|
||||||
@@ -86,8 +88,21 @@ void run_simulation(std::vector<Experiment *> experiments,
|
|||||||
printEnd(start);
|
printEnd(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
Trajectory make_trajectory(Dynamics &dynamics, const double t_max,
|
void make_trajectory(Trajectory &traj, Dynamics &dynamics, const double t_max,
|
||||||
std::mt19937_64 &rng) {
|
std::mt19937_64 &rng) {
|
||||||
|
traj.time.clear();
|
||||||
|
traj.phase.clear();
|
||||||
|
traj.omega.clear();
|
||||||
|
|
||||||
|
// Reserve is only useful on first call per thread; after that
|
||||||
|
// clear() preserves capacity from the previous walker
|
||||||
|
if (traj.time.capacity() == 0) {
|
||||||
|
const size_t estimate = 1024;
|
||||||
|
traj.time.reserve(estimate);
|
||||||
|
traj.phase.reserve(estimate);
|
||||||
|
traj.omega.reserve(estimate);
|
||||||
|
}
|
||||||
|
|
||||||
double t_passed = 0;
|
double t_passed = 0;
|
||||||
double phase = 0;
|
double phase = 0;
|
||||||
|
|
||||||
@@ -95,7 +110,6 @@ Trajectory make_trajectory(Dynamics &dynamics, const double t_max,
|
|||||||
|
|
||||||
double omega = dynamics.getInitOmega();
|
double omega = dynamics.getInitOmega();
|
||||||
|
|
||||||
Trajectory traj;
|
|
||||||
traj.time.emplace_back(t_passed);
|
traj.time.emplace_back(t_passed);
|
||||||
traj.phase.emplace_back(phase);
|
traj.phase.emplace_back(phase);
|
||||||
traj.omega.emplace_back(omega);
|
traj.omega.emplace_back(omega);
|
||||||
@@ -110,8 +124,6 @@ Trajectory make_trajectory(Dynamics &dynamics, const double t_max,
|
|||||||
traj.phase.emplace_back(phase);
|
traj.phase.emplace_back(phase);
|
||||||
traj.omega.emplace_back(omega);
|
traj.omega.emplace_back(omega);
|
||||||
}
|
}
|
||||||
|
|
||||||
return traj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::system_clock::time_point
|
std::chrono::system_clock::time_point
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ void run_simulation(std::vector<Experiment *> experiments,
|
|||||||
const std::unordered_map<std::string, double> &optional,
|
const std::unordered_map<std::string, double> &optional,
|
||||||
Dynamics &dynamics, std::mt19937_64 &rng);
|
Dynamics &dynamics, std::mt19937_64 &rng);
|
||||||
|
|
||||||
Trajectory make_trajectory(Dynamics &dynamics, double t_max,
|
void make_trajectory(Trajectory &traj, Dynamics &dynamics, double t_max,
|
||||||
std::mt19937_64 &rng);
|
std::mt19937_64 &rng);
|
||||||
|
|
||||||
std::chrono::system_clock::time_point
|
std::chrono::system_clock::time_point
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -5,6 +6,12 @@
|
|||||||
int nearest_index(const std::vector<double> &x_ref, const double x,
|
int nearest_index(const std::vector<double> &x_ref, const double x,
|
||||||
int start = 0) {
|
int start = 0) {
|
||||||
const int last = static_cast<int>(x_ref.size()) - 2;
|
const int last = static_cast<int>(x_ref.size()) - 2;
|
||||||
|
if (start == 0 && last > 32) {
|
||||||
|
// Binary search for cold starts on large trajectories
|
||||||
|
auto it = std::upper_bound(x_ref.begin(), x_ref.end(), x);
|
||||||
|
int idx = static_cast<int>(it - x_ref.begin()) - 1;
|
||||||
|
return std::clamp(idx, 0, last);
|
||||||
|
}
|
||||||
while (start < last && x > x_ref[start + 1]) {
|
while (start < last && x > x_ref[start + 1]) {
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user