ls1mardyn / ls1-mardyn

ls1-MarDyn is a massively parallel Molecular Dynamics (MD) code for large systems. Its main target is the simulation of thermodynamics and nanofluidics. ls1-MarDyn is designed with a focus on performance and easy extensibility.
http://www.ls1-mardyn.de
Other
28 stars 15 forks source link

The use of testcube-dense-fs results in a std::out_of_range error. #304

Open GuoYongFa opened 5 months ago

GuoYongFa commented 5 months ago

When running with the configuration file "examples/force-exchange/testcube-dense-fs.xml", I encountered an index out-of-bounds issue. Below, I've added comments hypothesizing the potential cause of this error, though I admit my usage is limited and I'm not entirely sure if my speculation is correct. My operating system is Ubuntu 22.04, with gcc version 11.4.0.

if (currentCell.isBoundaryCell()) {
        cellProcessor.processCell(currentCell);
        // loop over all forward neighbours
        for (auto& neighbourOffset : this->_forwardNeighbourOffsets) {
            CellTemplate& neighbourCell = this->_cells->at(cellIndex + neighbourOffset);    // Exceeding the maximum index of an array 
            cellProcessor.processCellPair(currentCell, neighbourCell);
        }
        // loop over all backward neighbours. calculate only forces
        // to neighbour cells in the halo region, all others already have been calculated
        for (auto& neighbourOffset : this->_backwardNeighbourOffsets) {
            CellTemplate& neighbourCell = this->_cells->at(cellIndex - neighbourOffset);   // The value of cellindex might be less than neighbourOffset, leading to an overflow.
            if (neighbourCell.isHaloCell()) {
                cellProcessor.processCellPair(currentCell, neighbourCell);
            }
        }
    } // if ( isBoundaryCell() )
HomesGH commented 4 months ago

I think that the problem is here: this->_cells->at(cellIndex - neighbourOffset) This can lead to "negative" (-> overflowed) results. Unfortunately, I am not really into this part of the code and I am not sure if this traversal is still in use at all.