Skip to content

Commit bbc95b1

Browse files
wx257osn2facebook-github-bot
authored andcommitted
Fix windows CI (facebookresearch#2889)
Summary: facebookresearch#2882 added [a for loop, which has unsigned index, qualified with `#pragma omp parallel for`](https://github.com/facebookresearch/faiss/pull/2882/files#diff-5a89dcb99a1cce3f297c7f7dfc8e221306b281d4ced6dac1e0fc0fa54188195fR449-R452), but it seems that [MSVC doesn't support unsigned index with `#pragma omp parallel for`](https://app.circleci.com/pipelines/github/facebookresearch/faiss/4220/workflows/ee72de05-6ead-42d9-8ec5-44772e9fd41b/jobs/22529?invite=true#step-104-333) (I think this would not be conformed to OpenMP specification, but...) I (finally) change the loop with signed index. This changes introduce the precondition `n <= std::numeric_limits<std::make_signed_t<std::size_t>>::max()` , but usually this is `true` I think, so I just put this limitation as a comment instead of any `FAISS_ASSERT` or something like that. Pull Request resolved: facebookresearch#2889 Reviewed By: wickedfoo Differential Revision: D46325322 Pulled By: alexanderguzhva fbshipit-source-id: c68f4c8be3db188ac067e053c6c716e2896f75c0
1 parent 90349f2 commit bbc95b1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

faiss/utils/utils.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <omp.h>
2929

3030
#include <algorithm>
31+
#include <type_traits>
3132
#include <vector>
3233

3334
#include <faiss/impl/AuxIndexStructures.h>
@@ -446,8 +447,13 @@ uint64_t bvec_checksum(size_t n, const uint8_t* a) {
446447
}
447448

448449
void bvecs_checksum(size_t n, size_t d, const uint8_t* a, uint64_t* cs) {
449-
#pragma omp parallel for if (n > 1000)
450-
for (size_t i = 0; i < n; i++) {
450+
// MSVC can't accept unsigned index for #pragma omp parallel for
451+
// so below codes only accept n <= std::numeric_limits<ssize_t>::max()
452+
using ssize_t = std::make_signed<std::size_t>::type;
453+
const ssize_t size = n;
454+
#pragma omp parallel for if (size > 1000)
455+
for (ssize_t i_ = 0; i_ < size; i_++) {
456+
const auto i = static_cast<std::size_t>(i_);
451457
cs[i] = bvec_checksum(d, a + i * d);
452458
}
453459
}

0 commit comments

Comments
 (0)