CoMD
A Mini-app for Co-Design of Classical Molecular Dynamics.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
haloExchange.h
Go to the documentation of this file.
1 /// \file
2 /// Communicate halo data such as "ghost" atoms with neighboring tasks.
3 
4 #ifndef __HALO_EXCHANGE_
5 #define __HALO_EXCHANGE_
6 
7 #include "mytype.h"
8 struct AtomsSt;
9 struct LinkCellSt;
10 struct DomainSt;
11 
12 /// A polymorphic structure to store information about a halo exchange.
13 /// This structure can be thought of as an abstract base class that
14 /// specifies the interface and implements the communication patterns of
15 /// a halo exchange. Concrete sub-classes supply actual implementations
16 /// of the loadBuffer, unloadBuffer, and destroy functions, that are
17 /// specific to the actual data being exchanged. If the subclass needs
18 /// additional data members, these can be stored in a structure that is
19 /// pointed to by parms.
20 ///
21 /// Designing the structure this way allows us to re-use the
22 /// communication code for both atom data and partial force data.
23 ///
24 /// \see eamForce
25 /// \see redistributeAtoms
26 typedef struct HaloExchangeSt
27 {
28  /// The MPI ranks of the six face neighbors of the local domain.
29  /// Ranks are stored in the order specified in HaloFaceOrder.
30  int nbrRank[6];
31  /// The maximum send/recv buffer size (in bytes) that will be needed
32  /// for this halo exchange.
34  /// Pointer to a sub-class specific function to load the send buffer.
35  /// \param [in] parms The parms member of the structure. This is a
36  /// pointer to a sub-class specific structure that can
37  /// be used by the load and unload functions to store
38  /// sub-class specific data.
39  /// \param [in] data A pointer to a structure that the contains the data
40  /// that is needed by the loadBuffer function. The
41  /// loadBuffer function will cast the pointer to a
42  /// concrete type that is appropriate for the data
43  /// being exchanged.
44  /// \param [in] face Specifies the face across which data is being sent.
45  /// \param [in] buf The send buffer to be loaded
46  /// \return The number of bytes loaded into the send buffer.
47  int (*loadBuffer)(void* parms, void* data, int face, char* buf);
48  /// Pointer to a sub-class specific function to unload the recv buffer.
49  /// \param [in] parms The parms member of the structure. This is a
50  /// pointer to a sub-class specific structure that can
51  /// be used by the load and unload functions to store
52  /// sub-class specific data.
53  /// \param [out] data A pointer to a structure that the contains the data
54  /// that is needed by the unloadBuffer function. The
55  /// unloadBuffer function will cast the pointer to a
56  /// concrete type that is appropriate for the data
57  /// being exchanged.
58  /// \param [in] face Specifies the face across which data is being sent.
59  /// \param [in] bufSize The number of bytes in the recv buffer.
60  /// \param [in] buf The recv buffer to be unloaded.
61  void (*unloadBuffer)(void* parms, void* data, int face, int bufSize, char* buf);
62  /// Pointer to a function to deallocate any memory used by the
63  /// sub-class parms. Essentially this is a virtual destructor.
64  void (*destroy)(void* parms);
65  /// A pointer to a sub-class specific structure that contains
66  /// additional data members needed by the sub-class.
67  void* parms;
68 }
70 
71 /// Create a HaloExchange for atom data.
72 HaloExchange* initAtomHaloExchange(struct DomainSt* domain, struct LinkCellSt* boxes);
73 
74 /// Create a HaloExchange for force data.
75 HaloExchange* initForceHaloExchange(struct DomainSt* domain, struct LinkCellSt* boxes);
76 
77 /// HaloExchange destructor.
79 
80 /// Execute a halo exchange.
81 void haloExchange(HaloExchange* haloExchange, void* data);
82 
83 /// Sort the atoms by gid in the specified link cell.
84 void sortAtomsInCell(struct AtomsSt* atoms, struct LinkCellSt* boxes, int iBox);
85 
86 #endif