61

I just got a new quad core computer and noticed that nmake is only using 1 process.

I used to use make which had the switch -j4 for launching 4 processes. What is the nmake equivalent?

[edit] Based on the information below I have been able to add a command to my qmake project file:

QMAKE_CXXFLAGS += /MP

Which effectively did it for me. Many thanks.

Phil Hannent
  • 12,047
  • 17
  • 71
  • 118

8 Answers8

56

Another generic, non-Qt-related way to tell nmake to use all the cores is to set environmental variable CL to /MP:

set CL=/MP
nmake

will use all the CPU cores.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
  • 3
    As I understand it this only helps if multiple files are compiled using the same command. – Zitrax Jun 20 '17 at 18:36
  • @Zitrax: you are correct. Typically, you compile a project (bunch of files) so it works. – Violet Giraffe Jun 21 '17 at 06:51
  • 7
    The project I looked at compile a few hundred files, but each one uses a separate cl command, like `cl a.cpp, cl b.cpp, cl c.cpp, ...` So I wanted to point out that it does not seem to help in such situation with nmake unless the build system is rewritten into supplying several files to each cl command like `cl a.cpp b.cpp c.cpp ...`. – Zitrax Jun 21 '17 at 07:22
  • @Zitrax: Perhaps https://learn.microsoft.com/en-us/cpp/build/batch-mode-rules?view=vs-2017 is relevant? I have not tried it myself. – Joseph Quinsey Jan 28 '19 at 03:51
  • That misleading hint to use `set CL=/MP` should really be dismissed more clearly. It has caused quite some extra work needlessly. – dvo Dec 03 '20 at 08:14
  • 2
    @dvo: the "misleading hint" worked great for me for many years on many different projects, especially those I just to want to build and be done with without modifying the supplied project files. If you've discovered a problem, it would be much more useful if you elaborated on it to warn others rather than just complain "something didn't work". – Violet Giraffe Dec 03 '20 at 14:14
40

QT has a tool for this: http://download.qt.io/official_releases/jom/

They also use it per default in Qt creator.

FourtyTwo
  • 1,616
  • 2
  • 15
  • 43
Tolik Odukha
  • 815
  • 1
  • 8
  • 12
  • 7
    Precompiled jom binaries are here: ftp://ftp.qt.nokia.com/jom/ – Lucas Jun 17 '10 at 17:41
  • The link is dead and this is an `nmake` question; not a QT question. Perhaps you can explain things a bit more. – jww Jun 01 '17 at 08:05
  • 1
    @jww this link was alive. 9 year ago at least (and updates for it in more recent connents) also. Have you seen tag "qt" and "QMAKE_CXXFLAGS" in question? also there was no support for using multiple cores in nmake 9 years ago... so there are no reason downvote the answer. – Tolik Odukha Jan 06 '18 at 17:50
  • 2
    @jww: jom is a drop-in nmake replacement, it has no dependency on Qt. – Jean-Michaël Celerier Feb 19 '19 at 10:40
  • @Jean-MichaëlCelerier Or so I thought... While jom works for NMake files generated by QMake, it does not work for NMake file generated by CMake; it complains about an invalid NMake format file. So in that case, it is not a drop-in replacement. Edit: It works when using the CMake generator "NMake Makefiles JOM". – jmk Aug 03 '22 at 00:09
  • if you're using CMake you should use the Ninja generator instead of nmake or jom, it will be much faster especially for incremental rebuilds @jmk – Jean-Michaël Celerier Aug 03 '22 at 09:17
27

According to MSDN, there's no such option for nmake.

You can however make the compiler build multiple files in parallel by using the /MP option with the VC++ command line compiler and passing multiple files at the same time:

> cl /MP a.cpp b.cpp c.cpp

However note that most Makefiles don't call the compiler like this - they usual invoke the compiler separate for each individual source file, which would prevent the /MP option from doing anything useful.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • 1
    Only not .o, but .obj. VC++ compilers generates .obj, GCC - .o, AFAIK – abatishchev Mar 02 '09 at 12:22
  • 16
    A convenient way to use this flag is to let cl.exe retrieve it from the "CL" environment variable. Set it in your system properties or type it on the command line: "set CL= /MP" – jturcotte Jun 14 '10 at 17:54
6

The CMake 2.8.1 RC1, as for the time of writing this it's ready to try, does bring new generator for NMake which is called NMake Makefiles JOM and it generates NMake with specific settings for jom, which is the drop in replacement of NMake. Thus, it gives multi-processing enabled building using NMake.

mloskot
  • 37,086
  • 11
  • 109
  • 136
6

Incredibuild claims to be able to run nmake builds on multiple cores / multiple machines. I don't have any experience of it.

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • It's very simple actually and works great. This is a good reference: http://xoreax.helpserve.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=171 – ttvd Mar 25 '11 at 07:31
  • Yep! I worked on an app. that took about 1h 20min. to compile in full. With Incredibuild and about 10 multi-processor machines, the same app. compiled in 5 min. Quite impressive improvement if you ask me! – Alexis Wilke Dec 14 '11 at 02:03
  • The link to the reference on how to accelerate nMake using IncrediBuild has changed to [link](http://xoreax.helpserve.com/staff/Knowledgebase/Article/Edit/105). Disclaimer - the writer of this comment works at IncrediBuild – Dori Jun 22 '16 at 12:33
  • @Dori - The link is behind a login. Can you provide a link that does not require us to buy the product or join the company or one of its programs? – jww Mar 19 '17 at 20:53
  • @jww I'm very sorry, but you'll require to register in order to receive a version of IncrediBuild (registering in order to receive a product link is a customary practice...). Once registered you'll get a 30 days trial license of the product which will allow you to distribute compilation tasks across additional cores in your network (thus increasing the amount of cores participating in your build to up to 5 machines of 8 cores each). Once the trial period is over you'll still be able to use IncrediBuild on your local machine free of charge :) Disclaimer - the writer works at IncrediBuild – Dori Mar 21 '17 at 16:20
2

Quick googling gives: http://msdn.microsoft.com/en-us/library/bb385193.aspx

Marcin Gil
  • 68,043
  • 8
  • 59
  • 60
  • 4
    that's parallel compilation of multiple .cpp files in the same invocation of the compiler - not parallel building of multiple 'make' targets – Alnitak Mar 02 '09 at 11:24
  • It's very interesting, how to switch on this switch in VS2008! I can't find it – abatishchev Mar 02 '09 at 11:31
  • it's not an "nmake" option, it's a "c1" option (i.e. for use with the command line compiler) – Alnitak Mar 02 '09 at 11:41
  • Yeap, cl.exe, so it must be possible to use in Visual Studio, as far as it calls it directly, I guess, not using nmake. Or I'm not right? – abatishchev Mar 02 '09 at 12:23
  • Didn't Visual Studion use that switch by default? I remember it batch compiling files already. – MSalters Mar 03 '09 at 12:57
  • Yes the IDE will use it by default, it just starts two instances of cl - but you can't use it with nmake. – Martin Beckett Mar 03 '09 at 16:26
2

This doesn't work for normal makefiles, but there is a setting in Visual Studio 2005 that lets you build more than one .vcproj file at the same time (provided one isn't dependent on the other). Tools -> Options -> Projects and Solutions -> Build and Run -> X maximum number of parallel project builds.

teeks99
  • 3,585
  • 2
  • 30
  • 38
-1

It's not quite the same, but if you use cmake, you can export solution (e.g. using generator "Visual Studio 14 2015" instead of "NMake Makefiles").

In this case it's possible to build exported solution using msbuild tool which allows you to parallelize building process with /maxcpucount command line switch.

Andrey Starodubtsev
  • 5,139
  • 3
  • 32
  • 46