Reputation: 234
I use make to automate numerical experiments. It is often the case that I have to simulate data that depends on multiple parameters.
For example, I may have the size of the reconstructed image as a parameter, the noise level as another and also the reconstruction algorithm as a third parameter.
As a concrete case, I may wish to reconstruct 512x512 and 1024x1024 images from 10% and 5% relative error in the data, all the four cases should be done with both FISTA and ISTA algorithms.
I know how to use patterns with %, $@ and $* in order to get what I want when there is only one parameter involved. So, it is easy to get the result for 1024x1024 images using FISTA for several error levels.
But how do I nest?
Upvotes: 0
Views: 532
Reputation: 29345
If what you want (not 100% sure) is to loop over all possible cases, and if the command to launch for each case is:
echo simulate SIZE RELATIVE_ERROR ALGORITHM
then you could try something like:
# sizes
S := 512 1024
# relative errors
E := 5 10
# algorithms
A := FISTA ISTA
# targets
T :=
.PHONY: all
.DEFAULT_GOAL := all
# $(1): size, $(2): error, $(3): algo
define MY_rule
T += $(1)-$(2)-$(3)
.PHONY: $(1)-$(2)-$(3)
$(1)-$(2)-$(3):
@echo simulate $(1) $(2) $(3)
endef
$(foreach s,$(S),$(foreach e,$(E),$(foreach a,$(A),$(eval $(call MY_rule,$(s),$(e),$(a))))))
all: $(T)
It makes use of an advanced GNU make feature, the foreach-eval-call
combination. This other answer explains it in details.
Upvotes: 1