-
-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gcc 编译环境下xmake构建的openmp程序无法多线程运行 #2603
Comments
不用xmake run运行,直接输路径运行编译出来这个程序会有问题吗 |
也有这个问题 |
你可以通过 |
理论上可以用
|
我这里可以,你这应该是有包里用了 package:has_tool,取不到 toolname 导致,我加了个判空处理,不过要让 package 支持tool切换,不建议单独切,走 --toolchain=gcc 来切 |
为啥这跟 g++/gcc 还有区别? |
不是这个原因,我执行xmake clean -a之后再运行这些命令,发现gcc也可以,不需要改g++,问题可能出在内置的ccache实现。 |
我试了一下,把xmake -v显示的编译链接两条命令单独执行,程序可以正常运行,且和gcc/g++没关系。但是xmake构建的程序运行就不对。 |
那吧 ccache 关了试试,xmake f --ccache=n; xmake -r |
按照你说的关了ccache,xmake构建的程序运行正常。谢谢大佬! |
这会你再把 ccache 打开,执行 我确认下是不是预处理加了 |
这样也是可以的,程序运行正常。 |
那就是 |
set_policy("preprocessor.gcc.directives_only", false) 也可以在 xmake.lua 里面禁用掉 |
谢谢大佬 : ) |
看了下,加了 我改了下,默认禁用了,如果要进一步加速 ccache,可以自己选择性开启它。可以更新到 dev 再试试,
|
Xmake 版本
2.6.9
操作系统版本和架构
Ubuntu 20.04 LTS x86_64, gcc version 9.4.0, linux kernel 5.15.0-42-lowlatency, CPU 12700k
描述问题
使用xmake & gcc编译openmp程序,构建得到的程序只能以单线程运行。而相同的源代码,手动使用gcc命令行编译得到的程序可以正常多线程运行。相同源代码在Windows11系统使用xmake & MSVC构建的openmp程序可以正常多线程运行,但使用xmake & MinGW64编译构建的程序也只能单线程运行。
期待的结果
找到gcc 编译环境下xmake构建的openmp程序只能单线程运行的原因
工程配置
本问题在测试个人编写的粒子跟踪模拟程序时发现的,使用以下最简单的工程配置以及源代码仍然存在该问题,所以大概率不是本人代码的问题。而且如上面问题描述所说的,Windows系统下MinGW64编译环境也有该问题,但是MSVC编译环境是没问题的。
xmake.lua:
add_rules("mode.release")
add_requires("openmp")
target("omptest")
add_packages("openmp")
set_kind("binary")
add_files("src/*.cpp")
main.cpp:
#include <stdio.h>
#include <omp.h>
int main(void)
{
#pragma omp parallel
{
printf("Hello, world.\n");
}
return 0;
}
附加信息和错误日志
xmake编译运行结果:
(base) kritha@kritha-ubuntu:
/simulation/data/xmake-test/omptest2$ xmake -v/simulation/data/xmake-test/omptest2$ xmake rchecking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /usr/bin/gcc
checking for dmd ... no
checking for ldc2 ... no
checking for gdc ... no
checking for zig ... no
checking for zig ... no
checking for unzip ... /usr/bin/unzip
checking for git ... /usr/bin/git
checking for gzip ... /usr/bin/gzip
checking for tar ... /usr/bin/tar
checking for ping ... /usr/bin/ping
pinging for the host(github.com) ... 65535 ms
pinging for the host(gitlab.com) ... 65535 ms
pinging for the host(gitee.com) ... 65535 ms
/usr/bin/git rev-parse HEAD
checking for gcc ... /usr/bin/gcc
checking for the c compiler (cc) ... gcc
checking for gcc ... /usr/bin/gcc
checking for the c++ compiler (cxx) ... gcc
checking for xmake-repo::openmp ... openmp
checking for /usr/bin/gcc ... ok
checking for flags (-fPIC) ... ok
checking for flags (-fvisibility-inlines-hidden) ... ok
checking for flags (-O3) ... ok
checking for flags (-fopenmp) ... ok
checking for flags (-DNDEBUG) ... ok
[ 25%]: ccache compiling.release src/main.cpp
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -fopenmp -DNDEBUG -o build/.objs/omptest/linux/x86_64/release/src/main.cpp.o src/main.cpp
checking for flags (-MMD -MF) ... ok
checking for flags (-fdiagnostics-color=always) ... ok
checking for g++ ... /usr/bin/g++
checking for the linker (ld) ... g++
checking for /usr/bin/g++ ... ok
checking for flags (-fPIC) ... ok
checking for flags (-fopenmp) ... ok
[ 50%]: linking.release omptest
/usr/bin/g++ -o build/linux/x86_64/release/omptest build/.objs/omptest/linux/x86_64/release/src/main.cpp.o -m64 -s -fopenmp
[100%]: build ok!
(base) kritha@kritha-ubuntu:
Hello, world.
(base) kritha@kritha-ubuntu:~/simulation/data/xmake-test/omptest2$
使用命令行手动编译及运行结果:
(base) kritha@kritha-ubuntu:
/simulation/data/xmake-test/omptest2/src$ g++ -fopenmp -O3 main.cpp -o test/simulation/data/xmake-test/omptest2/src$ ./test(base) kritha@kritha-ubuntu:
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.
(base) kritha@kritha-ubuntu:~/simulation/data/xmake-test/omptest2/src$
The text was updated successfully, but these errors were encountered: