kCalculateCustomNonbondedForces.h 25.5 KB
Newer Older
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
/* -------------------------------------------------------------------------- *
 *                                   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) 2009 Stanford University and the Authors.           *
 * Authors: Scott Le Grand, Peter Eastman                                     *
 * Contributors:                                                              *
 *                                                                            *
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU Lesser General Public License as published   *
 * by the Free Software Foundation, either version 3 of the License, or       *
 * (at your option) any later version.                                        *
 *                                                                            *
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU Lesser General Public License for more details.                        *
 *                                                                            *
 * You should have received a copy of the GNU Lesser General Public License   *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
 * -------------------------------------------------------------------------- */

/**
28
 * This file contains the kernels for evalauating custom nonbonded forces.  It is included
29
30
31
32
33
34
35
 * several times in kCalculateCustomNonbondedForces.cu with different #defines to generate
 * different versions of the kernels.
 */

__global__ void METHOD_NAME(kCalculateCustomNonbonded, Forces_kernel)(unsigned int* workUnit)
{
    extern __shared__ float stack[];
36
    Atom* sA = (Atom*) &stack[cSim.customExpressionStackSize*blockDim.x];
37
    float* variables = (float*) &sA[blockDim.x];
38
39
40
41
42
    unsigned int totalWarps = cSim.nonbond_blocks*cSim.nonbond_threads_per_block/GRID;
    unsigned int warp = (blockIdx.x*blockDim.x+threadIdx.x)/GRID;
    unsigned int numWorkUnits = cSim.pInteractionCount[0];
    unsigned int pos = warp*numWorkUnits/totalWarps;
    unsigned int end = (warp+1)*numWorkUnits/totalWarps;
43
    float totalEnergy = 0.0f;
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifdef USE_CUTOFF
    float3* tempBuffer = (float3*) &sA[cSim.nonbond_threads_per_block];
#endif

    unsigned int lasty = 0xFFFFFFFF;
    while (pos < end)
    {

        // Extract cell coordinates from appropriate work unit
        unsigned int x = workUnit[pos];
        unsigned int y = ((x >> 2) & 0x7fff) << GRIDBITS;
        bool bExclusionFlag = (x & 0x1);
        x = (x >> 17) << GRIDBITS;
        float4      apos;   // Local atom x, y, z, q
        float3      af;     // Local atom fx, fy, fz
        unsigned int tgx = threadIdx.x & (GRID - 1);
        unsigned int tbx = threadIdx.x - tgx;
        unsigned int tj = tgx;
        Atom* psA = &sA[tbx];
        unsigned int i      = x + tgx;
        apos                = cSim.pPosq[i];
65
        float4 params       = cSim.pCustomParams[i];
66
67
68
69
70
71
72
73
74
75
        af.x                = 0.0f;
        af.y                = 0.0f;
        af.z                = 0.0f;
        if (x == y) // Handle diagonals uniquely at 50% efficiency
        {
            // Read fixed atom data into registers and GRF
            sA[threadIdx.x].x   = apos.x;
            sA[threadIdx.x].y   = apos.y;
            sA[threadIdx.x].z   = apos.z;
            sA[threadIdx.x].params = params;
76
77
78
79
            unsigned int xi   = x>>GRIDBITS;
            unsigned int cell = xi+xi*cSim.paddedNumberOfAtoms/GRID-xi*(xi+1)/2;
            unsigned int excl = cSim.pExclusion[cSim.pExclusionIndex[cell]+tgx];
            for (unsigned int j = 0; j < GRID; j++)
80
            {
81
82
                // Apply the combining rules to the parameters.

83
84
85
86
87
                float combinedParams[4];
                VARIABLE(0) = params.x;
                VARIABLE(1) = params.y;
                VARIABLE(2) = params.z;
                VARIABLE(3) = params.w;
88
89
90
91
                VARIABLE(4) = psA[j].params.x;
                VARIABLE(5) = psA[j].params.y;
                VARIABLE(6) = psA[j].params.z;
                VARIABLE(7) = psA[j].params.w;
92
                for (int k = 0; k < cSim.customParameters; k++)
93
                {
94
                    float value = kEvaluateExpression_kernel(&combiningRules[k], stack, variables);
95
                    switch (k)
96
                    {
97
                        case 0:
98
                            combinedParams[0] = value;
99
100
                            break;
                        case 1:
101
                            combinedParams[1] = value;
102
103
                            break;
                        case 2:
104
                            combinedParams[2] = value;
105
106
                            break;
                        case 3:
107
                            combinedParams[3] = value;
108
                            break;
109
110
                    }
                }
111
112
113
114
                VARIABLE(1) = combinedParams[0];
                VARIABLE(2) = combinedParams[1];
                VARIABLE(3) = combinedParams[2];
                VARIABLE(4) = combinedParams[3];
115
116
117
118
119
120

                // Compute the force.

                float dx        = psA[j].x - apos.x;
                float dy        = psA[j].y - apos.y;
                float dz        = psA[j].z - apos.z;
121
#ifdef USE_PERIODIC
122
123
124
                dx -= floor(dx/cSim.periodicBoxSizeX+0.5f)*cSim.periodicBoxSizeX;
                dy -= floor(dy/cSim.periodicBoxSizeY+0.5f)*cSim.periodicBoxSizeY;
                dz -= floor(dz/cSim.periodicBoxSizeZ+0.5f)*cSim.periodicBoxSizeZ;
125
#endif
126
127
                float r         = sqrt(dx*dx + dy*dy + dz*dz);
                float invR      = 1.0f/r;
128
129
130
                VARIABLE(0)     = r;
                float dEdR      = -kEvaluateExpression_kernel(&forceExp, stack, variables)*invR;
                float energy    = kEvaluateExpression_kernel(&energyExp, stack, variables);
131
#ifdef USE_CUTOFF
132
                if (!(excl & 0x1) || r > cSim.nonbondedCutoff)
133
#else
134
                if (!(excl & 0x1))
135
#endif
136
137
                {
                    dEdR = 0.0f;
138
                    energy = 0.0f;
139
                }
140
                totalEnergy    += 0.5f*energy;
141
142
143
144
145
146
147
                dx             *= dEdR;
                dy             *= dEdR;
                dz             *= dEdR;
                af.x           -= dx;
                af.y           -= dy;
                af.z           -= dz;
                excl          >>= 1;
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
            }

            // Write results
            float4 of;
#ifdef USE_OUTPUT_BUFFER_PER_WARP
            unsigned int offset                          = x + tgx + warp*cSim.stride;
            of                                  = cSim.pForce4a[offset];
            of.x                               += af.x;
            of.y                               += af.y;
            of.z                               += af.z;
            cSim.pForce4a[offset]               = of;
#else
            of.x                                = af.x;
            of.y                                = af.y;
            of.z                                = af.z;
            of.w                                = 0.0f;
            unsigned int offset                          = x + tgx + (x >> GRIDBITS) * cSim.stride;
            cSim.pForce4a[offset]               = of;
#endif
        }
        else        // 100% utilization
        {
            // Read fixed atom data into registers and GRF
            if (lasty != y)
            {
                unsigned int j                   = y + tgx;
                float4 temp             = cSim.pPosq[j];
                sA[threadIdx.x].x       = temp.x;
                sA[threadIdx.x].y       = temp.y;
                sA[threadIdx.x].z       = temp.z;
178
                sA[threadIdx.x].params  = cSim.pCustomParams[j];
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
            }
            sA[threadIdx.x].fx      = 0.0f;
            sA[threadIdx.x].fy      = 0.0f;
            sA[threadIdx.x].fz      = 0.0f;
            if (!bExclusionFlag)
            {
#ifdef USE_CUTOFF
                unsigned int flags = cSim.pInteractionFlag[pos];
                if (flags == 0)
                {
                    // No interactions in this block.
                }
                else if (flags == 0xFFFFFFFF)
#endif
                {
                    // Compute all interactions within this block.

                    for (unsigned int j = 0; j < GRID; j++)
                    {
198
199
                        // Apply the combining rules to the parameters.

200
201
202
203
204
                        float combinedParams[4];
                        VARIABLE(0) = params.x;
                        VARIABLE(1) = params.y;
                        VARIABLE(2) = params.z;
                        VARIABLE(3) = params.w;
205
206
207
208
                        VARIABLE(4) = psA[tj].params.x;
                        VARIABLE(5) = psA[tj].params.y;
                        VARIABLE(6) = psA[tj].params.z;
                        VARIABLE(7) = psA[tj].params.w;
209
210
                        for (int k = 0; k < cSim.customParameters; k++)
                        {
211
                            float value = kEvaluateExpression_kernel(&combiningRules[k], stack, variables);
212
213
214
                            switch (k)
                            {
                                case 0:
215
                                    combinedParams[0] = value;
216
217
                                    break;
                                case 1:
218
                                    combinedParams[1] = value;
219
220
                                    break;
                                case 2:
221
                                    combinedParams[2] = value;
222
223
                                    break;
                                case 3:
224
                                    combinedParams[3] = value;
225
226
227
                                    break;
                            }
                        }
228
229
230
231
                        VARIABLE(1) = combinedParams[0];
                        VARIABLE(2) = combinedParams[1];
                        VARIABLE(3) = combinedParams[2];
                        VARIABLE(4) = combinedParams[3];
232
233
234

                        // Compute the force.

235
236
237
238
239
240
241
242
243
244
                        float dx        = psA[tj].x - apos.x;
                        float dy        = psA[tj].y - apos.y;
                        float dz        = psA[tj].z - apos.z;
#ifdef USE_PERIODIC
                        dx -= floor(dx/cSim.periodicBoxSizeX+0.5f)*cSim.periodicBoxSizeX;
                        dy -= floor(dy/cSim.periodicBoxSizeY+0.5f)*cSim.periodicBoxSizeY;
                        dz -= floor(dz/cSim.periodicBoxSizeZ+0.5f)*cSim.periodicBoxSizeZ;
#endif
                        float r         = sqrt(dx*dx + dy*dy + dz*dz);
                        float invR      = 1.0f/r;
245
246
247
                        VARIABLE(0)     = r;
                        float dEdR      = -kEvaluateExpression_kernel(&forceExp, stack, variables)*invR;
                        float energy    = kEvaluateExpression_kernel(&energyExp, stack, variables);
248
249
250
251
#ifdef USE_CUTOFF
                        if (r > cSim.nonbondedCutoff)
                        {
                            dEdR = 0.0f;
252
                            energy = 0.0f;
253
254
                        }
#endif
255
                        totalEnergy    += energy;
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
                        dx             *= dEdR;
                        dy             *= dEdR;
                        dz             *= dEdR;
                        af.x           -= dx;
                        af.y           -= dy;
                        af.z           -= dz;
                        psA[tj].fx     += dx;
                        psA[tj].fy     += dy;
                        psA[tj].fz     += dz;
                        tj              = (tj + 1) & (GRID - 1);
                    }
                }
#ifdef USE_CUTOFF
                else
                {
                    // Compute only a subset of the interactions in this block.

                    for (unsigned int j = 0; j < GRID; j++)
                    {
                        if ((flags&(1<<j)) != 0)
                        {
277
278
                            // Apply the combining rules to the parameters.

279
280
281
282
283
                            float combinedParams[4];
                            VARIABLE(0) = params.x;
                            VARIABLE(1) = params.y;
                            VARIABLE(2) = params.z;
                            VARIABLE(3) = params.w;
284
285
286
287
                            VARIABLE(4) = psA[j].params.x;
                            VARIABLE(5) = psA[j].params.y;
                            VARIABLE(6) = psA[j].params.z;
                            VARIABLE(7) = psA[j].params.w;
288
289
                            for (int k = 0; k < cSim.customParameters; k++)
                            {
290
                                float value = kEvaluateExpression_kernel(&combiningRules[k], stack, variables);
291
292
293
                                switch (k)
                                {
                                    case 0:
294
                                        combinedParams[0] = value;
295
296
                                        break;
                                    case 1:
297
                                        combinedParams[1] = value;
298
299
                                        break;
                                    case 2:
300
                                        combinedParams[2] = value;
301
302
                                        break;
                                    case 3:
303
                                        combinedParams[3] = value;
304
305
306
                                        break;
                                }
                            }
307
308
309
310
                            VARIABLE(1) = combinedParams[0];
                            VARIABLE(2) = combinedParams[1];
                            VARIABLE(3) = combinedParams[2];
                            VARIABLE(4) = combinedParams[3];
311
312
313

                            // Compute the force.

314
315
316
317
318
319
320
321
322
323
                            float dx        = psA[j].x - apos.x;
                            float dy        = psA[j].y - apos.y;
                            float dz        = psA[j].z - apos.z;
#ifdef USE_PERIODIC
                            dx -= floor(dx/cSim.periodicBoxSizeX+0.5f)*cSim.periodicBoxSizeX;
                            dy -= floor(dy/cSim.periodicBoxSizeY+0.5f)*cSim.periodicBoxSizeY;
                            dz -= floor(dz/cSim.periodicBoxSizeZ+0.5f)*cSim.periodicBoxSizeZ;
#endif
                            float r         = sqrt(dx*dx + dy*dy + dz*dz);
                            float invR      = 1.0f/r;
324
325
326
                            VARIABLE(0)     = r;
                            float dEdR      = -kEvaluateExpression_kernel(&forceExp, stack, variables)*invR;
                            float energy    = kEvaluateExpression_kernel(&energyExp, stack, variables);
327
328
329
330
#ifdef USE_CUTOFF
                            if (r > cSim.nonbondedCutoff)
                            {
                                dEdR = 0.0f;
331
                                energy = 0.0f;
332
333
                            }
#endif
334
                            totalEnergy    += energy;
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
                            dx             *= dEdR;
                            dy             *= dEdR;
                            dz             *= dEdR;
                            af.x           -= dx;
                            af.y           -= dy;
                            af.z           -= dz;
                            tempBuffer[threadIdx.x].x = dx;
                            tempBuffer[threadIdx.x].y = dy;
                            tempBuffer[threadIdx.x].z = dz;

                            // Sum the forces on atom j.

                            if (tgx % 2 == 0)
                            {
                                tempBuffer[threadIdx.x].x += tempBuffer[threadIdx.x+1].x;
                                tempBuffer[threadIdx.x].y += tempBuffer[threadIdx.x+1].y;
                                tempBuffer[threadIdx.x].z += tempBuffer[threadIdx.x+1].z;
                            }
                            if (tgx % 4 == 0)
                            {
                                tempBuffer[threadIdx.x].x += tempBuffer[threadIdx.x+2].x;
                                tempBuffer[threadIdx.x].y += tempBuffer[threadIdx.x+2].y;
                                tempBuffer[threadIdx.x].z += tempBuffer[threadIdx.x+2].z;
                            }
                            if (tgx % 8 == 0)
                            {
                                tempBuffer[threadIdx.x].x += tempBuffer[threadIdx.x+4].x;
                                tempBuffer[threadIdx.x].y += tempBuffer[threadIdx.x+4].y;
                                tempBuffer[threadIdx.x].z += tempBuffer[threadIdx.x+4].z;
                            }
                            if (tgx % 16 == 0)
                            {
                                tempBuffer[threadIdx.x].x += tempBuffer[threadIdx.x+8].x;
                                tempBuffer[threadIdx.x].y += tempBuffer[threadIdx.x+8].y;
                                tempBuffer[threadIdx.x].z += tempBuffer[threadIdx.x+8].z;
                            }
                            if (tgx == 0)
                            {
                                psA[j].fx += tempBuffer[threadIdx.x].x + tempBuffer[threadIdx.x+16].x;
                                psA[j].fy += tempBuffer[threadIdx.x].y + tempBuffer[threadIdx.x+16].y;
                                psA[j].fz += tempBuffer[threadIdx.x].z + tempBuffer[threadIdx.x+16].z;
                            }
                        }
                    }
                }
#endif
            }
            else  // bExclusion
            {
                // Read fixed atom data into registers and GRF
                unsigned int xi   = x>>GRIDBITS;
                unsigned int yi   = y>>GRIDBITS;
                unsigned int cell          = xi+yi*cSim.paddedNumberOfAtoms/GRID-yi*(yi+1)/2;
                unsigned int excl = cSim.pExclusion[cSim.pExclusionIndex[cell]+tgx];
                excl              = (excl >> tgx) | (excl << (GRID - tgx));
                for (unsigned int j = 0; j < GRID; j++)
                {
392
393
                    // Apply the combining rules to the parameters.

394
395
396
397
398
                    float combinedParams[4];
                    VARIABLE(0) = params.x;
                    VARIABLE(1) = params.y;
                    VARIABLE(2) = params.z;
                    VARIABLE(3) = params.w;
399
400
401
402
                    VARIABLE(4) = psA[tj].params.x;
                    VARIABLE(5) = psA[tj].params.y;
                    VARIABLE(6) = psA[tj].params.z;
                    VARIABLE(7) = psA[tj].params.w;
403
404
                    for (int k = 0; k < cSim.customParameters; k++)
                    {
405
                        float value = kEvaluateExpression_kernel(&combiningRules[k], stack, variables);
406
407
408
                        switch (k)
                        {
                            case 0:
409
                                combinedParams[0] = value;
410
411
                                break;
                            case 1:
412
                                combinedParams[1] = value;
413
414
                                break;
                            case 2:
415
                                combinedParams[2] = value;
416
417
                                break;
                            case 3:
418
                                combinedParams[3] = value;
419
420
421
                                break;
                        }
                    }
422
423
424
425
                    VARIABLE(1) = combinedParams[0];
                    VARIABLE(2) = combinedParams[1];
                    VARIABLE(3) = combinedParams[2];
                    VARIABLE(4) = combinedParams[3];
426
427
428

                    // Compute the force.

429
430
431
432
433
434
435
436
437
438
                    float dx        = psA[tj].x - apos.x;
                    float dy        = psA[tj].y - apos.y;
                    float dz        = psA[tj].z - apos.z;
#ifdef USE_PERIODIC
                    dx -= floor(dx/cSim.periodicBoxSizeX+0.5f)*cSim.periodicBoxSizeX;
                    dy -= floor(dy/cSim.periodicBoxSizeY+0.5f)*cSim.periodicBoxSizeY;
                    dz -= floor(dz/cSim.periodicBoxSizeZ+0.5f)*cSim.periodicBoxSizeZ;
#endif
                    float r         = sqrt(dx*dx + dy*dy + dz*dz);
                    float invR      = 1.0f/r;
439
440
441
                    VARIABLE(0)     = r;
                    float dEdR      = -kEvaluateExpression_kernel(&forceExp, stack, variables)*invR;
                    float energy    = kEvaluateExpression_kernel(&energyExp, stack, variables);
442
443
444
445
446
447
448
#ifdef USE_CUTOFF
                    if (!(excl & 0x1) || r > cSim.nonbondedCutoff)
#else
                    if (!(excl & 0x1))
#endif
                    {
                        dEdR = 0.0f;
449
                        energy = 0.0f;
450
                    }
451
                    totalEnergy    += energy;
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
                    dx             *= dEdR;
                    dy             *= dEdR;
                    dz             *= dEdR;
                    af.x           -= dx;
                    af.y           -= dy;
                    af.z           -= dz;
                    psA[tj].fx     += dx;
                    psA[tj].fy     += dy;
                    psA[tj].fz     += dz;
                    excl          >>= 1;
                    tj              = (tj + 1) & (GRID - 1);
                }
            }

            // Write results
            float4 of;
#ifdef USE_OUTPUT_BUFFER_PER_WARP
            unsigned int offset                 = x + tgx + warp*cSim.stride;
            of                                  = cSim.pForce4a[offset];
            of.x                               += af.x;
            of.y                               += af.y;
            of.z                               += af.z;
            cSim.pForce4a[offset]               = of;
            offset                              = y + tgx + warp*cSim.stride;
            of                                  = cSim.pForce4a[offset];
            of.x                               += sA[threadIdx.x].fx;
            of.y                               += sA[threadIdx.x].fy;
            of.z                               += sA[threadIdx.x].fz;
            cSim.pForce4a[offset]               = of;
#else
            of.x                                = af.x;
            of.y                                = af.y;
            of.z                                = af.z;
            of.w                                = 0.0f;
            unsigned int offset                 = x + tgx + (y >> GRIDBITS) * cSim.stride;
            cSim.pForce4a[offset]               = of;
            of.x                                = sA[threadIdx.x].fx;
            of.y                                = sA[threadIdx.x].fy;
            of.z                                = sA[threadIdx.x].fz;
            offset                              = y + tgx + (x >> GRIDBITS) * cSim.stride;
            cSim.pForce4a[offset]               = of;
#endif
            lasty = y;
        }

        pos++;
    }
499
    cSim.pEnergy[blockIdx.x*blockDim.x+threadIdx.x] += totalEnergy;
500
}
501
502
503
504
505


__global__ void METHOD_NAME(kCalculateCustomNonbonded, Exceptions_kernel)()
{
    extern __shared__ float stack[];
506
    float* variables = (float*) &stack[cSim.customExpressionStackSize*blockDim.x];
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
    unsigned int pos = blockIdx.x * blockDim.x + threadIdx.x;
    float totalEnergy = 0.0f;

    while (pos < cSim.customExceptions)
    {
        int4 atom       = cSim.pCustomExceptionID[pos];
        float4 params   = cSim.pCustomExceptionParams[pos];
        float4 a1       = cSim.pPosq[atom.x];
        float4 a2       = cSim.pPosq[atom.y];
        float dx        = a1.x - a2.x;
        float dy        = a1.y - a2.y;
        float dz        = a1.z - a2.z;
#ifdef USE_PERIODIC
        dx -= floor(dx/cSim.periodicBoxSizeX+0.5f)*cSim.periodicBoxSizeX;
        dy -= floor(dy/cSim.periodicBoxSizeY+0.5f)*cSim.periodicBoxSizeY;
        dz -= floor(dz/cSim.periodicBoxSizeZ+0.5f)*cSim.periodicBoxSizeZ;
#endif
        float r         = sqrt(dx*dx + dy*dy + dz*dz);
        float invR      = 1.0f/r;
526
527
528
529
530
531
532
        VARIABLE(0)     = r;
        VARIABLE(1)     = params.x;
        VARIABLE(2)     = params.y;
        VARIABLE(3)     = params.z;
        VARIABLE(4)     = params.w;
        float dEdR      = -kEvaluateExpression_kernel(&forceExp, stack, variables)*invR;
        float energy    = kEvaluateExpression_kernel(&energyExp, stack, variables);
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#ifdef USE_CUTOFF
        if (r > cSim.nonbondedCutoff)
        {
            dEdR = 0.0f;
            energy = 0.0f;
        }
#endif
        totalEnergy          += energy;
        dx                   *= dEdR;
        dy                   *= dEdR;
        dz                   *= dEdR;
        unsigned int offsetA  = atom.x + atom.z * cSim.stride;
        unsigned int offsetB  = atom.y + atom.w * cSim.stride;
        float4 forceA         = cSim.pForce4[offsetA];
        float4 forceB         = cSim.pForce4[offsetB];
        forceA.x             += dx;
        forceA.y             += dy;
        forceA.z             += dz;
        forceB.x             -= dx;
        forceB.y             -= dy;
        forceB.z             -= dz;
        cSim.pForce4[offsetA] = forceA;
        cSim.pForce4[offsetB] = forceB;
        pos                  += blockDim.x * gridDim.x;
    }
    cSim.pEnergy[blockIdx.x * blockDim.x + threadIdx.x] += totalEnergy;
}