Skip to content

Commit

Permalink
Merge pull request #582 from stan-dev/build/use-precompiled-headers
Browse files Browse the repository at this point in the history
Use precompiled headers to shave off ~15% compile time for models.
  • Loading branch information
seantalts committed Nov 3, 2017
2 parents b4fb55c + d99a3c3 commit 2d58bb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions make/models
Expand Up @@ -2,22 +2,25 @@
# Models (to be passed through stanc)
##
MODEL_HEADER := $(STAN)src/stan/model/model_header.hpp
MODEL_PCH := $(MODEL_HEADER:.hpp=.hpp.gch)
CMDSTAN_MAIN := src/cmdstan/main.cpp

$(MODEL_PCH) : $(MODEL_HEADER)
@echo 'Compiling pre-compiled header'
$(COMPILE.cc) -O$O $(MODEL_HEADER) -o $@

.PRECIOUS: %.hpp %.o
$(patsubst %.stan,%,$(wildcard $(addsuffix .stan,$(MAKECMDGOALS)))) : %$(EXE) : %.hpp %.stan bin/stanc$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) $(LIBCVODES)
$(patsubst %.stan,%,$(wildcard $(addsuffix .stan,$(MAKECMDGOALS)))) : %$(EXE) : %.hpp %.stan bin/stanc$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) $(LIBCVODES) $(MODEL_PCH)
@echo ''
@echo '--- Linking C++ model ---'
ifneq (,$(findstring allow_undefined,$(STANCFLAGS)))
$(LINK.cc) -O$O $(OUTPUT_OPTION) $(CMDSTAN_MAIN) -include $< -include $(USER_HEADER) $(LIBCVODES)
$(LINK.cc) -include-pch $(MODEL_PCH) -O$O $(OUTPUT_OPTION) $(CMDSTAN_MAIN) -include $< -include $(USER_HEADER) $(LIBCVODES)
else
$(LINK.cc) -O$O $(OUTPUT_OPTION) $(CMDSTAN_MAIN) -include $< $(LIBCVODES)
$(LINK.cc) -include-pch $(MODEL_PCH) -O$O $(OUTPUT_OPTION) $(CMDSTAN_MAIN) -include $< $(LIBCVODES)
endif

.PRECIOUS: %.hpp
%.hpp : %.stan $(MODEL_HEADER) bin/stanc$(EXE)
@echo ''
@echo '--- Translating Stan model to C++ code ---'
$(WINE) bin$(PATH_SEPARATOR)stanc$(EXE) $(STANCFLAGS) $< --o=$@

1 change: 1 addition & 0 deletions makefile
Expand Up @@ -249,6 +249,7 @@ clean-manual:

clean-all: clean clean-libraries
$(RM) -r bin
$(RM) $(STAN)src/stan/model/model_header.hpp.gch

##
# Submodule related tasks
Expand Down

0 comments on commit 2d58bb3

Please sign in to comment.