2 Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 (HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
4 the University of Michigan All rights reserved.
6 HOOMD-blue may contain modifications ("Contributions") provided, and to which
7 copyright is held, by various Contributors who have granted The Regents of the
8 University of Michigan the right to modify and/or distribute such Contributions.
10 You may redistribute, use, and create derivate works of HOOMD-blue, in source
11 and binary forms, provided you abide by the following conditions:
13 * Redistributions of source code must retain the above copyright notice, this
14 list of conditions, and the following disclaimer both in the code and
15 prominently in any materials provided with the distribution.
17 * Redistributions in binary form must reproduce the above copyright notice, this
18 list of conditions, and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
21 * All publications and presentations based on HOOMD-blue, including any reports
22 or published results obtained, in whole or in part, with HOOMD-blue, will
23 acknowledge its use according to the terms posted at the time of submission on:
24 http://codeblue.umich.edu/hoomd-blue/citations.html
26 * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
27 http://codeblue.umich.edu/hoomd-blue/
29 * Apart from the above required attributions, neither the name of the copyright
30 holder nor the names of HOOMD-blue's contributors may be used to endorse or
31 promote products derived from this software without specific prior written
36 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
37 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
39 WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
41 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
43 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 // Maintainer: jglaser
52 /*! \file CommunicatorGPU.h
53 \brief Defines the CommunicatorGPU class
56 #ifndef __COMMUNICATOR_GPU_H__
57 #define __COMMUNICATOR_GPU_H__
62 #include "Communicator.h"
64 #include "CommunicatorGPU.cuh"
69 /*! \ingroup communication
72 //! Class that handles MPI communication (GPU version)
73 /*! CommunicatorGPU is the GPU implementation of the base communication class.
75 class CommunicatorGPU
: public Communicator
79 /*! \param sysdef system definition the communicator is associated with
80 * \param decomposition Information about the decomposition of the global simulation domain
82 CommunicatorGPU(boost::shared_ptr
<SystemDefinition
> sysdef
,
83 boost::shared_ptr
<DomainDecomposition
> decomposition
);
84 virtual ~CommunicatorGPU();
86 //! \name communication methods
89 /*! Perform ghosts update
91 * \param timestep The time step
93 virtual void beginUpdateGhosts(unsigned int timestep
);
95 /*! Finish ghost update
97 * \param timestep The time step
99 virtual void finishUpdateGhosts(unsigned int timestep
);
101 //! Transfer particles between neighboring domains
102 virtual void migrateParticles();
104 //! Build a ghost particle list, exchange ghost particle data with neighboring processors
105 virtual void exchangeGhosts();
109 //! Set maximum number of communication stages
110 /*! \param max_stages Maximum number of communication stages
112 void setMaxStages(unsigned int max_stages
)
114 m_max_stages
= max_stages
;
115 initializeCommunicationStages();
119 //! Set autotuner parameters
120 /*! \param enable Enable/disable autotuning
121 \param period period (approximate) in time steps when returning occurs
123 Derived classes should override this to set the parameters of their autotuners.
125 virtual void setAutotunerParams(bool enable
, unsigned int period
)
127 Communicator::setAutotunerParams(enable
, period
);
129 #ifndef ENABLE_MPI_CUDA
130 m_tuner_ghost_recv
->setPeriod(period
);
131 m_tuner_ghost_recv
->setEnabled(enable
);
133 m_tuner_ghost_send
->setPeriod(period
);
134 m_tuner_ghost_send
->setEnabled(enable
);
140 //! Helper class to perform the communication tasks related to bonded groups
141 template<class group_data
>
142 class GroupCommunicatorGPU
145 typedef struct rank_element
<typename
group_data::ranks_t
> rank_element_t
;
146 typedef typename
group_data::packed_t group_element_t
;
149 GroupCommunicatorGPU(CommunicatorGPU
& gpu_comm
, boost::shared_ptr
<group_data
> gdata
);
152 /*! \param incomplete If true, mark all groups that have non-local members and update local
153 * member rank information. Otherwise, mark only groups flagged for communication
156 * A group is marked for sending by setting its rtag to GROUP_NOT_LOCAL, and by updating
157 * the rank information with the destination ranks (or the local ranks if incomplete=true)
159 void migrateGroups(bool incomplete
);
161 //! Mark ghost particles
162 /* All particles that need to be sent as ghosts because they are members
163 * of incomplete groups are marked, and destination ranks are compute accordingly.
165 * \param plans Array of particle plans to write to
166 * \param mask Mask for allowed sending directions
168 void markGhostParticles(const GPUArray
<unsigned int>& plans
, unsigned int mask
);
171 CommunicatorGPU
& m_gpu_comm
; //!< The outer class
172 boost::shared_ptr
<const ExecutionConfiguration
> m_exec_conf
; //< The execution configuration
173 boost::shared_ptr
<group_data
> m_gdata
; //!< The group data
175 GPUVector
<unsigned int> m_rank_mask
; //!< Bitfield for every group to keep track of updated rank fields
176 GPUVector
<unsigned int> m_scan
; //!< Temporary array for exclusive scan of group membership information
178 GPUVector
<rank_element_t
> m_ranks_out
; //!< Packed ranks data
179 GPUVector
<rank_element_t
> m_ranks_sendbuf
; //!< Send buffer for ranks information
180 GPUVector
<rank_element_t
> m_ranks_recvbuf
; //!< Recv buffer for ranks information
182 GPUVector
<group_element_t
> m_groups_out
; //!< Packed group data
183 GPUVector
<unsigned int> m_rank_mask_out
; //!< Output buffer for rank update bitfields
184 GPUVector
<group_element_t
> m_groups_sendbuf
; //!< Send buffer for groups
185 GPUVector
<group_element_t
> m_groups_recvbuf
; //!< Recv buffer for groups
186 GPUVector
<group_element_t
> m_groups_in
; //!< Input buffer of unique groups
190 /* General communication */
191 unsigned int m_max_stages
; //!< Maximum number of (dependent) communication stages
192 unsigned int m_num_stages
; //!< Number of stages
193 std::vector
<unsigned int> m_comm_mask
; //!< Communication mask per stage
194 std::vector
<int> m_stages
; //!< Communication stage per unique neighbor
196 /* Particle migration */
197 GPUVector
<pdata_element
> m_gpu_sendbuf
; //!< Send buffer for particle data
198 GPUVector
<pdata_element
> m_gpu_recvbuf
; //!< Receive buffer for particle data
199 GPUVector
<unsigned int> m_comm_flags
; //!< Output buffer for communication flags
201 GPUVector
<unsigned int> m_send_keys
; //!< Destination rank for particles
203 /* Communication of bonded groups */
204 GroupCommunicatorGPU
<BondData
> m_bond_comm
; //!< Communication helper for bonds
205 friend class GroupCommunicatorGPU
<BondData
>;
207 GroupCommunicatorGPU
<AngleData
> m_angle_comm
; //!< Communication helper for angles
208 friend class GroupCommunicatorGPU
<AngleData
>;
210 GroupCommunicatorGPU
<DihedralData
> m_dihedral_comm
; //!< Communication helper for dihedrals
211 friend class GroupCommunicatorGPU
<DihedralData
>;
213 GroupCommunicatorGPU
<ImproperData
> m_improper_comm
; //!< Communication helper for impropers
214 friend class GroupCommunicatorGPU
<ImproperData
>;
216 /* Ghost communication */
217 bool m_mapped_ghost_recv
; //!< True if using host-mapped memory for ghost recv buffers
218 bool m_mapped_ghost_send
; //!< True if using host-mapped memory for ghost send buffers
219 boost::scoped_ptr
<Autotuner
> m_tuner_ghost_recv
; //!< Autotuner for mapped memory (recv ghosts)
220 boost::scoped_ptr
<Autotuner
> m_tuner_ghost_send
; //!< Autotuner for mapped memory (recv ghosts)
222 GPUVector
<unsigned int> m_tag_ghost_sendbuf
; //!< Buffer for sending particle tags
223 GPUVector
<unsigned int> m_tag_ghost_recvbuf
; //!< Buffer for recveiving particle tags
225 GPUVector
<Scalar4
> m_pos_ghost_sendbuf
; //<! Buffer for sending ghost positions
226 GPUVector
<Scalar4
> m_pos_ghost_recvbuf
; //<! Buffer for receiving ghost positions
228 GPUVector
<Scalar4
> m_vel_ghost_sendbuf
; //<! Buffer for sending ghost velocities
229 GPUVector
<Scalar4
> m_vel_ghost_recvbuf
; //<! Buffer for receiving ghost velocities
231 GPUVector
<Scalar
> m_charge_ghost_sendbuf
; //!< Buffer for sending ghost charges
232 GPUVector
<Scalar
> m_charge_ghost_recvbuf
; //!< Buffer for sending ghost charges
234 GPUVector
<Scalar
> m_diameter_ghost_sendbuf
; //!< Buffer for sending ghost charges
235 GPUVector
<Scalar
> m_diameter_ghost_recvbuf
; //!< Buffer for sending ghost charges
237 GPUVector
<Scalar4
> m_orientation_ghost_sendbuf
;//<! Buffer for sending ghost orientations
238 GPUVector
<Scalar4
> m_orientation_ghost_recvbuf
;//<! Buffer for receiving ghost orientations
240 GPUVector
<unsigned int> m_tag_ghost_sendbuf_alt
; //!< Buffer for sending particle tags (standby)
241 GPUVector
<unsigned int> m_tag_ghost_recvbuf_alt
; //!< Buffer for recveiving particle tags (standby)
243 GPUVector
<Scalar4
> m_pos_ghost_sendbuf_alt
; //<! Buffer for sending ghost positions (standby)
244 GPUVector
<Scalar4
> m_pos_ghost_recvbuf_alt
; //<! Buffer for receiving ghost positions (standby)
246 GPUVector
<Scalar4
> m_vel_ghost_sendbuf_alt
; //<! Buffer for sending ghost velocities (standby)
247 GPUVector
<Scalar4
> m_vel_ghost_recvbuf_alt
; //<! Buffer for receiving ghost velocities (standby)
249 GPUVector
<Scalar
> m_charge_ghost_sendbuf_alt
; //!< Buffer for sending ghost charges (standby)
250 GPUVector
<Scalar
> m_charge_ghost_recvbuf_alt
; //!< Buffer for sending ghost charges (standby)
252 GPUVector
<Scalar
> m_diameter_ghost_sendbuf_alt
; //!< Buffer for sending ghost charges (standby)
253 GPUVector
<Scalar
> m_diameter_ghost_recvbuf_alt
; //!< Buffer for sending ghost charges (standby)
255 GPUVector
<Scalar4
> m_orientation_ghost_sendbuf_alt
;//<! Buffer for sending ghost orientations (standby)
256 GPUVector
<Scalar4
> m_orientation_ghost_recvbuf_alt
;//<! Buffer for receiving ghost orientations (standby)
258 GPUVector
<unsigned int> m_ghost_begin
; //!< Begin index for every stage and neighbor in send buf_alt
259 GPUVector
<unsigned int> m_ghost_end
; //!< Begin index for every and neighbor in send buf_alt
261 GPUVector
<uint2
> m_ghost_idx_adj
; //!< Indices and adjacency relationships of ghosts to send
262 GPUVector
<unsigned int> m_ghost_neigh
; //!< Neighbor ranks for every ghost particle
263 GPUVector
<unsigned int> m_ghost_plan
; //!< Plans for every particle
264 std::vector
<unsigned int> m_idx_offs
; //!< Per-stage offset into ghost idx list
266 GPUVector
<unsigned int> m_neigh_counts
; //!< List of number of neighbors to send ghost to (temp array)
268 std::vector
<std::vector
<unsigned int> > m_n_send_ghosts
; //!< Number of ghosts to send per stage and neighbor
269 std::vector
<std::vector
<unsigned int> > m_n_recv_ghosts
; //!< Number of ghosts to receive per stage and neighbor
270 std::vector
<std::vector
<unsigned int> > m_ghost_offs
; //!< Begin of offset in recv buf per stage and neighbor
272 std::vector
<unsigned int> m_n_send_ghosts_tot
; //!< Total number of sent ghosts per stage
273 std::vector
<unsigned int> m_n_recv_ghosts_tot
; //!< Total number of received ghosts per stage
275 mgpu::ContextPtr m_mgpu_context
; //!< MGPU context
276 cudaEvent_t m_event
; //!< CUDA event for synchronization
278 //! Helper function to allocate various buffers
279 void allocateBuffers();
281 //! Helper function to set up communication stages
282 void initializeCommunicationStages();
285 //! Export CommunicatorGPU class to python
286 void export_CommunicatorGPU();
288 #endif // ENABLE_CUDA
290 #endif // __COMMUNICATOR_GPU_H