|
@@ -6,6 +6,7 @@ template <class Real, int DIM> class MyObject {
|
|
|
MyObject() {
|
|
|
for (int i = 0; i < DIM; i++) coord[i] = drand48() * 3;
|
|
|
rad = drand48() * 0.01;
|
|
|
+ some_data = 0;
|
|
|
}
|
|
|
|
|
|
const Real* Coord() const { return coord; }
|
|
@@ -23,6 +24,8 @@ template <class Real, int DIM> class MyObject {
|
|
|
memcpy(this, buff.data(), count);
|
|
|
}
|
|
|
|
|
|
+ long some_data;
|
|
|
+
|
|
|
private:
|
|
|
Real coord[DIM];
|
|
|
Real rad;
|
|
@@ -56,7 +59,11 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
NearInteraction<Real,DIM> near_interac(comm);
|
|
|
sctl::Profile::Enable(true);
|
|
|
- { // Repartition data
|
|
|
+ { // Repartition data across MPI processes (optional)
|
|
|
+ // so that nearby objects are on the same MPI process.
|
|
|
+ // This reduces interprocess communication during
|
|
|
+ // subsequent computations
|
|
|
+
|
|
|
// Setup for repartition
|
|
|
sctl::Profile::Tic("RepartSetup", &comm, true);
|
|
|
near_interac.SetupRepartition(src_vec, trg_vec);
|
|
@@ -73,6 +80,11 @@ int main(int argc, char **argv) {
|
|
|
sctl::Profile::Toc();
|
|
|
}
|
|
|
{ // Compute near interactions
|
|
|
+ // 1) Rearrange src_vec and trg_vec so that near pairs are on same MPI process.
|
|
|
+ // 2) Find pairs (s,t) in (src_vec x trg_vec); such that: distance(s,t) <= s.Rad() + t.Rad();
|
|
|
+ // 3) Then, compute something on (s,t) and store the result in t.
|
|
|
+ // 4) Finally, send t back to trg_vec.
|
|
|
+
|
|
|
// Setup for near interaction
|
|
|
sctl::Profile::Tic("NearSetup", &comm, true);
|
|
|
near_interac.SetupNearInterac(src_vec, trg_vec);
|
|
@@ -90,9 +102,9 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
const auto& trg_src_interac = near_interac.GetInteractionList(); // Get interaction list
|
|
|
//for (auto interac : trg_src_interac) { // compute near interactions (single thread)
|
|
|
- // SrcObj& t = trg_near[interac.first];
|
|
|
- // TrgObj& s = src_near[interac.second];
|
|
|
- // // ( compute interaction between t and s )
|
|
|
+ // TrgObj& t = trg_near[interac.first];
|
|
|
+ // const SrcObj& s = src_near[interac.second];
|
|
|
+ // t.some_data += 1; // ( compute some interaction between t and s )
|
|
|
//}
|
|
|
#pragma omp parallel
|
|
|
{ // compute near interactions (multiple threads)
|
|
@@ -107,9 +119,9 @@ int main(int argc, char **argv) {
|
|
|
while (b + 1 < N && trg_src_interac[b].first == trg_src_interac[b + 1].first) b++;
|
|
|
|
|
|
for (long i = a; i < b; i++) {
|
|
|
- SrcObj& t = trg_near[trg_src_interac[i].first];
|
|
|
- TrgObj& s = src_near[trg_src_interac[i].second];
|
|
|
- // ( compute interaction between t and s )
|
|
|
+ TrgObj& t = trg_near[trg_src_interac[i].first];
|
|
|
+ const SrcObj& s = src_near[trg_src_interac[i].second];
|
|
|
+ t.some_data += 1; // ( compute some interaction between t and s )
|
|
|
}
|
|
|
}
|
|
|
|