我一直在对我最近开始使用 CMake 构建的项目进行一些测试。在转向 CMake 之前,我注意到使用 -j
时构建时间有显着改善。 make
的选项用我手写的 Makefile。
现在使用 CMake 我做同样的事情并且速度没有任何明显的提高。是否与我一起运行 -j
与否,我得到了 make.exe
的四个进程,尽管其中只有一个为 CPU 时间计时,并且从不使用超过 25% 的 CPU。
一般来说,CMake 生成的 Makefile 比我手写的 Makefile 慢得多。快速测试显示了带有和不带有 -j
的 CMake 和手写 makefile 的构建时间。旗帜:
CMake: "make -j all" = 7min
CMake: "make all" = 7min
Handwritten: "make -j all" = 2min
Handwritten: "make all" = 4min
一般来说,CMake 速度要慢得多,而且似乎不使用并行作业。
谁能解释为什么我没有看到任何改进?
(使用 gfortran 构建 Fortran 程序并使用 CMake 的自动检测依赖项功能……尽管我不知道这是否与我所看到的有关)。
这是我的 CMakeLists.txt 文件:
## CMake Version
cmake_minimum_required(VERSION 2.8)
## Project Name
project(PROJECT)
## Use FORTRAN
enable_language(Fortran)
## Release compiler options
set (CMAKE_Fortran_FLAGS_RELEASE "-O3 -cpp -ffree-line-length-none -fimplicit-none")
## Debug compiler options
set (CMAKE_Fortran_FLAGS_DEBUG "-g -cpp -ffree-line-length-none -fimplicit-none")
## Set directory for FORTRAN modules
set (CMAKE_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/modules")
## Build Executable
add_executable(EXE
Source1.f90
Source2.f90
.
.
.
Source219.f90
Source220.f90)
这是我的原始 Makefile:
PROG = PROGRAM.exe
SRCS = Source1.f90 Source2.f90 ... Source219.o Source220.o
OBJS = Source1.o Source2.o ... Source219.o Source220.o
LIBS =
VPATH = src
BUILDDIR = debug
F90 = gfortran
F90FLAGS = -g -cpp -ffree-line-length-none -fimplicit-none
all: $(PROG)
$(PROG): $(OBJS)
$(F90) -o $@ $(OBJS) $(LIBS)
clean:
erase -f $(BUILDDIR)$(PROG) $(BUILDDIR)\$(OBJS) $(BUILDDIR)\*.mod
.SUFFIXES: $(SUFFIXES) .f90
.f90.o:
$(F90) $(F90FLAGS) -c $<
Source1.o: Dependency1.o Dependency2.o ... DependencyN.o
Source2.o: Dependency1.o Dependency2.o ... DependencyN.o
.
.
.
Source219.o: Dependency1.o Dependency2.o ... DependencyN.o
Source220.o: Dependency1.o Dependency2.o ... DependencyN.o
最佳答案
这是在 window 上吗?如果是这样,那是因为 gmake 的 Windows 版本没有作业服务器,并且递归生成文件不是并行的。我假设当您编写 make.exe 时,这意味着 Windows。我认为 CVS gmake 现在有一个工作服务器。 cygwin gmake 也支持作业服务器。
此链接可能对您有所帮助:
http://lists.gnu.org/archive/html/make-w32/2011-07/msg00002.html
关于makefile - 使用 CMake 生成的 makefile 的并行作业(没有速度改进),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12807806/