Skip to content

Commit

Permalink
🐛 If the number of threads is initially set to zero, the simulation i…
Browse files Browse the repository at this point in the history
…s run with one thread.
  • Loading branch information
Drewniok committed Feb 23, 2023
1 parent 6f53788 commit cca55af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions include/fiction/algorithms/simulation/sidb/quicksim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,22 @@ void quicksim(const Lyt& lyt, const quicksim_params& ps = quicksim_params{}, qui
st.valid_lyts.push_back(charge_distribution_surface<Lyt>{charge_lyt});
}

// If the number of threads is initially set to zero, the simulation is run with one thread.
uint64_t num_threads = std::max(ps.number_threads, uint64_t{1});

This comment has been minimized.

Copy link
@marcelwa

marcelwa Feb 23, 2023

Collaborator

Can be const


// split the iterations among threads
const auto iter_per_thread =
std::max(ps.interation_steps / ps.number_threads,
std::max(ps.interation_steps / num_threads,
uint64_t{1}); // If the number of set threads is greater than the number of iterations, the
// number of threads defines how many times QuickSim is repeated

const auto bound = static_cast<uint64_t>(std::round(0.6 * static_cast<double>(charge_lyt.num_cells())));

This comment has been minimized.

Copy link
@marcelwa

marcelwa Feb 23, 2023

Collaborator

Is this a lower or an upper bound? Why multiply with 0.6? Can you add a descriptive comment, please?


std::vector<std::thread> threads{};
threads.reserve(ps.number_threads);
threads.reserve(num_threads);
std::mutex mutex{}; // used to control access to shared resources

for (uint64_t z = 0ul; z < ps.number_threads; z++)
for (uint64_t z = 0ul; z < num_threads; z++)
{
threads.emplace_back(
[&]
Expand Down
3 changes: 2 additions & 1 deletion test/algorithms/simulation/sidb/quicksim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ TEMPLATE_TEST_CASE(
const sidb_simulation_parameters params{2, -0.30};
const quicksim_params quicksim_params{params, 80, 0.7, 0};
quicksim<TestType>(lyt, quicksim_params, &quicksimstats);
CHECK(quicksimstats.valid_lyts.empty());
CHECK(!quicksimstats.valid_lyts.empty());
CHECK(quicksimstats.time_total.count() > 0);
}

SECTION("one thread")
Expand Down

0 comments on commit cca55af

Please sign in to comment.