kCalculateAmoebaCudaPmeDirectElectrostatic.h 20.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
28
29
30
31
/* -------------------------------------------------------------------------- *
 *                                   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/>.      *
 * -------------------------------------------------------------------------- */

#include "amoebaScaleFactors.h"

__global__ 
#if (__CUDA_ARCH__ >= 200)
__launch_bounds__(384, 1)
32
#elif (__CUDA_ARCH__ >= 120)
33
34
35
36
__launch_bounds__(128, 1)
#else
__launch_bounds__(64, 1)
#endif
Mark Friedrichs's avatar
Mark Friedrichs committed
37
void METHOD_NAME(kCalculateAmoebaPmeDirectElectrostatic, Forces_kernel)(
38
                            unsigned int* workUnit, float* outputTorque
39
40
41
42
43
44

#ifdef AMOEBA_DEBUG
                           , float4* debugArray, unsigned int targetAtom
#endif
){
#ifdef AMOEBA_DEBUG
Mark Friedrichs's avatar
Mark Friedrichs committed
45
    int maxPullIndex = 7;
46
    float4 pullBack[12];
47
48
#endif

Mark Friedrichs's avatar
Mark Friedrichs committed
49
    extern __shared__ PmeDirectElectrostaticParticle sA[];
50
51
52
53
54
55
56
57

    unsigned int totalWarps      = gridDim.x*blockDim.x/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;
    unsigned int lasty           = 0xFFFFFFFF;
    float totalEnergy            = 0.0f;     
Mark Friedrichs's avatar
Mark Friedrichs committed
58
    float4 forceTorqueEnergy[3];
59
60

    float scalingFactors[LastScalingIndex];
Mark Friedrichs's avatar
Mark Friedrichs committed
61
    float conversionFactor       = (-cAmoebaSim.electric/cAmoebaSim.dielec);
62
63
64
65
66
67
68

    while (pos < end)
    {

        unsigned int x;
        unsigned int y;
        bool bExclusionFlag;
Mark Friedrichs's avatar
Mark Friedrichs committed
69
70
71
        int  dScaleMask;
        int2 pScaleMask;
        int2 mScaleMask;
72
73
74
75
76

        // Extract cell coordinates

        decodeCell( workUnit[pos], &x, &y, &bExclusionFlag );

Mark Friedrichs's avatar
Mark Friedrichs committed
77
78
79
        unsigned int tgx                       = threadIdx.x & (GRID - 1);
        unsigned int tbx                       = threadIdx.x - tgx;
        unsigned int tj                        = tgx;
80

Mark Friedrichs's avatar
Mark Friedrichs committed
81
        PmeDirectElectrostaticParticle* psA    = &sA[tbx];
Mark Friedrichs's avatar
Mark Friedrichs committed
82
        unsigned int atomI                     = x + tgx;
Mark Friedrichs's avatar
Mark Friedrichs committed
83
84
        PmeDirectElectrostaticParticle localParticle;
        loadPmeDirectElectrostaticShared(&localParticle, atomI );
85

Mark Friedrichs's avatar
Mark Friedrichs committed
86
87
88
        localParticle.force[0]                 = 0.0f;
        localParticle.force[1]                 = 0.0f;
        localParticle.force[2]                 = 0.0f;
89

Mark Friedrichs's avatar
Mark Friedrichs committed
90
91
92
        localParticle.torque[0]                = 0.0f;
        localParticle.torque[1]                = 0.0f;
        localParticle.torque[2]                = 0.0f;
93

Mark Friedrichs's avatar
Mark Friedrichs committed
94
        scalingFactors[UScaleIndex]            = 1.0f;
95
96
97
98
99
100

        if (x == y) // Handle diagonals uniquely at 50% efficiency
        {

            // load shared data

Mark Friedrichs's avatar
Mark Friedrichs committed
101
            loadPmeDirectElectrostaticShared( &(sA[threadIdx.x]), atomI );
102

Mark Friedrichs's avatar
Mark Friedrichs committed
103
            if (bExclusionFlag)
104
105
            {
                unsigned int xi       = x >> GRIDBITS;
106
                unsigned int cell     = xi + xi*cSim.paddedNumberOfAtoms/GRID-xi*(xi+1)/2;
Mark Friedrichs's avatar
Mark Friedrichs committed
107
108
109
110
111
112
                dScaleMask            = cAmoebaSim.pD_ScaleIndices[cAmoebaSim.pScaleIndicesIndex[cell]+tgx];
                pScaleMask            = cAmoebaSim.pP_ScaleIndices[cAmoebaSim.pScaleIndicesIndex[cell]+tgx];
                mScaleMask            = cAmoebaSim.pM_ScaleIndices[cAmoebaSim.pScaleIndicesIndex[cell]+tgx];
            } else {
                scalingFactors[DScaleIndex] = scalingFactors[PScaleIndex] = scalingFactors[MScaleIndex] = 1.0f;
            }
113

Mark Friedrichs's avatar
Mark Friedrichs committed
114
115
            for (unsigned int j = 0; j < GRID; j++)
            {
116

Mark Friedrichs's avatar
Mark Friedrichs committed
117
                unsigned int atomJ = y + j;
118

Mark Friedrichs's avatar
Mark Friedrichs committed
119
                // set scale factors
120

Mark Friedrichs's avatar
Mark Friedrichs committed
121
122
                if (bExclusionFlag)
                {
123
124
125
                    getMaskedDScaleFactor( j, dScaleMask, scalingFactors + DScaleIndex );
                    getMaskedPScaleFactor( j, pScaleMask, scalingFactors + PScaleIndex );
                    getMaskedMScaleFactor( j, mScaleMask, scalingFactors + MScaleIndex );
Mark Friedrichs's avatar
Mark Friedrichs committed
126
                }
127

Mark Friedrichs's avatar
Mark Friedrichs committed
128
                // force
129

Mark Friedrichs's avatar
Mark Friedrichs committed
130
                calculatePmeDirectElectrostaticPairIxn_kernel( localParticle, psA[j], scalingFactors, forceTorqueEnergy
131
132
133
134
135
#ifdef AMOEBA_DEBUG
, pullBack
#endif
 );

Mark Friedrichs's avatar
Mark Friedrichs committed
136
137
                // nan*0.0 = nan not 0.0, so explicitly exclude (atomI == atomJ) contribution
                // by setting match flag
138

139
                if( (atomI != atomJ) && (atomI < cSim.atoms) && (atomJ < cSim.atoms) )
Mark Friedrichs's avatar
Mark Friedrichs committed
140
141
142
143
144
145
146
147
148
149
                {
                    localParticle.force[0]      += forceTorqueEnergy[0].x;
                    localParticle.force[1]      += forceTorqueEnergy[0].y;
                    localParticle.force[2]      += forceTorqueEnergy[0].z;
    
                    localParticle.torque[0]     += forceTorqueEnergy[1].x;
                    localParticle.torque[1]     += forceTorqueEnergy[1].y;
                    localParticle.torque[2]     += forceTorqueEnergy[1].z;
    
                    // energy for each diagonal-block ixn included twice, hence factor of 0.5
150

Mark Friedrichs's avatar
Mark Friedrichs committed
151
152
                    totalEnergy                 += 0.5*forceTorqueEnergy[0].w;
                }
153
154

#ifdef AMOEBA_DEBUG
Mark Friedrichs's avatar
Mark Friedrichs committed
155
if( atomI == targetAtom || atomJ == targetAtom ){
156

157
    unsigned int mask       =  ( (atomI == atomJ) || (atomI >= cSim.atoms) || (atomJ >= cSim.atoms) ) ? 0 : 1;
Mark Friedrichs's avatar
Mark Friedrichs committed
158
159
160
161
162
163
164
165
    unsigned int index                 = (atomI == targetAtom) ? atomJ : atomI;
    float blockId                      = 1.0f;

    debugArray[index].x                = (float) atomI;
    debugArray[index].y                = (float) atomJ;
    debugArray[index].z                = (float) y;
    debugArray[index].w                = blockId;

166
    index                             += cSim.paddedNumberOfAtoms;
Mark Friedrichs's avatar
Mark Friedrichs committed
167
168
169
170
    debugArray[index].x                = mask ? forceTorqueEnergy[0].x  : 0.0f;
    debugArray[index].y                = mask ? forceTorqueEnergy[0].y  : 0.0f;
    debugArray[index].z                = mask ? forceTorqueEnergy[0].z  : 0.0f;
    debugArray[index].w                = mask ? forceTorqueEnergy[0].w  : 0.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
171
172


173
    index                             += cSim.paddedNumberOfAtoms;
Mark Friedrichs's avatar
Mark Friedrichs committed
174
175
176
    debugArray[index].x                = mask ? forceTorqueEnergy[1].x : 0.0f;
    debugArray[index].y                = mask ? forceTorqueEnergy[1].y : 0.0f;
    debugArray[index].z                = mask ? forceTorqueEnergy[1].z : 0.0f;
177
    float offsetF                      = (float)(3*(x + tgx + (x >> GRIDBITS) * cSim.paddedNumberOfAtoms));
Mark Friedrichs's avatar
Mark Friedrichs committed
178
    debugArray[index].w                = offsetF;
Mark Friedrichs's avatar
Mark Friedrichs committed
179

180
    index                             += cSim.paddedNumberOfAtoms;
Mark Friedrichs's avatar
Mark Friedrichs committed
181
182
183
184
    debugArray[index].x                = mask ? forceTorqueEnergy[2].x : 0.0f;
    debugArray[index].y                = mask ? forceTorqueEnergy[2].y : 0.0f;
    debugArray[index].z                = mask ? forceTorqueEnergy[2].z : 0.0f;
    debugArray[index].w                = offsetF;
Mark Friedrichs's avatar
Mark Friedrichs committed
185

186
    for( int pullIndex = 0; pullIndex < maxPullIndex; pullIndex++ ){
187
        index                             += cSim.paddedNumberOfAtoms;
Mark Friedrichs's avatar
Mark Friedrichs committed
188
189
190
191
192
        debugArray[index].x                = pullBack[pullIndex].x;
        debugArray[index].y                = pullBack[pullIndex].y;
        debugArray[index].z                = pullBack[pullIndex].z;
        debugArray[index].w                = pullBack[pullIndex].w;
    }
193
194
195
}
#endif

Mark Friedrichs's avatar
Mark Friedrichs committed
196
            } // end of j-loop
197

Mark Friedrichs's avatar
Mark Friedrichs committed
198
199
            // include self energy and self torque

200
            if( atomI < cSim.atoms ){
Mark Friedrichs's avatar
Mark Friedrichs committed
201
                calculatePmeSelfTorqueElectrostaticPairIxn_kernel( localParticle );
Mark Friedrichs's avatar
Mark Friedrichs committed
202
203
204
                float energy;
                calculatePmeSelfEnergyElectrostaticPairIxn_kernel( localParticle, &energy );
                totalEnergy += energy;
Mark Friedrichs's avatar
Mark Friedrichs committed
205
206
            }

Mark Friedrichs's avatar
Mark Friedrichs committed
207
208
209
210
211
212
213
214
            localParticle.force[0]  *= conversionFactor;
            localParticle.force[1]  *= conversionFactor;
            localParticle.force[2]  *= conversionFactor;

            localParticle.torque[0] *= -conversionFactor;
            localParticle.torque[1] *= -conversionFactor;
            localParticle.torque[2] *= -conversionFactor;

215
216
217
            // Write results

#ifdef USE_OUTPUT_BUFFER_PER_WARP
218
219
220
            unsigned int offset                 = (x + tgx + warp*cSim.paddedNumberOfAtoms);
            add3dArrayToFloat4( offset, localParticle.force, cSim.pForce4 );
            add3dArray( 3*offset, localParticle.torque, outputTorque );
221
#else
222
223
224
            unsigned int offset                 = (x + tgx + (x >> GRIDBITS) * cSim.paddedNumberOfAtoms);
            add3dArrayToFloat4( offset, localParticle.force, cSim.pForce4 );
            load3dArray( 3*offset, localParticle.torque, outputTorque );
225
226
#endif

Mark Friedrichs's avatar
Mark Friedrichs committed
227
        } else {
228

Mark Friedrichs's avatar
Mark Friedrichs committed
229
230
231
232
233
234
235
236
            if (lasty != y) {

                // load shared data

               loadPmeDirectElectrostaticShared( &(sA[threadIdx.x]), (y+tgx) );

            }

Mark Friedrichs's avatar
Mark Friedrichs committed
237
238
239
240
            unsigned int flags           = cSim.pInteractionFlag[pos];
            if (flags == 0) {
                // No interactions in this block.
            } else {
241

Mark Friedrichs's avatar
Mark Friedrichs committed
242
243
244
245
246
247
248
249
250
251
252
253
                sA[threadIdx.x].force[0]     = 0.0f;
                sA[threadIdx.x].force[1]     = 0.0f;
                sA[threadIdx.x].force[2]     = 0.0f;
    
                sA[threadIdx.x].torque[0]    = 0.0f;
                sA[threadIdx.x].torque[1]    = 0.0f;
                sA[threadIdx.x].torque[2]    = 0.0f;
    
                if( bExclusionFlag )
                {
                    unsigned int xi   = x >> GRIDBITS;
                    unsigned int yi   = y >> GRIDBITS;
254
                    unsigned int cell = xi+yi*cSim.paddedNumberOfAtoms/GRID-yi*(yi+1)/2;
Mark Friedrichs's avatar
Mark Friedrichs committed
255
256
257
258
259
260
261
                    dScaleMask        = cAmoebaSim.pD_ScaleIndices[cAmoebaSim.pScaleIndicesIndex[cell]+tgx];
                    pScaleMask        = cAmoebaSim.pP_ScaleIndices[cAmoebaSim.pScaleIndicesIndex[cell]+tgx];
                    mScaleMask        = cAmoebaSim.pM_ScaleIndices[cAmoebaSim.pScaleIndicesIndex[cell]+tgx];
                } else {
                    scalingFactors[DScaleIndex] = scalingFactors[PScaleIndex] = scalingFactors[MScaleIndex] = 1.0f;
                }
       
262
263
                for (unsigned int j = 0; j < GRID; j++)
                {
Mark Friedrichs's avatar
Mark Friedrichs committed
264
                    if( (flags & (1<<j) ) != 0)
Mark Friedrichs's avatar
Mark Friedrichs committed
265
                    {
Peter Eastman's avatar
Peter Eastman committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
                        unsigned int jIdx  = (flags == 0xFFFFFFFF) ? tj : j;
                        unsigned int atomJ = y + jIdx;

                        // set scale factors

                        if( bExclusionFlag )
                        {
                            getMaskedDScaleFactor( jIdx, dScaleMask, scalingFactors + DScaleIndex );
                            getMaskedPScaleFactor( jIdx, pScaleMask, scalingFactors + PScaleIndex );
                            getMaskedMScaleFactor( jIdx, mScaleMask, scalingFactors + MScaleIndex );
                        }

                        // force

Mark Friedrichs's avatar
Mark Friedrichs committed
280
281
                        calculatePmeDirectElectrostaticPairIxn_kernel( localParticle, psA[jIdx],
                                                                       scalingFactors, forceTorqueEnergy
282
#ifdef AMOEBA_DEBUG
Mark Friedrichs's avatar
Mark Friedrichs committed
283
    , pullBack
284
#endif
Peter Eastman's avatar
Peter Eastman committed
285
         );
286

Peter Eastman's avatar
Peter Eastman committed
287
                        // check if atoms out-of-bounds
288

289
                        if( (atomI < cSim.atoms) && (atomJ < cSim.atoms) )
Mark Friedrichs's avatar
Mark Friedrichs committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
                        {
                            // add force and torque to atom I due atom J
    
                            localParticle.force[0]         += forceTorqueEnergy[0].x;
                            localParticle.force[1]         += forceTorqueEnergy[0].y;
                            localParticle.force[2]         += forceTorqueEnergy[0].z;
    
                            totalEnergy                    += forceTorqueEnergy[0].w;
    
                            localParticle.torque[0]        += forceTorqueEnergy[1].x;
                            localParticle.torque[1]        += forceTorqueEnergy[1].y;
                            localParticle.torque[2]        += forceTorqueEnergy[1].z;
    
                            // add force and torque to atom J due atom I
    
                            if( flags == 0xFFFFFFFF ){
    
                                psA[jIdx].force[0]         -= forceTorqueEnergy[0].x;
                                psA[jIdx].force[1]         -= forceTorqueEnergy[0].y;
                                psA[jIdx].force[2]         -= forceTorqueEnergy[0].z;
    
                                psA[jIdx].torque[0]        += forceTorqueEnergy[2].x;
                                psA[jIdx].torque[1]        += forceTorqueEnergy[2].y;
                                psA[jIdx].torque[2]        += forceTorqueEnergy[2].z;
    
                            } else {
    
                                sA[threadIdx.x].tempForce[0]  = forceTorqueEnergy[0].x;
Mark Friedrichs's avatar
Mark Friedrichs committed
318
319
                                sA[threadIdx.x].tempForce[1]  = forceTorqueEnergy[0].y;
                                sA[threadIdx.x].tempForce[2]  = forceTorqueEnergy[0].z;
Mark Friedrichs's avatar
Mark Friedrichs committed
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
    
                                sA[threadIdx.x].tempTorque[0] = forceTorqueEnergy[2].x;
                                sA[threadIdx.x].tempTorque[1] = forceTorqueEnergy[2].y;
                                sA[threadIdx.x].tempTorque[2] = forceTorqueEnergy[2].z;
    
                                if( tgx % 2 == 0 ){
                                    sumTempBuffer( sA[threadIdx.x], sA[threadIdx.x+1] );
                                }
                                if( tgx % 4 == 0 ){
                                    sumTempBuffer( sA[threadIdx.x], sA[threadIdx.x+2] );
                                }
                                if( tgx % 8 == 0 ){
                                    sumTempBuffer( sA[threadIdx.x], sA[threadIdx.x+4] );
                                }
                                if( tgx % 16 == 0 ){
                                    sumTempBuffer( sA[threadIdx.x], sA[threadIdx.x+8] );
                                }
    
                                if (tgx == 0)
                                {
                                    psA[jIdx].force[0]  -= sA[threadIdx.x].tempForce[0]  + sA[threadIdx.x+16].tempForce[0];
                                    psA[jIdx].force[1]  -= sA[threadIdx.x].tempForce[1]  + sA[threadIdx.x+16].tempForce[1];
                                    psA[jIdx].force[2]  -= sA[threadIdx.x].tempForce[2]  + sA[threadIdx.x+16].tempForce[2];
    
                                    psA[jIdx].torque[0] += sA[threadIdx.x].tempTorque[0] + sA[threadIdx.x+16].tempTorque[0];
                                    psA[jIdx].torque[1] += sA[threadIdx.x].tempTorque[1] + sA[threadIdx.x+16].tempTorque[1];
                                    psA[jIdx].torque[2] += sA[threadIdx.x].tempTorque[2] + sA[threadIdx.x+16].tempTorque[2];
                                }
                            }
                        } // end of atoms out-of-bounds
                    } // end of flags&(1<<j block
 
#ifdef AMOEBA_DEBUG
unsigned int jIdx  = (flags == 0xFFFFFFFF) ? tj : j;
unsigned int atomJ = y + jIdx;
355
unsigned int mask  =  ( (atomI >= cSim.atoms) || (atomJ >= cSim.atoms) ) ? 0 : 1;
Mark Friedrichs's avatar
Mark Friedrichs committed
356
357
if( atomI == targetAtom || atomJ == targetAtom ){
    unsigned int index                 = (atomI == targetAtom) ? atomJ : atomI;
Peter Eastman's avatar
Peter Eastman committed
358

Mark Friedrichs's avatar
Mark Friedrichs committed
359
360
361
362
    debugArray[index].x                = (float) atomI;
    debugArray[index].y                = (float) atomJ;
    debugArray[index].z                = (float) y;
    debugArray[index].w                = (flags == 0xFFFFFFFF) ? (float) -141.0f : -151.0f;
Peter Eastman's avatar
Peter Eastman committed
363

364
    index                             += cSim.paddedNumberOfAtoms;
Mark Friedrichs's avatar
Mark Friedrichs committed
365
366
367
368
    debugArray[index].x                = mask ? forceTorqueEnergy[0].x  : 0.0f;
    debugArray[index].y                = mask ? forceTorqueEnergy[0].y  : 0.0f;
    debugArray[index].z                = mask ? forceTorqueEnergy[0].z  : 0.0f;
    debugArray[index].w                = mask ? forceTorqueEnergy[0].w  : 0.0f;
Peter Eastman's avatar
Peter Eastman committed
369
370


371
    index                             += cSim.paddedNumberOfAtoms;
Mark Friedrichs's avatar
Mark Friedrichs committed
372
373
374
    debugArray[index].x                = mask ? forceTorqueEnergy[1].x : 0.0f;
    debugArray[index].y                = mask ? forceTorqueEnergy[1].y : 0.0f;
    debugArray[index].z                = mask ? forceTorqueEnergy[1].z : 0.0f;
375
    float offsetF                      = (float)(3*(y + tgx + (x >> GRIDBITS) * cSim.paddedNumberOfAtoms));
Mark Friedrichs's avatar
Mark Friedrichs committed
376
    debugArray[index].w                = offsetF;
Peter Eastman's avatar
Peter Eastman committed
377

378
    index                             += cSim.paddedNumberOfAtoms;
Mark Friedrichs's avatar
Mark Friedrichs committed
379
380
381
    debugArray[index].x                = mask ? forceTorqueEnergy[2].x : 0.0f;
    debugArray[index].y                = mask ? forceTorqueEnergy[2].y : 0.0f;
    debugArray[index].z                = mask ? forceTorqueEnergy[2].z : 0.0f;
382
    offsetF                            = (float) (3*(x + tgx + (y >> GRIDBITS) * cSim.paddedNumberOfAtoms));
Mark Friedrichs's avatar
Mark Friedrichs committed
383
    debugArray[index].w                = offsetF;
Mark Friedrichs's avatar
Mark Friedrichs committed
384

Mark Friedrichs's avatar
Mark Friedrichs committed
385
    for( int pullIndex = 0; pullIndex < maxPullIndex; pullIndex++ ){
386
        index                             += cSim.paddedNumberOfAtoms;
Mark Friedrichs's avatar
Mark Friedrichs committed
387
388
389
390
391
392
393
        debugArray[index].x                = pullBack[pullIndex].x;
        debugArray[index].y                = pullBack[pullIndex].y;
        debugArray[index].z                = pullBack[pullIndex].z;
        debugArray[index].w                = pullBack[pullIndex].w;
    }
}
#endif
Mark Friedrichs's avatar
Mark Friedrichs committed
394
                    tj = (tj + 1) & (GRID - 1);
395

Mark Friedrichs's avatar
Mark Friedrichs committed
396
                } // end of j-loop
397

Mark Friedrichs's avatar
Mark Friedrichs committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
                localParticle.force[0]    *=  conversionFactor;
                localParticle.force[1]    *=  conversionFactor;
                localParticle.force[2]    *=  conversionFactor;
    
                localParticle.torque[0]   *= -conversionFactor;
                localParticle.torque[1]   *= -conversionFactor;
                localParticle.torque[2]   *= -conversionFactor;
    
                sA[threadIdx.x].force[0]  *=  conversionFactor;
                sA[threadIdx.x].force[1]  *=  conversionFactor;
                sA[threadIdx.x].force[2]  *=  conversionFactor;
    
                sA[threadIdx.x].torque[0] *= -conversionFactor;
                sA[threadIdx.x].torque[1] *= -conversionFactor;
                sA[threadIdx.x].torque[2] *= -conversionFactor;
    
Mark Friedrichs's avatar
Mark Friedrichs committed
414
415
                // Write results
    
Mark Friedrichs's avatar
Mark Friedrichs committed
416
#ifdef USE_OUTPUT_BUFFER_PER_WARP
Mark Friedrichs's avatar
Mark Friedrichs committed
417
    
418
419
420
                unsigned int offset                 = (x + tgx + warp*cSim.paddedNumberOfAtoms);
                add3dArrayToFloat4( offset, localParticle.force,  cSim.pForce4 );
                add3dArray(       3*offset, localParticle.torque, outputTorque );
Mark Friedrichs's avatar
Mark Friedrichs committed
421
    
422
423
424
                offset                              = (y + tgx + warp*cSim.paddedNumberOfAtoms);
                add3dArrayToFloat4( offset, sA[threadIdx.x].force,  cSim.pForce4 );
                add3dArray(       3*offset, sA[threadIdx.x].torque, outputTorque );
Mark Friedrichs's avatar
Mark Friedrichs committed
425
    
Mark Friedrichs's avatar
Mark Friedrichs committed
426
#else
427
428
429
                unsigned int offset                 = (x + tgx + (y >> GRIDBITS) * cSim.paddedNumberOfAtoms);
                add3dArrayToFloat4( offset, localParticle.force,  cSim.pForce4 );
                load3dArray(       3*offset, localParticle.torque, outputTorque );
Mark Friedrichs's avatar
Mark Friedrichs committed
430
    
431
                offset                              = (y + tgx + (x >> GRIDBITS) * cSim.paddedNumberOfAtoms);
Mark Friedrichs's avatar
Mark Friedrichs committed
432
    
433
434
                add3dArrayToFloat4( offset, sA[threadIdx.x].force,  cSim.pForce4 );
                load3dArray(       3*offset, sA[threadIdx.x].torque, outputTorque );
Mark Friedrichs's avatar
Mark Friedrichs committed
435
    
Mark Friedrichs's avatar
Mark Friedrichs committed
436
#endif
Mark Friedrichs's avatar
Mark Friedrichs committed
437
                lasty = y;
438

Mark Friedrichs's avatar
Mark Friedrichs committed
439
            } // end of pInteractionFlag block
440
441
442
        }
        pos++;
    }
Mark Friedrichs's avatar
Mark Friedrichs committed
443
    cSim.pEnergy[blockIdx.x * blockDim.x + threadIdx.x] -= conversionFactor*totalEnergy;
444
}