CpuNeighborList.h 1.95 KB
Newer Older
1
2
3
4
#ifndef OPENMM_CPU_NEIGHBORLIST_H_
#define OPENMM_CPU_NEIGHBORLIST_H_

#include "windowsExportCpu.h"
5
#include <pthread.h>
6
7
8
9
10
11
12
13
#include <set>
#include <utility>
#include <vector>

namespace OpenMM {
    
class OPENMM_EXPORT_CPU CpuNeighborList {
public:
14
    class ThreadData;
15
    class Voxels;
16
    static const int BlockSize;
17
18
19
20
    CpuNeighborList();
    ~CpuNeighborList();
    void computeNeighborList(int numAtoms, const std::vector<float>& atomLocations, const std::vector<std::set<int> >& exclusions,
            const float* periodicBoxSize, bool usePeriodic, float maxDistance);
21
22
23
24
    int getNumBlocks() const;
    const std::vector<int>& getSortedAtoms() const;
    const std::vector<int>& getBlockNeighbors(int blockIndex) const;
    const std::vector<char>& getBlockExclusions(int blockIndex) const;
25
26
27
    /**
     * This routine contains the code executed by each thread.
     */
28
    void runThread(int index);
29
private:
30
31
32
33
34
35
36
37
    /**
     * This is called by the worker threads to wait until the master thread instructs them to advance.
     */
    void threadWait();
    /**
     * This is called by the master thread to instruct all the worker threads to advance.
     */
    void advanceThreads();
38
39
    bool isDeleted;
    int numThreads, waitCount;
40
41
42
    std::vector<int> sortedAtoms;
    std::vector<std::vector<int> > blockNeighbors;
    std::vector<std::vector<char> > blockExclusions;
43
44
45
46
47
    std::vector<pthread_t> thread;
    std::vector<ThreadData*> threadData;
    pthread_cond_t startCondition, endCondition;
    pthread_mutex_t lock;
    // The following variables are used to make information accessible to the individual threads.
48
49
    float minx, maxx, miny, maxy, minz, maxz;
    std::vector<std::pair<int, int> > atomBins;
50
    Voxels* voxels;
51
52
53
54
55
56
    const std::vector<std::set<int> >* exclusions;
    const float* atomLocations;
    const float* periodicBoxSize;
    int numAtoms;
    bool usePeriodic;
    float maxDistance;
57
58
59
60
61
};

} // namespace OpenMM

#endif // OPENMM_REFERENCE_NEIGHBORLIST_H_