make: Run several tasks in parallel and wait for completion

后端 未结 2 445
耶瑟儿~
耶瑟儿~ 2020-12-30 07:23

One target in my makefile is a very CPU and time consuming task. But I can split the workload and run the task several times in parallel to speed up the entire process.

2条回答
  •  一向
    一向 (楼主)
    2020-12-30 08:03

    Why not use the mechanisms already built in make? Something like this:

    task%:
            sh task.sh $*
    
    test: task5 task15 task10
            echo "DONE"
    

    You will be able to adjust the level of parallelism on the make command line, instead of having it hard-coded into your makefile (e.g use 'make -j 2 test' if you have 2 cores available and 'make -j 32 test' if you have 32 cores)

提交回复
热议问题