NeighborhoodGraph share std::mt19937 among different threads
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 5k
- Forks
- 622
- Avg merge
- 8h 37m
- Merged PRs (30d)
- 5
Description
Describe the bug
In https://github.com/microsoft/SPTAG/blob/main/AnnService/inc/Core/Common/NeighborhoodGraph.h#L320
#pragma omp parallel for schedule(dynamic)
for (int i = 0; i < m_iTPTNumber; i++)
{
Sleep(i * 100); std::srand(clock());
for (SizeType j = 0; j < m_iGraphSize; j++) TptreeDataIndices[i][j] = j;
std::shuffle(TptreeDataIndices[i].begin(), TptreeDataIndices[i].end(), rg);
PartitionByTptree<T>(index, TptreeDataIndices[i], 0, m_iGraphSize - 1, TptreeLeafNodes[i]);
SPTAGLIB_LOG(Helper::LogLevel::LL_Info, "Finish Getting Leaves for Tree %d\n", i);
}
The rg is a global variable that shares between threads, which may cause a array out of index in std::shuffle() since the rg may generate an index that exceed the size of TptreeDataIndices[i]. That index will be used in std::shuffle to swap items so the out of range error happens.
To Reproduce
I don't know the exact way to reproduce this, I find it by trying to build index on SIFT100M Dataset.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in AnnService/inc/Core/Common/NeighborhoodGraph.h around line 320 and inspect how the shared rg is declared and used inside the OpenMP loop. Build the index against the SIFT100M dataset if available, then verify that parallel shuffling no longer produces invalid accesses or failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100