diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreams.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreams.cpp index f191c628dabbe9432c5930596e403a333c0593d4..63a518f7379c2007a4fdabf2a7a26ce83b529875 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreams.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreams.cpp @@ -103,10 +103,10 @@ std::vector<uint> IndexRearrangementForStreams::initSendIndicesForCommAfterFToCZ std::vector<uint> IndexRearrangementForStreams::exchangeIndicesForCommAfterFtoCX( uint level, int indexOfProcessNeighbor, std::vector<uint> &sendIndicesForCommAfterFtoCPositions) const { - // fill the receive vector with zeros as placeholders (0 is never a valid fluid node) + // fill the receive vector with zeros as placeholders (0 is not a valid fluid node) // give vector an arbitrary size (larger than needed) // TODO: Find a better way std::vector<uint> recvIndicesForCommAfterFtoCPositions( - (size_t)para->getParH(level)->sendProcessNeighborsAfterFtoCX[indexOfProcessNeighbor].numberOfNodes * 2, 0); + (size_t)para->getParH(level)->sendProcessNeighborsAfterFtoCY[indexOfProcessNeighbor].numberOfNodes * 2, 0); communicator.receive_send( recvIndicesForCommAfterFtoCPositions.data(), (int)recvIndicesForCommAfterFtoCPositions.size(), @@ -114,16 +114,23 @@ std::vector<uint> IndexRearrangementForStreams::exchangeIndicesForCommAfterFtoCX sendIndicesForCommAfterFtoCPositions.data(), (int)sendIndicesForCommAfterFtoCPositions.size(), para->getParH(level)->sendProcessNeighborX[indexOfProcessNeighbor].rankNeighbor); - // resize receiving vector to correct size (remove all zeros) - auto it = std::find(recvIndicesForCommAfterFtoCPositions.begin(), recvIndicesForCommAfterFtoCPositions.end(), 0); - recvIndicesForCommAfterFtoCPositions.erase(it, recvIndicesForCommAfterFtoCPositions.end()); + // resize receiving vector to correct size + if ((uint)recvIndicesForCommAfterFtoCPositions.size() > 0) { + auto it = std::unique( + recvIndicesForCommAfterFtoCPositions.begin(), + recvIndicesForCommAfterFtoCPositions.end()); // finds the second zero when there are multiple zeros in a row + recvIndicesForCommAfterFtoCPositions.erase( + std::prev(it, 1), // begin erasing at the first zero + recvIndicesForCommAfterFtoCPositions.end()); // TODO: Find a better way + } + return recvIndicesForCommAfterFtoCPositions; } std::vector<uint> IndexRearrangementForStreams::exchangeIndicesForCommAfterFtoCY( uint level, int indexOfProcessNeighbor, std::vector<uint> &sendIndicesForCommAfterFtoCPositions) const { - // fill the receive vector with zeros as placeholders (0 is never a valid fluid node) + // fill the receive vector with zeros as placeholders (0 is not a valid fluid node) // give vector an arbitrary size (larger than needed) // TODO: Find a better way std::vector<uint> recvIndicesForCommAfterFtoCPositions( (size_t)para->getParH(level)->sendProcessNeighborsAfterFtoCY[indexOfProcessNeighbor].numberOfNodes * 2, 0); @@ -134,16 +141,23 @@ std::vector<uint> IndexRearrangementForStreams::exchangeIndicesForCommAfterFtoCY sendIndicesForCommAfterFtoCPositions.data(), (int)sendIndicesForCommAfterFtoCPositions.size(), para->getParH(level)->sendProcessNeighborY[indexOfProcessNeighbor].rankNeighbor); - // resize receiving vector to correct size (remove all zeros) - auto it = std::find(recvIndicesForCommAfterFtoCPositions.begin(), recvIndicesForCommAfterFtoCPositions.end(), 0); - recvIndicesForCommAfterFtoCPositions.erase(it, recvIndicesForCommAfterFtoCPositions.end()); + // resize receiving vector to correct size + if ((uint)recvIndicesForCommAfterFtoCPositions.size() > 0) { + auto it = std::unique( + recvIndicesForCommAfterFtoCPositions.begin(), + recvIndicesForCommAfterFtoCPositions.end()); // finds the second zero when there are multiple zeros in a row + recvIndicesForCommAfterFtoCPositions.erase( + std::prev(it, 1), // begin erasing at the first zero + recvIndicesForCommAfterFtoCPositions.end()); // TODO: Find a better way + } + return recvIndicesForCommAfterFtoCPositions; } std::vector<uint> IndexRearrangementForStreams::exchangeIndicesForCommAfterFtoCZ( uint level, int indexOfProcessNeighbor, std::vector<uint> &sendIndicesForCommAfterFtoCPositions) const { - // fill the receive vector with zeros as placeholders (0 is never a valid fluid node) + // fill the receive vector with zeros as placeholders (0 is not a valid fluid node) // give vector an arbitrary size (larger than needed) // TODO: Find a better way std::vector<uint> recvIndicesForCommAfterFtoCPositions( (size_t)para->getParH(level)->sendProcessNeighborsAfterFtoCZ[indexOfProcessNeighbor].numberOfNodes * 2, 0); @@ -154,9 +168,16 @@ std::vector<uint> IndexRearrangementForStreams::exchangeIndicesForCommAfterFtoCZ sendIndicesForCommAfterFtoCPositions.data(), (int)sendIndicesForCommAfterFtoCPositions.size(), para->getParH(level)->sendProcessNeighborZ[indexOfProcessNeighbor].rankNeighbor); - // resize receiving vector to correct size (remove all zeros) - auto it = std::find(recvIndicesForCommAfterFtoCPositions.begin(), recvIndicesForCommAfterFtoCPositions.end(), 0); - recvIndicesForCommAfterFtoCPositions.erase(it, recvIndicesForCommAfterFtoCPositions.end()); + // resize receiving vector to correct size + if ((uint)recvIndicesForCommAfterFtoCPositions.size() > 0) { + auto it = std::unique( + recvIndicesForCommAfterFtoCPositions.begin(), + recvIndicesForCommAfterFtoCPositions.end()); // finds the second zero when there are multiple zeros in a row + recvIndicesForCommAfterFtoCPositions.erase( + std::prev(it, 1), // begin erasing at the first zero + recvIndicesForCommAfterFtoCPositions.end()); // TODO: Find a better way + } + return recvIndicesForCommAfterFtoCPositions; }