Skip to content
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

Use precompiled headers to shave off ~15% compile time for models. #582

Merged
merged 1 commit into from Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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