CpuPme.h 3.63 KB
Newer Older
peastman's avatar
peastman committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef OPENMM_CPU_PME_H_
#define OPENMM_CPU_PME_H_

/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2013 Stanford University and the Authors.           *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

#include "windowsExportCuda.h"
#include "openmm/Vec3.h"
37
38
#include <complex>
#include <fftw3.h>
peastman's avatar
peastman committed
39
40
41
42
43
44
45
46
47
48
#include <pthread.h>
#include <vector>

namespace OpenMM {

/**
 */

class OPENMM_EXPORT_CUDA CpuPme {
public:
49
    class ThreadData;
peastman's avatar
peastman committed
50
51
52
53
    /**
     */
    CpuPme(int gridx, int gridy, int gridz, int numParticles, double alpha);
    ~CpuPme();
54
    double computeForceAndEnergy(float* posq, float* force, Vec3 periodicBoxSize, bool includeEnergy);
55
    void runThread(int index);
peastman's avatar
peastman committed
56
private:
57
58
    void threadWait();
    void advanceThreads();
59
60
    static bool hasInitializedThreads;
    static int numThreads;
peastman's avatar
peastman committed
61
62
    int gridx, gridy, gridz, numParticles;
    double alpha;
63
    bool hasCreatedPlan, isFinished;
64
65
66
67
    std::vector<float> bsplineModuli[3];
    float* realGrid;
    fftwf_complex* complexGrid;
    fftwf_plan forwardFFT, backwardFFT;
68
69
70
    int waitCount;
    pthread_cond_t startCondition, endCondition;
    pthread_mutex_t lock;
peastman's avatar
peastman committed
71
    std::vector<pthread_t> thread;
72
73
74
75
76
77
78
    std::vector<ThreadData*> threadData;
    // The following variables are used to store information about the calculation currently being performed.
    float energy;
    float* posq;
    float* force;
    Vec3 periodicBoxSize;
    bool includeEnergy;
peastman's avatar
peastman committed
79
80
81
82
83
};

} // namespace OpenMM

#endif /*OPENMM_CPU_PME_H_*/