microsoft / microsoft/SPTAG

NeighborhoodGraph share std::mt19937 among different threads

Open
#428 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.