customGBEnergyPerParticle.cl 968 Bytes
Newer Older
1
2
3
4
5
6
#define REDUCE_VALUE(NAME, TYPE) \
    TYPE sum = NAME[index]; \
    for (int i = index+bufferSize; i < totalSize; i += bufferSize) \
        sum += NAME[i]; \
    NAME[index] = sum;

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

11
__kernel void computePerParticleEnergy(int bufferSize, int numBuffers, __global float4* restrict forceBuffers, __global float* restrict energyBuffer, __global const float4* restrict posq
12
13
14
15
16
17
        PARAMETER_ARGUMENTS) {
    float energy = 0.0f;
    unsigned int index = get_global_id(0);
    while (index < NUM_ATOMS) {
        // Reduce the derivatives

18
19
        int totalSize = bufferSize*numBuffers;
        REDUCE_DERIVATIVES
20
21
22

        // Now calculate the per-particle energy terms.

23
24
        float4 pos = posq[index];
        float4 force = (float4) 0.0f;
25
26
27
28
29
        COMPUTE_ENERGY
        index += get_global_size(0);
    }
    energyBuffer[get_global_id(0)] += energy;
}