Created
September 28, 2018 19:05
-
-
Save luiarthur/08d4d4dc0642dc733b883ed2817555a8 to your computer and use it in GitHub Desktop.
Makefile example for running multiple jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RUN ALL THIS IN AN EMPTY DIR! | |
# Run in parallel | |
MAKEFLAGS += -j4 | |
# Simulation variables. | |
MSG = "Hello" | |
PARAMS := 100 1000 10000 | |
#PARAMS := $(shell seq 1 10) # or something like this for params = 1, 2, ..., 10 | |
SIMS := $(addprefix sim, $(PARAMS)) | |
RESULTS_DIR := "results/" | |
# Simulation. | |
.PHONY: sims $(SIMS) | |
sims: $(SIMS) | |
echo "Completed simulations." | |
# Note that each line is executed in a new shell. So, if you want to cd and then do something, | |
# make it in the same line. | |
$(SIMS): sim%: | |
$(eval EXPERIMENT := $*) | |
mkdir -p $(RESULTS_DIR)/$(EXPERIMENT)/ | |
cd $(RESULTS_DIR) && echo "$(MSG) $(EXPERIMENT)!" > $(EXPERIMENT)/out.txt | |
# Remove artifacts from simulations. | |
clean: | |
rm -rf $(RESULTS_DIR)/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment