From a3b5ceab38fabb725963e594708597706c69c102 Mon Sep 17 00:00:00 2001 From: Haoran Du Date: Sun, 7 Jun 2026 12:16:11 +0800 Subject: [PATCH] Fix Windows OpenMP wheel build --- .github/workflows/wheel_publish.yml | 2 -- cpp_easygraph/functions/community/louvain.cpp | 6 +++--- cpp_easygraph/functions/community/modularity.cpp | 11 ++++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/wheel_publish.yml b/.github/workflows/wheel_publish.yml index cd39669c..2065873f 100644 --- a/.github/workflows/wheel_publish.yml +++ b/.github/workflows/wheel_publish.yml @@ -45,7 +45,6 @@ jobs: uses: pypa/cibuildwheel@v2.23.3 with: output-dir: dist/ - merge-multiple: true - name: Upload wheels uses: actions/upload-artifact@v4 @@ -74,4 +73,3 @@ jobs: password: ${{ secrets.PYPI_API_TOKEN }} skip-existing: true - diff --git a/cpp_easygraph/functions/community/louvain.cpp b/cpp_easygraph/functions/community/louvain.cpp index d73137d6..bff5625a 100644 --- a/cpp_easygraph/functions/community/louvain.cpp +++ b/cpp_easygraph/functions/community/louvain.cpp @@ -312,10 +312,10 @@ double modularity_optimization_parallel_simplified(const Graph_L& G, vector } if (best_comm != old_comm) { - #pragma omp atomic update + #pragma omp atomic comm_weights[old_comm] -= weight_all; - #pragma omp atomic update + #pragma omp atomic comm_weights[best_comm] += weight_all; membership[u - 1] = best_comm; @@ -541,4 +541,4 @@ py::object cpp_louvain_communities(py::object G, py::object weight, py::object t } return final_result; -} \ No newline at end of file +} diff --git a/cpp_easygraph/functions/community/modularity.cpp b/cpp_easygraph/functions/community/modularity.cpp index e83d3ac1..e822b02e 100644 --- a/cpp_easygraph/functions/community/modularity.cpp +++ b/cpp_easygraph/functions/community/modularity.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #ifdef _OPENMP #include #else @@ -18,8 +19,10 @@ void addVectorsInPlace(std::vector& v1, std::vector& v2) { throw std::invalid_argument("Vectors must have the same size for element-wise addition."); } + const std::ptrdiff_t n = static_cast(v1.size()); + #pragma omp parallel for - for (size_t i = 0; i < v1.size(); ++i) { + for (std::ptrdiff_t i = 0; i < n; ++i) { double sum = v1[i] + v2[i]; v1[i] = sum; v2[i] = sum; @@ -32,8 +35,10 @@ double dotProduct(const std::vector& v1, const std::vector& v2) } double result = 0.0; + const std::ptrdiff_t n = static_cast(v1.size()); + #pragma omp parallel for reduction(+:result) - for (size_t i = 0; i < v1.size(); ++i) { + for (std::ptrdiff_t i = 0; i < n; ++i) { result += v1[i] * v2[i]; } return result; @@ -205,4 +210,4 @@ py::object cpp_modularity(py::object G, py::object communities, py::object weigh double Q = e - sum_products; return py::float_(Q); -} \ No newline at end of file +}