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: joaander
52 #include "NeighborList.h"
54 #include "Autotuner.h"
56 /*! \file NeighborListGPU.h
57 \brief Declares the NeighborListGPU class
61 #error This header cannot be compiled by nvcc
64 #ifndef __NEIGHBORLISTGPU_H__
65 #define __NEIGHBORLISTGPU_H__
67 //! Neighbor list build on the GPU
68 /*! Implements the O(N^2) neighbor list build on the GPU. Also implements common functions (like distance check)
69 on the GPU for use by other GPU nlist classes derived from NeighborListGPU.
71 GPU kernel methods are defined in NeighborListGPU.cuh and defined in NeighborListGPU.cu.
75 class NeighborListGPU
: public NeighborList
78 //! Constructs the compute
79 NeighborListGPU(boost::shared_ptr
<SystemDefinition
> sysdef
, Scalar r_cut
, Scalar r_buff
)
80 : NeighborList(sysdef
, r_cut
, r_buff
)
82 GPUArray
<unsigned int> flags(1,exec_conf
,true);
84 ArrayHandle
<unsigned int> h_flags(m_flags
,access_location::host
, access_mode::overwrite
);
87 // default to full mode
88 m_storage_mode
= full
;
90 m_distcheck_scheduled
= false;
91 m_last_schedule_tstep
= 0;
94 cudaEventCreate(&m_event
,cudaEventDisableTiming
);
96 m_tuner_filter
.reset(new Autotuner(32, 1024, 32, 5, 100000, "nlist_filter", this->m_exec_conf
));
100 virtual ~NeighborListGPU()
103 if (m_callback_connection
.connected())
104 m_callback_connection
.disconnect();
107 cudaEventDestroy(m_event
);
110 //! Set autotuner parameters
111 /*! \param enable Enable/disable autotuning
112 \param period period (approximate) in time steps when returning occurs
114 virtual void setAutotunerParams(bool enable
, unsigned int period
)
116 NeighborList::setAutotunerParams(enable
, period
);
117 m_tuner_filter
->setPeriod(period
/10);
118 m_tuner_filter
->setEnabled(enable
);
121 //! Benchmark the filter kernel
122 double benchmarkFilter(unsigned int num_iters
);
124 //! Update the exclusion list on the GPU
125 virtual void updateExListIdx();
128 //! Set the communicator to use
129 /*! \param comm MPI communication class
131 virtual void setCommunicator(boost::shared_ptr
<Communicator
> comm
)
133 // upon first call, register with Communicator
135 comm
->addLocalComputeCallback(bind(&NeighborListGPU::scheduleDistanceCheck
, this, _1
));
137 // call base class method
138 NeighborList::setCommunicator(comm
);
142 //! Schedule the distance check kernel
143 /*! \param timestep Current time step
145 void scheduleDistanceCheck(unsigned int timestep
);
148 GPUArray
<unsigned int> m_flags
; //!< Storage for device flags on the GPU
150 //! Builds the neighbor list
151 virtual void buildNlist(unsigned int timestep
);
153 //! Perform the nlist distance check on the GPU
154 virtual bool distanceCheck(unsigned int timestep
);
156 //! GPU nlists set their last updated pos in the compute kernel, this call only resets the last box length
157 virtual void setLastUpdatedPos()
159 m_last_L
= m_pdata
->getGlobalBox().getNearestPlaneDistance();
160 m_last_L_local
= m_pdata
->getBox().getNearestPlaneDistance();
163 //! Filter the neighbor list of excluded particles
164 virtual void filterNlist();
167 boost::scoped_ptr
<Autotuner
> m_tuner_filter
; //!< Autotuner for filter block size
169 unsigned int m_checkn
; //!< Internal counter to assign when checking if the nlist needs an update
170 bool m_distcheck_scheduled
; //!< True if a distance check kernel has been queued
171 unsigned int m_last_schedule_tstep
; //!< Time step of last kernel schedule
173 cudaEvent_t m_event
; //!< Event signalling completion of distcheck kernel
175 boost::signals2::connection m_callback_connection
; //!< Connection to Communicator
179 //! Exports NeighborListGPU to python
180 void export_NeighborListGPU();