NetDEM v1.0
Loading...
Searching...
No Matches
mpi_manager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "mpi_data_def.hpp"
4#include "utils_macros.hpp"
5#include <mpi.h>
6
7namespace netdem {
8
9class Simulation;
10
40private:
42 MPIDataDefine mpi_data_def;
43
45 int self_rank, total_rank;
46
48 VecXT<VecXT<Particle *>> particle_proxy_out_list;
49
51 VecXT<VecXT<ContactPP *>> contact_pp_proxy_out_list;
52 VecXT<VecXT<BondEntry *>> bond_entry_pp_proxy_out_list;
53 VecXT<VecXT<CollisionEntry *>> collision_entry_pp_proxy_out_list;
54
56 VecXT<VecXT<ContactPW *>> contact_pw_proxy_out_list;
57 VecXT<VecXT<BondEntry *>> bond_entry_pw_proxy_out_list;
58 VecXT<VecXT<CollisionEntry *>> collision_entry_pw_proxy_out_list;
59
62 VecXT<VecXT<ContactPP *>> contact_pp_back_out_list;
63 VecXT<VecXT<BondEntry *>> bond_entry_pp_back_out_list;
64 VecXT<VecXT<CollisionEntry *>> collision_entry_pp_back_out_list;
65
67 VecXT<VecXT<ContactPW *>> contact_pw_back_out_list;
68 VecXT<VecXT<BondEntry *>> bond_entry_pw_back_out_list;
69 VecXT<VecXT<CollisionEntry *>> collision_entry_pw_back_out_list;
70
72 VecXT<VecXT<Particle *>> particle_transfer_out_list;
73
75 VecXT<VecXT<ContactPP *>> contact_pp_transfer_out_list;
76 VecXT<VecXT<BondEntry *>> bond_entry_pp_transfer_out_list;
77 VecXT<VecXT<CollisionEntry *>> collision_entry_pp_transfer_out_list;
78
80 VecXT<VecXT<ContactPW *>> contact_pw_transfer_out_list;
81 VecXT<VecXT<BondEntry *>> bond_entry_pw_transfer_out_list;
82 VecXT<VecXT<CollisionEntry *>> collision_entry_pw_transfer_out_list;
83
85 VecXT<VecXT<Particle *>> particle_proxy_in_list;
86 VecXT<VecXT<ContactPP *>> contact_pp_proxy_in_list;
87 VecXT<VecXT<ContactPW *>> contact_pw_proxy_in_list;
88
90 VecXT<VecXT<ContactPP *>> contact_pp_back_in_list;
91 VecXT<VecXT<ContactPW *>> contact_pw_back_in_list;
92
94 VecXT<VecXT<Particle *>> particle_transfer_in_list;
95 VecXT<VecXT<ContactPP *>> contact_pp_transfer_in_list;
96 VecXT<VecXT<ContactPW *>> contact_pw_transfer_in_list;
97
99 VecXT<VecXT<Particle *>> particle_sync_in_list;
100 VecXT<VecXT<ContactPP *>> contact_pp_sync_in_list;
101 VecXT<VecXT<ContactPW *>> contact_pw_sync_in_list;
102
103public:
107 MPIManager();
108
114 void Init(Simulation *sim);
115
119 void CommitMPIDataType();
120
124 int GetSelfRank() const;
125
129 int GetTotalRank() const;
130
135
140
145
149 void ExchangeDataProxy();
150
155 void ExchangeDataBack();
156
161
166
171
176
181
186
187private:
191 void GatherDataProxy();
192
197 void GatherDataBack();
198
202 void GatherDataTransfer();
203
207 void SendDataProxy();
208
213 void SendDataBack();
214
218 void SendDataTransfer();
219
223 void SendParticleSync();
224
228 void SendContactSync();
229
233 void RecvDataProxy();
234
239 void RecvDataBack();
240
244 void RecvDataTransfer();
245
249 void RecvParticleSync();
250
254 void RecvContactSync();
255
262 void MergeShape(int source_rank);
263
269 void MergeShapeFast(int source_rank);
270
276 void MergeParticleProxy(int source_rank);
277
283 void MergeContactPPProxy(int source_rank);
284
290 void MergeContactPWProxy(int source_rank);
291
297 void MergeContactPPBack(int source_rank);
298
304 void MergeContactPWBack(int source_rank);
305
311 void MergeParticleTransfer(int source_rank);
312
318 void MergeContactPPTransfer(int source_rank);
319
325 void MergeContactPWTransfer(int source_rank);
326
332 void MergeParticleSync(int source_rank);
333
340 void MergeContactPPSync(int source_rank);
341
347 void MergeContactPWSync(int source_rank);
348
349public:
355 static int GetSelfRankStatic();
356
362 static int GetTotalRankStatic();
363
369 static void SyncDataAmongProcessors(VecXT<int> *const data);
370
376 static void SyncDataAmongProcessors(VecXT<double> *const data);
377
381 ~MPIManager();
382
383private:
384 // for basic properties
385 void GatherDataShape();
386
387 void SendShape(int i_rank);
388 void SendParticle(VecXT<Particle *> const &p_list, int i_rank);
389
390 void SendBondEntryPP(VecXT<BondEntry *> const &bond_list, int i_rank);
391 void SendCollisionEntryPP(VecXT<CollisionEntry *> const &collision_list,
392 int i_rank);
393 void SendContactPP(VecXT<ContactPP *> const &cnt_list, int i_rank);
394
395 void SendBondEntryPW(VecXT<BondEntry *> const &bond_list, int i_rank);
396 void SendCollisionEntryPW(VecXT<CollisionEntry *> const &collision_list,
397 int i_rank);
398 void SendContactPW(VecXT<ContactPW *> const &cnt_list, int i_rank);
399
400 void RecvShape(MPIManager *obj, void (MPIManager::*MergeFunc)(int));
401 void RecvParticle(MPIManager *obj, void (MPIManager::*MergeFunc)(int));
402
403 void RecvBondEntryPP();
404 void RecvCollisionEntryPP();
405 void RecvContactPP(MPIManager *obj, void (MPIManager::*MergeFunc)(int));
406
407 void RecvBondEntryPW();
408 void RecvCollisionEntryPW();
409 void RecvContactPW(MPIManager *obj, void (MPIManager::*MergeFunc)(int));
410
411 // for dynamics properties
412 void SendParticleProp(VecXT<Particle *> const &p_list, int i_rank);
413 void SendContactPPProp(VecXT<ContactPP *> const &cnt_list, int i_rank);
414 void SendContactPWProp(VecXT<ContactPW *> const &cnt_list, int i_rank);
415
416 void RecvParticleProp(VecXT<VecXT<Particle *>> *const p_list);
417 void RecvContactPPProp(VecXT<VecXT<ContactPP *>> *const cnt_list);
418 void RecvContactPWProp(VecXT<VecXT<ContactPW *>> *const cnt_list);
419
420 void MergeParticleProp(VecXT<Particle *> *const p_list, int source_rank);
421 void MergeContactPPProp(VecXT<ContactPP *> *const cnt_list, int source_rank);
422 void MergeContactPWProp(VecXT<ContactPW *> *const cnt_list, int source_rank);
423
424private:
425 bool mpi_initialized_here{false};
426
427 Simulation *sim{nullptr};
428
429 VecXT<ParticleData *> particle_data_list_send;
430 VecXT<std::string> particle_prop_keys_list_send;
431 VecXT<VecXT<double>> particle_prop_vals_list_send;
432 VecXT<ContactPPData *> contact_pp_data_list_send;
433 VecXT<std::string> contact_pp_prop_keys_list_send;
434 VecXT<VecXT<double>> contact_pp_prop_vals_list_send;
435 VecXT<BondEntryData *> bond_entry_pp_data_list_send;
436 VecXT<CollisionEntryData *> collision_entry_pp_data_list_send;
437 VecXT<ContactPWData *> contact_pw_data_list_send;
438 VecXT<std::string> contact_pw_prop_keys_list_send;
439 VecXT<VecXT<double>> contact_pw_prop_vals_list_send;
440 VecXT<BondEntryData *> bond_entry_pw_data_list_send;
441 VecXT<CollisionEntryData *> collision_entry_pw_data_list_send;
442
443 VecXT<int> particle_num_list_send;
444 VecXT<int> contact_pp_num_list_send;
445 VecXT<int> bond_entry_pp_num_list_send;
446 VecXT<int> collision_entry_pp_num_list_send;
447 VecXT<int> contact_pw_num_list_send;
448 VecXT<int> bond_entry_pw_num_list_send;
449 VecXT<int> collision_entry_pw_num_list_send;
450
451 VecXT<MPI_Request> particle_req_list_send;
452 VecXT<MPI_Request> particle_prop_keys_req_list_send;
453 VecXT<MPI_Request> particle_prop_vals_req_list_send;
454 VecXT<MPI_Request> contact_pp_req_list_send;
455 VecXT<MPI_Request> contact_pp_prop_keys_req_list_send;
456 VecXT<MPI_Request> contact_pp_prop_vals_req_list_send;
457 VecXT<MPI_Request> bond_entry_pp_req_list_send;
458 VecXT<MPI_Request> collision_entry_pp_req_list_send;
459 VecXT<MPI_Request> contact_pw_req_list_send;
460 VecXT<MPI_Request> contact_pw_prop_keys_req_list_send;
461 VecXT<MPI_Request> contact_pw_prop_vals_req_list_send;
462 VecXT<MPI_Request> bond_entry_pw_req_list_send;
463 VecXT<MPI_Request> collision_entry_pw_req_list_send;
464
465 std::string *shape_data_send{nullptr};
466 VecXT<MPI_Request> shape_req_list_send;
467 VecXT<std::string> shape_data_list_recv;
468 VecXT<MPI_Request> shape_req_list_recv;
469 VecXT<bool> shape_probed_list;
470
471 VecXT<ParticleData *> particle_data_list_recv;
472 VecXT<std::string> particle_prop_keys_list_recv;
473 VecXT<VecXT<double>> particle_prop_vals_list_recv;
474 VecXT<ContactPPData *> contact_pp_data_list_recv;
475 VecXT<std::string> contact_pp_prop_keys_list_recv;
476 VecXT<VecXT<double>> contact_pp_prop_vals_list_recv;
477 VecXT<BondEntryData *> bond_entry_pp_data_list_recv;
478 VecXT<CollisionEntryData *> collision_entry_pp_data_list_recv;
479 VecXT<ContactPWData *> contact_pw_data_list_recv;
480 VecXT<std::string> contact_pw_prop_keys_list_recv;
481 VecXT<VecXT<double>> contact_pw_prop_vals_list_recv;
482 VecXT<BondEntryData *> bond_entry_pw_data_list_recv;
483 VecXT<CollisionEntryData *> collision_entry_pw_data_list_recv;
484
485 VecXT<int> particle_num_list_recv;
486 VecXT<int> contact_pp_num_list_recv;
487 VecXT<int> bond_entry_pp_num_list_recv;
488 VecXT<int> collision_entry_pp_num_list_recv;
489 VecXT<int> contact_pw_num_list_recv;
490 VecXT<int> bond_entry_pw_num_list_recv;
491 VecXT<int> collision_entry_pw_num_list_recv;
492
493 VecXT<MPI_Request> particle_req_list_recv;
494 VecXT<MPI_Request> particle_prop_keys_req_list_recv;
495 VecXT<MPI_Request> particle_prop_vals_req_list_recv;
496 VecXT<MPI_Request> contact_pp_req_list_recv;
497 VecXT<MPI_Request> contact_pp_prop_keys_req_list_recv;
498 VecXT<MPI_Request> contact_pp_prop_vals_req_list_recv;
499 VecXT<MPI_Request> bond_entry_pp_req_list_recv;
500 VecXT<MPI_Request> collision_entry_pp_req_list_recv;
501 VecXT<MPI_Request> contact_pw_req_list_recv;
502 VecXT<MPI_Request> contact_pw_prop_keys_req_list_recv;
503 VecXT<MPI_Request> contact_pw_prop_vals_req_list_recv;
504 VecXT<MPI_Request> bond_entry_pw_req_list_recv;
505 VecXT<MPI_Request> collision_entry_pw_req_list_recv;
506
507 VecXT<bool> particle_probed_list;
508 VecXT<bool> particle_prop_keys_probed_list;
509 VecXT<bool> particle_prop_vals_probed_list;
510 VecXT<bool> contact_pp_probed_list;
511 VecXT<bool> contact_pp_prop_keys_probed_list;
512 VecXT<bool> contact_pp_prop_vals_probed_list;
513 VecXT<bool> bond_entry_pp_probed_list;
514 VecXT<bool> collision_entry_pp_probed_list;
515 VecXT<bool> contact_pw_probed_list;
516 VecXT<bool> contact_pw_prop_keys_probed_list;
517 VecXT<bool> contact_pw_prop_vals_probed_list;
518 VecXT<bool> bond_entry_pw_probed_list;
519 VecXT<bool> collision_entry_pw_probed_list;
520
521 List<int> GetOtherRanks();
522 void RemoveParticle(int id, VecXT<Particle *> *p_list);
523
524 void ClearBuffer();
525
526 void ClearBufferShape();
527 void ClearBufferParticle();
528 void ClearBufferContact();
529};
530
531} // namespace netdem
A class for defining MPI datatypes for various data structures.
Definition mpi_data_def.hpp:21
Manages the data exchange in a DEM simulation.
Definition mpi_manager.hpp:39
static void SyncDataAmongProcessors(VecXT< int > *const data)
Definition mpi_manager.cpp:1370
void ExchangeDataProxy()
Exchange data between processors using particle proxies.
Definition mpi_manager.cpp:238
void ExchangeDataBack()
Send exchanged data to original processors using ghost particles as proxies.
Definition mpi_manager.cpp:248
MPIManager()
Default constructor for MPIManager class.
Definition mpi_manager.cpp:15
void SyncContactToGhostSubDomains()
Synchronize contact information with ghost sub-domains.
Definition mpi_manager.cpp:351
int GetTotalRank() const
Get the total ranks of the simulation.
Definition mpi_manager.cpp:214
void Init(Simulation *sim)
Initialize the MPIManager with a Simulation object.
Definition mpi_manager.cpp:17
void SyncWallToGhostSubDomains()
Synchronize wall information with ghost sub-domains.
Definition mpi_manager.cpp:437
void ClearContactRefTable()
Clear the contact look-up table.
Definition mpi_manager.cpp:288
void SyncShapeToAllProcessors()
Synchronize shape information between all processors.
Definition mpi_manager.cpp:300
static int GetSelfRankStatic()
Definition mpi_manager.cpp:1358
void CommitMPIDataType()
Commit the MPI data type for particle exchange.
Definition mpi_manager.cpp:210
void SyncParticleToGhostSubDomains()
Synchronize particle information with ghost sub-domains.
Definition mpi_manager.cpp:320
int GetSelfRank() const
Get the rank id of the domain.
Definition mpi_manager.cpp:212
void ExchangeDataTransfer()
Exchange data between processors using ghost particles as proxies.
Definition mpi_manager.cpp:258
~MPIManager()
Definition mpi_manager.cpp:1431
void BuildContactRefTable()
Build a look-up table for contacts between particles.
Definition mpi_manager.cpp:216
static int GetTotalRankStatic()
Definition mpi_manager.cpp:1364
void RecycleParticleGhost()
Recycle ghost particles.
Definition mpi_manager.cpp:268
void RecycleParticleProxy()
Recycle a particle proxy.
Definition mpi_manager.cpp:228
Class for managing a DEM simulation.
Definition simulation.hpp:21
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31
std::list< T > List
Definition utils_macros.hpp:34