Handmade Hero » Forums » Code » Multithreaded builds?
PassiveCoder
11 posts

Friendly old programmer from the days of the BBC and Amiga

#7425 Multithreaded builds?
1 year, 6 months ago

After speeding up my builds with some tricks learned here I wondered if we couldn't speed things up some more by using a multi-threaded build.
One way to do this is to use START to run a command on a new thread from a batch file.
So you can just stick START before calling CL.EXE.
But this has some problems associate with it.
Firstly if you have a meta pre-processor "project", you need that to build & run first. That OK as you can just build that without the START.
Then you can build both your EXE and your DLLs multi-threaded with START.
The Other problem which is more troublesome is getting the output back from the threaded CL calls.. you can pipe the output to files but that's not ideal.

What do people think? Is it worth it? any ideas?



Lets make CPU orientated programming a thing :)
mmozeiko
Mārtiņš Možeiko
1535 posts
1 project
#7426 Multithreaded builds?
1 year, 6 months ago Edited by Mārtiņš Možeiko on June 28, 2016, 5:28 p.m.

If you have multiple translation units then use /MP argument to cl.exe:
1
cl.exe /MP ...(other args)... file1.cpp file2.cpp fileN.cpp

This will make cl.exe to compile each file in separate process. This is available since VS2005.

If you have only one translation unit use /cgthreads argument. It will use 4 threads for code generation and optimizations. You can use number 1 to 8 to specify exactly how many threads to use. This is available since VS2013.

You can use both switches together.
PassiveCoder
11 posts

Friendly old programmer from the days of the BBC and Amiga

#7436 Multithreaded builds?
1 year, 6 months ago

Oh that's a much better solution,
thanks mmozeiko

Lets make CPU orientated programming a thing :)