Skip to content

Instantly share code, notes, and snippets.

@luiarthur
Created September 28, 2018 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luiarthur/08d4d4dc0642dc733b883ed2817555a8 to your computer and use it in GitHub Desktop.
Save luiarthur/08d4d4dc0642dc733b883ed2817555a8 to your computer and use it in GitHub Desktop.
Makefile example for running multiple jobs
# 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