user1649641
user1649641

Reputation: 51

Running make with a mixture of single-threaded and multi-threaded recipes

I have a makefile that compiles and runs a fairly large set of programs, to produce output. Some of the programs are single-threaded, and some use OpenMP to run on multiple CPU cores. Quite a few of the tasks take a long time to run, so it would be useful to pass a "-j" option to make, to allow the single-threaded programs to be run in parallel. However, the OpenMP tasks already use all available CPU cores (and quite a lot of RAM), so they should be run one at a time.

Is there a flag that I can attach to the tasks that use OpenMP in the makefile that prevents other tasks running in parallel to it, while allowing other tasks to run in parallel at other times? I think the .NOTPARALLEL special target completely disables all parallelism.

Upvotes: 5

Views: 889

Answers (1)

nat chouf
nat chouf

Reputation: 756

I can think of three possibilities:

1) make will not run tasks in parallel if they depend on each other. So you could try to trick make by adding false dependecies to the targets that you want to run alone. For exemple, declare that your OpenMP targets depend on the output of all the serial ones.

2) you could maybe also split your Makefile into two different ones: one for OpenMP targets that will not run in parallel, and one for the serial ones. This implies that you don't have cross dependencies between OpenMP and serial targets.

3) split the compiling and the running. Use a bash script to run things as you wish.

Upvotes: 1

Related Questions