Commit cb599d67 authored by Peter Eastman's avatar Peter Eastman
Browse files

Ensure neighbor list is large enough on first step

parent 300566f3
...@@ -142,8 +142,10 @@ public: ...@@ -142,8 +142,10 @@ public:
void computeInteractions(int forceGroups); void computeInteractions(int forceGroups);
/** /**
* Check to see if the neighbor list arrays are large enough, and make them bigger if necessary. * Check to see if the neighbor list arrays are large enough, and make them bigger if necessary.
*
* @return true if the neighbor list needed to be enlarged.
*/ */
void updateNeighborListSize(); bool updateNeighborListSize();
/** /**
* Get the array containing the center of each atom block. * Get the array containing the center of each atom block.
*/ */
......
...@@ -375,11 +375,16 @@ void CudaNonbondedUtilities::prepareInteractions(int forceGroups) { ...@@ -375,11 +375,16 @@ void CudaNonbondedUtilities::prepareInteractions(int forceGroups) {
if (lastCutoff != kernels.cutoffDistance) if (lastCutoff != kernels.cutoffDistance)
forceRebuildNeighborList = true; forceRebuildNeighborList = true;
context.executeKernel(kernels.findBlockBoundsKernel, &findBlockBoundsArgs[0], context.getNumAtoms()); bool rebuild = false;
blockSorter->sort(*sortedBlocks); do {
context.executeKernel(kernels.sortBoxDataKernel, &sortBoxDataArgs[0], context.getNumAtoms()); context.executeKernel(kernels.findBlockBoundsKernel, &findBlockBoundsArgs[0], context.getNumAtoms());
context.executeKernel(kernels.findInteractingBlocksKernel, &findInteractingBlocksArgs[0], context.getNumAtoms(), 256); blockSorter->sort(*sortedBlocks);
forceRebuildNeighborList = false; context.executeKernel(kernels.sortBoxDataKernel, &sortBoxDataArgs[0], context.getNumAtoms());
context.executeKernel(kernels.findInteractingBlocksKernel, &findInteractingBlocksArgs[0], context.getNumAtoms(), 256);
forceRebuildNeighborList = false;
if (context.getComputeForceCount() == 1)
rebuild = updateNeighborListSize(); // This is the first time step, so check whether our initial guess was large enough.
} while(rebuild);
lastCutoff = kernels.cutoffDistance; lastCutoff = kernels.cutoffDistance;
} }
...@@ -389,18 +394,16 @@ void CudaNonbondedUtilities::computeInteractions(int forceGroups) { ...@@ -389,18 +394,16 @@ void CudaNonbondedUtilities::computeInteractions(int forceGroups) {
KernelSet& kernels = groupKernels[forceGroups]; KernelSet& kernels = groupKernels[forceGroups];
if (kernels.hasForces) { if (kernels.hasForces) {
context.executeKernel(kernels.forceKernel, &forceArgs[0], numForceThreadBlocks*forceThreadBlockSize, forceThreadBlockSize); context.executeKernel(kernels.forceKernel, &forceArgs[0], numForceThreadBlocks*forceThreadBlockSize, forceThreadBlockSize);
if (context.getComputeForceCount() == 1)
updateNeighborListSize(); // This is the first time step, so check whether our initial guess was large enough.
} }
} }
void CudaNonbondedUtilities::updateNeighborListSize() { bool CudaNonbondedUtilities::updateNeighborListSize() {
if (!useCutoff) if (!useCutoff)
return; return false;
unsigned int* pinnedInteractionCount = (unsigned int*) context.getPinnedBuffer(); unsigned int* pinnedInteractionCount = (unsigned int*) context.getPinnedBuffer();
interactionCount->download(pinnedInteractionCount); interactionCount->download(pinnedInteractionCount);
if (pinnedInteractionCount[0] <= (unsigned int) maxTiles) if (pinnedInteractionCount[0] <= (unsigned int) maxTiles)
return; return false;
// The most recent timestep had too many interactions to fit in the arrays. Make the arrays bigger to prevent // The most recent timestep had too many interactions to fit in the arrays. Make the arrays bigger to prevent
// this from happening in the future. // this from happening in the future.
...@@ -422,6 +425,7 @@ void CudaNonbondedUtilities::updateNeighborListSize() { ...@@ -422,6 +425,7 @@ void CudaNonbondedUtilities::updateNeighborListSize() {
forceArgs[17] = &interactingAtoms->getDevicePointer(); forceArgs[17] = &interactingAtoms->getDevicePointer();
findInteractingBlocksArgs[7] = &interactingAtoms->getDevicePointer(); findInteractingBlocksArgs[7] = &interactingAtoms->getDevicePointer();
forceRebuildNeighborList = true; forceRebuildNeighborList = true;
return true;
} }
void CudaNonbondedUtilities::setUsePadding(bool padding) { void CudaNonbondedUtilities::setUsePadding(bool padding) {
......
...@@ -154,8 +154,10 @@ public: ...@@ -154,8 +154,10 @@ public:
void computeInteractions(int forceGroups); void computeInteractions(int forceGroups);
/** /**
* Check to see if the neighbor list arrays are large enough, and make them bigger if necessary. * Check to see if the neighbor list arrays are large enough, and make them bigger if necessary.
*
* @return true if the neighbor list needed to be enlarged.
*/ */
void updateNeighborListSize(); bool updateNeighborListSize();
/** /**
* Get the array containing the center of each atom block. * Get the array containing the center of each atom block.
*/ */
......
...@@ -341,14 +341,19 @@ void OpenCLNonbondedUtilities::prepareInteractions(int forceGroups) { ...@@ -341,14 +341,19 @@ void OpenCLNonbondedUtilities::prepareInteractions(int forceGroups) {
if (lastCutoff != kernels.cutoffDistance) if (lastCutoff != kernels.cutoffDistance)
forceRebuildNeighborList = true; forceRebuildNeighborList = true;
setPeriodicBoxArgs(context, kernels.findBlockBoundsKernel, 1); bool rebuild = false;
context.executeKernel(kernels.findBlockBoundsKernel, context.getNumAtoms()); do {
blockSorter->sort(*sortedBlocks); setPeriodicBoxArgs(context, kernels.findBlockBoundsKernel, 1);
kernels.sortBoxDataKernel.setArg<cl_int>(9, forceRebuildNeighborList); context.executeKernel(kernels.findBlockBoundsKernel, context.getNumAtoms());
context.executeKernel(kernels.sortBoxDataKernel, context.getNumAtoms()); blockSorter->sort(*sortedBlocks);
setPeriodicBoxArgs(context, kernels.findInteractingBlocksKernel, 0); kernels.sortBoxDataKernel.setArg<cl_int>(9, forceRebuildNeighborList);
context.executeKernel(kernels.findInteractingBlocksKernel, context.getNumAtoms(), interactingBlocksThreadBlockSize); context.executeKernel(kernels.sortBoxDataKernel, context.getNumAtoms());
forceRebuildNeighborList = false; setPeriodicBoxArgs(context, kernels.findInteractingBlocksKernel, 0);
context.executeKernel(kernels.findInteractingBlocksKernel, context.getNumAtoms(), interactingBlocksThreadBlockSize);
forceRebuildNeighborList = false;
if (context.getComputeForceCount() == 1)
rebuild = updateNeighborListSize(); // This is the first time step, so check whether our initial guess was large enough.
} while (rebuild);
lastCutoff = kernels.cutoffDistance; lastCutoff = kernels.cutoffDistance;
} }
...@@ -360,18 +365,16 @@ void OpenCLNonbondedUtilities::computeInteractions(int forceGroups) { ...@@ -360,18 +365,16 @@ void OpenCLNonbondedUtilities::computeInteractions(int forceGroups) {
if (useCutoff) if (useCutoff)
setPeriodicBoxArgs(context, kernels.forceKernel, 9); setPeriodicBoxArgs(context, kernels.forceKernel, 9);
context.executeKernel(kernels.forceKernel, numForceThreadBlocks*forceThreadBlockSize, forceThreadBlockSize); context.executeKernel(kernels.forceKernel, numForceThreadBlocks*forceThreadBlockSize, forceThreadBlockSize);
if (context.getComputeForceCount() == 1)
updateNeighborListSize(); // This is the first time step, so check whether our initial guess was large enough.
} }
} }
void OpenCLNonbondedUtilities::updateNeighborListSize() { bool OpenCLNonbondedUtilities::updateNeighborListSize() {
if (!useCutoff) if (!useCutoff)
return; return false;
unsigned int* pinnedInteractionCount = (unsigned int*) context.getPinnedBuffer(); unsigned int* pinnedInteractionCount = (unsigned int*) context.getPinnedBuffer();
interactionCount->download(pinnedInteractionCount); interactionCount->download(pinnedInteractionCount);
if (pinnedInteractionCount[0] <= (unsigned int) interactingTiles->getSize()) if (pinnedInteractionCount[0] <= (unsigned int) interactingTiles->getSize())
return; return false;
// The most recent timestep had too many interactions to fit in the arrays. Make the arrays bigger to prevent // The most recent timestep had too many interactions to fit in the arrays. Make the arrays bigger to prevent
// this from happening in the future. // this from happening in the future.
...@@ -395,6 +398,7 @@ void OpenCLNonbondedUtilities::updateNeighborListSize() { ...@@ -395,6 +398,7 @@ void OpenCLNonbondedUtilities::updateNeighborListSize() {
iter->second.findInteractingBlocksKernel.setArg<cl_uint>(9, maxTiles); iter->second.findInteractingBlocksKernel.setArg<cl_uint>(9, maxTiles);
} }
forceRebuildNeighborList = true; forceRebuildNeighborList = true;
return true;
} }
void OpenCLNonbondedUtilities::setUsePadding(bool padding) { void OpenCLNonbondedUtilities::setUsePadding(bool padding) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment