Skip to content

Commit

Permalink
Claculate bins in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
rprospero committed Apr 23, 2024
1 parent e4081ff commit a9e5b29
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/modules/siteRDF/process.cpp
Expand Up @@ -12,6 +12,8 @@
#include "math/sampledDouble.h"
#include "module/context.h"
#include "modules/siteRDF/siteRDF.h"
#include "templates/algorithms.h"
#include "templates/combinable.h"

// Run main processing
Module::ExecutionResult SiteRDFModule::process(ModuleContext &moduleContext)
Expand All @@ -38,15 +40,27 @@ Module::ExecutionResult SiteRDFModule::process(ModuleContext &moduleContext)
histAB.zeroBins();

ProductIterator pairs(a.sites().size(), b.sites().size());

dissolve::for_each(ParallelPolicies::seq, pairs.begin(), pairs.end(), [this, &histAB, &a, &b](auto pair) {
auto [aIndex, bIndex] = pair;
const auto &[siteA, indexA] = a.sites()[aIndex];
const auto &[siteB, indexB] = b.sites()[bIndex];
if (excludeSameMolecule_ && (siteB->molecule() == siteA->molecule()))
return;
histAB.bin(targetConfiguration_->box()->minimumDistance(siteA->origin(), siteB->origin()));
});
auto combinableHistograms = dissolve::CombinableValue<Histogram1D>(
[&histAB]()
{
return histAB;
});

std::vector<std::optional<double>> bins;
bins.resize(pairs.end() - pairs.begin());
dissolve::transform(ParallelPolicies::par, pairs.begin(), pairs.end(), bins.begin(), [this, &histAB, &a, &b](const auto& pair) -> std::optional<double> {
const auto &[siteA, indexA] = a.sites()[std::get<0>(pair)];
const auto &[siteB, indexB] = b.sites()[std::get<1>(pair)];
if (excludeSameMolecule_ && (siteB->molecule() == siteA->molecule()))
return {};
return targetConfiguration_->box()->minimumDistance(siteA->origin(), siteB->origin());
});

for (auto bin : bins)
{
if (bin)
histAB.bin(*bin);
}

// Accumulate histogram
histAB.accumulate();
Expand Down

0 comments on commit a9e5b29

Please sign in to comment.