3

How do I make gprbuild default to doing parallel builds? It's not 1990 any more, and I have all these spare cores and don't want to have to keep adding -j0 onto the command line.

From my understanding of the docs, this should work:

package Builder is
    for Default_Switches("Builder") use ("-j0");
end Builder;

...but it doesn't; it's just ignored. I've seen mentions on the interwebs that Default_Switches("Ada") should work, but all that does is pass the --jobs option to GNAT, which is of course wrong.

David Given
  • 13,277
  • 9
  • 76
  • 123

1 Answers1

6

I don’t see anywhere in the sources of gprbuild where the number of jobs can be controlled except by -j.

However, the documentation suggests that you gan get the effect you want using an “aggregate project”. I wrapped one of my project files in an aggregate like so:

aggregate project Gnat_Util_Aggregate is
   for Project_Files use ("gnat_util.gpr");
   package Builder is
      for Switches (others) use ("-j0");
   end Builder;
end Gnat_Util_Aggregate;

The times for the plain project build on this 13” Macbook Pro were

   70.17 real        66.33 user         2.85 sys

and for the aggregate project build

   35.46 real       119.05 user         4.80 sys

(I have no idea what the “user” values mean! but I checked the “real” values and they match my wristwatch.)

I’ve reported the error on the GPRBuild documentation link above (it says for Switches (other), should be others) to AdaCore.

UPDATE: following David’s justified complaint, and on a hunch, I tried this package Builder trick in my plain project and it worked. I still don’t see where this happens in the sources.

For info, the undocumented switch -dm reports the maximum number of simultaneous compilations (in both gnatmake and gprbuild).

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • trashgod, thanks. Surprising then that it takes twice as much total CPU time to do the job using 4 cores as it does with just one. Communications/cache misses/waiting for disk, I suppose. – Simon Wright May 18 '14 at 12:09
  • Thanks (even though using an aggregate project just to pass parameters is really ugly). Odd there isn't an internal option for this. – David Given May 19 '14 at 12:34
  • :blush: (though given the lack of documentation I don’t feel *too* bad). See the updated answer for Good News. – Simon Wright May 19 '14 at 14:32
  • Yes --- that works nicely. Thanks very much! Now, if only `-p` worked there as well... – David Given May 22 '14 at 21:01