llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.61k stars 11.82k forks source link

[OpenMP] atomic operation does not work properly on Windows with clang #64694

Open annop-w opened 1 year ago

annop-w commented 1 year ago

The following program produces wrong result with -O3

#include <iostream>
#include <omp.h>
int main () {
        double sum = 0.0;
        int i;
#pragma omp parallel for default(none) private(i) shared(sum)
        for (i = 0; i < 1000; ++i) {
                #pragma omp atomic
                sum += 1.0;
        } 
        std::cout << sum << std::endl;
        return 0;
}
clang version 16.0.0
Target: aarch64-pc-windows-msvc
Thread model: posix
llvmbot commented 1 year ago

@llvm/issue-subscribers-openmp

shiltian commented 1 year ago

This might be related to #64693. Can you show how you build LLVM and OpenMP?

annop-w commented 1 year ago

Here is the cmake line I used for building the compiler

cmake -GNinja -DLLVM_ENABLE_PROJECTS="clang;flang;mlir"  -DLLVM_ENABLE_RUNTIMES="openmp"  -DLLVM_TARGETS_TO_BUILD="AArch64"    -DCMAKE_C_FLAGS="-fms-compatibility-version=19.27"    -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.27"    -DCMAKE_EXE_LINKER_FLAGS="$builtins_path/$builtins_lib"    -DCMAKE_SHARED_LINKER_FLAGS="$builtins_path/$builtins_lib"    -DCMAKE_STATIC_LINKER_FLAGS="$builtins_path/$builtins_lib"  -DCMAKE_TRY_COMPILE_CONFIGURATION=Release    -DCMAKE_BUILD_TYPE=Release    -DLLVM_ENABLE_ASSERTIONS=ON    -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON    -DLLVM_BUILD_LLVM_C_DYLIB=ON    -DCMAKE_INSTALL_UCRT_LIBRARIES=ON    -DCMAKE_CL_SHOWINCLUDES_PREFIX='Note: including file: '    -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-pc-windows-msvc    -DLLVM_HOST_TRIPLE=aarch64-pc-windows-msvc    -DLLVM_TARGET_ARCH=AArch64    -DCMAKE_INSTALL_PREFIX=$install_dir    -DCLANG_DEFAULT_LINKER=lld  -DLLVM_USE_CRT_RELEASE=MT ../llvm-project/llvm

This is based on these instructions https://www.linaro.org/blog/how-to-set-up-windows-on-arm-for-llvm-development/ from Linaro. I'm building the commit f2b241474f. Running with OMP_NUM_THREADS=32 prints 942 as the result, for example.

shiltian commented 1 year ago

So is it an ARM based Windows?

annop-w commented 1 year ago

So is it an ARM based Windows?

Yes.

shiltian commented 1 year ago

Okay. I'll have to get Parallels Desktop on my Mac. Let me see what I can do.