customGBEnergyPerParticle.cl 1006 Bytes
Newer Older
Peter Eastman's avatar
Peter Eastman committed
1
#define REDUCE_VALUE(NAME, TYPE) {\
2
3
4
    TYPE sum = NAME[index]; \
    for (int i = index+bufferSize; i < totalSize; i += bufferSize) \
        sum += NAME[i]; \
Peter Eastman's avatar
Peter Eastman committed
5
6
    NAME[index] = sum; \
}
7

8
9
10
11
/**
 * Reduce the derivatives computed in the N^2 energy kernel, and compute all per-particle energy terms.
 */

12
__kernel void computePerParticleEnergy(int bufferSize, int numBuffers, __global real4* restrict forceBuffers, __global mixed* restrict energyBuffer, __global const real4* restrict posq
13
        PARAMETER_ARGUMENTS) {
14
    mixed energy = 0;
15
    INIT_PARAM_DERIVS
16
17
18
19
    unsigned int index = get_global_id(0);
    while (index < NUM_ATOMS) {
        // Reduce the derivatives

20
21
        int totalSize = bufferSize*numBuffers;
        REDUCE_DERIVATIVES
22
23
24

        // Now calculate the per-particle energy terms.

25
26
        real4 pos = posq[index];
        real4 force = (real4) 0;
27
28
29
30
        COMPUTE_ENERGY
        index += get_global_size(0);
    }
    energyBuffer[get_global_id(0)] += energy;
31
    SAVE_PARAM_DERIVS
32
}