Click here to Skip to main content
Click here to Skip to main content

Run All Jobs at Once Utility

, 20 Aug 2009
Rate this:
Please Sign up or sign in to vote.
A command-line tool to run multiple programs in parallel (i.e. concurrently, as a group).

Turbo-charge your Visual Studio project builds!

How often have you wished there was a batch (command-line) command that allowed you to start several programs 'at once,' and then wait for 'all' of them to finish together as a group before continuing?

How handy would it be to be able to write a batch file that allowed you to start several VCBUILDs, having each of them run simultaneously with one another (i.e. at the same time or "in parallel" with one another), thereby fully utilizing that new dual- or quad-processor system you just bought, thereby dramatically reducing the amount of time it takes to build your product?

Well, with "RunJobs", now you can!

Background

If you have, on occasions, searched the Microsoft Visual Studio Support Forums in the past, you may have noticed that more than one person has inquired about the possibility of running multiple builds in parallel (i.e., doing a "Batch Build" but have each Solution Configuration built concurrently rather than serially one after the other), with Microsoft always replying that due to certain technical difficulties, it was not possible.

To me, this was unacceptable since, when designed (configured) properly, each Solution Project's different build configuration 'should' designate different Intermediate and Output directories, thereby allowing each of them (Debug|Win32, Release|Win32, Debug|x64, Release|x64, etc.) to be built 'in parallel' since neither was dependent on the other.

Never being the one who is satisfied with any type of "Can't be done!" response, I set about developing a simple means of accomplishing just that, thereby dramatically reducing Solution build times (especially for large complicated Solutions with many projects, each with many different build configurations).

Using RunJobs

RunJobs is a simple command-line program written in MFC that allows one to start several different programs at the same time. It is written in MFC only because that is what I personally prefer writing my Windows programs in. It is 'not' however a requirement, of course. Being such a simple program, it could easily be ported to any other language of your choice.

I shall first describe how to use it, followed briefly by how it works.

Upon starting the program either without any arguments or with the standard /? argument, the following 'Help' text is displayed, which I hope is self-explanatory in describing how to use the utility:

                     RunJobs
        Fish's Run All Jobs at Once utility
                Version 1.1.2.nnn

  Copyright (C), Software Development Laboratories
         http://www.softdevlabs.com/runjobs
                fish@softdevlabs.com

Format:

   RunJobs   <jobsfile>   [ -j nnn ]   [ -rcfile xxxxx ]


Where:

   <jobsfile>      filename of command-lines to be started
   -j nnn          maximum number of simultaneous commands
   -rcfile xxxxx   name of optional return codes file


The jobs file is a simple verbatim list of the command-lines
that you wish to issue.

Lines whose first non-blank character is '#', ';' or '*' are
considered comment lines and are ignored. All blank lines are
also ignored.

All other lines contain the exact command-line to be issued.

The -j parameter sets an upper limit to the maximum number of
simultaneously running commands.

When the jobs file contains more than this number of commands
the next job (command) is not started until one or more of the
previously issued jobs (commands) finishes first.

Specifying 0 (zero) indicates no upper limit (i.e. ALL listed
jobs will be started simultaneously regardless of how ever many
there are).

The default for -j is the value of the "RUNJOBS_DEFAULT_MAXJOBS"
environment variable if defined or the number of CPUs installed
on your system if it is not defined.

The return code from RunJobs is always the maximum returned
return code value from any of the started jobs. If the -rcfile
option is specified the return code value from each job is also
written to the specified return codes file using the following
format: "n = rc" where 'n' is the job number and 'rc' is its
corresponding return code value.


                         USAGE NOTE

Since RunJobs doesn't parse jobs file command-lines, all of your
environment variable strings on your command-line SHOULD have a
valid (non-empty) value assigned to it. Otherwise an improperly
formed command-line will be built since ExpandEnvironmentStrings
leaves the variable unexpanded whenever it cannot find it. For
example: if your specified command-line is:

    VCBUILD  %VCBUILDTYPE%  "MyProj.vcproj"  "Debug|Win32"

then VCBUILD fails (and crashes if invoked within the IDE!) with
the following error:

  "vcbuild.exe : warning VCBLD6002: invalid option Debug|Win32
                 specified. The option was ignored."

To prevent this, ensure that all environment variable strings on
your command-line are expandable.

In the sample project (which actually builds the RunJobs utility itself), the vcbuild-all.cmd batch file illustrates how RunJobs could be used to build all of your project's various configurations in parallel.

The first thing you'll want to do is copy RunJobs.exe to somewhere where Windows can find it (i.e. somewhere in your Windows search PATH).

Then simply define some additional Solution/Project configurations that call the vcbuild-all.cmd batch file (see project source) to run RunJobs with the proper jobs file which would of course be setup to issue the actual VCBUILD command for each of the different configurations you wished to be built in parallel for that particular configuration.

Refer to the supplied Visual Studio project (both the .sln solution file as well as the .vcproj project file as well as the vcbuild-all.cmd batch file and associated All-Debug.jobs, All-Release.jobs, etc, files too) for a real world example of how you might accomplish this.

RunJobs Internals

The CMyCmdLineParser class parses the command-line arguments and sets global variables to the name of the "jobs" file to be run and the desired "maximum concurrent jobs" value.

The CStdioFileEx class is used to read the specified "jobs" file and create a new entry in a CList of CPipedProcessCtl objects. The CPipedProcessCtl class is a simple custom designed class to make it trivial to spin off a secondary process via CreateProcess with its STDIN/STDOUT/STDERR files piped back to the creating process.

As each started process writes to its STDOUT/STDERR file, the separate pipe monitoring threads the CPipedProcessCtl class automatically creates redirects the output to RunJob's real STDOUT/STDERR files (which, of course, is then intercepted by Visual Studio and displayed in the Output pane).

As each process ends, the return code is retrieved (via GetExitCodeProcess) and saved, with the highest one of any of the started process' used as RunJob's own return code. In this way, one can check within one's batch files whether all the "jobs" -- as a group -- completed successfully or not.

Expected Improvement in Build-times

RunJobs, running on my dual 2.4GHz Xeon development platform (hyperthreaded to look like a quad-processor), has reduced my build time for a small, semi-complex multiple-projects / multiple-build-configurations (Debug|Win32, Release|Win32, Unicode Debug|Win32, Unicode Release|Win32, plus the same four but for the x64 platform (i.e. a total of eight build configurations per project)) from 9:48 to 5:37. An improvement of approximately 43%.

rdboss (see comments further below) writes:

This product has been a god send for us. [...] Our nightly build process has been dropped from about 20 hours down to about 10 hours!

Esteban Papp however (see comments further below) writes:

We are using it to do multiple platforms parallelized build, it is running great in a 2xQuad-Core 3Ghz, our build time was 1h and now it is 7min.

That's over '8.5x' times faster! ('almost' 10x times!) Wow!

Of course I should caution that "Your Mileage May Vary". It all depends on the complexity of your projects/solutions (how many source files each project has, how many different configurations each one has, etc), but the point is, being able to build multiple project configurations in parallel definitely does help! (which of course is why I wrote RunJobs in the first place)

In general however, based largely on the above reports, I expect you should see an approximate improvement in your build times of anywhere from 50% to over 150% or more.

Not bad for a simple command-line too, eh?   Smile | :)

Closing Remarks

Well, I guess that's it. There's really not much else to add. I hope you all enjoy using RunJobs to help speed your build times, and look forward to hearing how well it works for you.

That's it!   Enjoy faster build times with RunJobs!   Smile | :)

History

  • May 2008: Version 1.0.0 released and article written

  • November 2008: Version 1.0.2
    • Corrected return-code issue identified by esteban.papp
    • Converted to Visual C++ 2008 SP1
    • Statically link to MFC and CRT

  • March 2009: Version 1.1.0
    • Fixed cancel propagation issue.
    • Added -rcfile option
    • Redesigned project implementation

  • August 2009: Version 1.1.2
    • Fix issue where 'StartChildProcess' failure was causing the overall return-code to not get updated.
    • Fix non-unique job-number log-prefix issue identified by rdboss. (see comments)

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License

About the Author

"Fish" (David B. Trout)
Software Development Laboratories
United States United States
Old timer with over 30+ years experience in the industry.
 
Started out programming in assembler on IBM mainframes working my way up from novice computer operator to manager of programming department responsible for multi-million-record database updating software for a major credit reporting company, eventually becoming part of a small team responsible for designing/developing a new microprocessor operating system.
 
Made the transition from IBM mainframes to Windows personal computers in the early '90s when the internet was still young. Started programming on Windows with Visual C++ version 1.0 on Windows 3.1. Currently using VS2005 but plan to upgrade to VS2008 "soon".
 
Contracted for a short while at Microsoft providing Premier Technical Support for the "Desktop Team 3" (VC++/MFC).
 
Currently part of the "Hercules" Open Source core development team, allowing me to stay active in both the mainframe area (which is most definitely NOT dead but still VERY much alive and well thankyouverymuch) as well as in the Windows programming area too (which seems to be a good fit for someone with my background).
 
I'm currently self-employed providing per-hour contract support for Hercules (http://www.hercules-390.org).

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberwrljet9-Jul-13 3:52 
QuestionThanks a lot. PinmemberJohn M. Drescher28-Jul-11 13:06 
GeneralRe: Thanks a lot. Pinmember"Fish" (David B. Trout)15-Dec-11 18:51 
GeneralAnother Suggestion and Big Thanks! Pinmemberrdboss27-Jul-09 11:42 
AnswerRe: Another Suggestion and Big Thanks! Pinmember"Fish" (David B. Trout)12-Oct-09 21:43 
Generaltwo more suggestions Pinmemberesteban.papp10-Feb-09 3:20 
AnswerRe: two more suggestions Pinmember"Fish" (David B. Trout)12-Mar-09 23:02 
GeneralRe: two more suggestions Pinmember"Fish" (David B. Trout)12-Oct-09 21:54 
GeneralChanged type for return code variable Pinmemberesteban.papp17-Sep-08 16:54 
GeneralRe: Changed type for return code variable Pinmember"Fish" (David B. Trout)20-Nov-08 17:40 
AnswerRe: Changed type for return code variable Pinmember"Fish" (David B. Trout)12-Oct-09 21:50 
NewsBSOD update -- it's not Process Explorer, it's avast anti-virus Pinmember"Fish" (David B. Trout)12-May-08 5:23 
GeneralRe: BSOD update -- it's not Process Explorer, it's avast anti-virus Pinmembertrotwa14-May-08 12:03 
AnswerRe: BSOD update -- it's not Process Explorer, it's avast anti-virus Pinmember"Fish" (David B. Trout)14-May-08 15:09 
GeneralRe: BSOD update -- it's not Process Explorer, it's avast anti-virus PinmemberFabc20-May-08 4:17 
AnswerRe: BSOD update -- it's not Process Explorer, it's avast anti-virus Pinmember"Fish" (David B. Trout)26-May-08 0:13 
GeneralRe: BSOD update -- it's not Process Explorer, it's avast anti-virus Pinmembertrotwa31-May-08 6:52 
QuestionStart ? PinmemberSoundman32.25-May-08 22:03 
AnswerRe: Start ? [modified] Pinmember"Fish" (David B. Trout)5-May-08 23:19 
GeneralRe: Start ? PinmemberSoundman32.26-May-08 0:23 
GeneralRe: Start ? PinmemberSoundman32.26-May-08 0:25 
GeneralRe: Start ? [modified] Pinmember"Fish" (David B. Trout)6-May-08 0:54 
GeneralBSOD Pinmembertrotwa5-May-08 11:27 
AnswerRe: BSOD [modified] Pinmemberpkaospwvxdkyt5-May-08 16:47 
GeneralRe: BSOD Pinmembertrotwa5-May-08 21:29 
GeneralRe: BSOD Pinmember"Fish" (David B. Trout)6-May-08 0:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 20 Aug 2009
Article Copyright 2008 by "Fish" (David B. Trout)
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid