Recompiling openframeworks with more cpus

hi folks,

just wondering if anyone has had the experience of setting up an openframeworks version
on their machine by compiling the source to run on the default setting of 3 cpus and then
later realized that their machine could offer plenty more?

In this case, I have a maximum of 8 cpus available. At the moment I’m not doing anything
particularly expensive in terms of computation, just learning the ropes with some
simple animation and oops design. So, very much adhering to the “if it ain’t broke don’t fix it”
philosophy for the time being.

Nevertheless, it would be interesting to know for future reference, if anyone has got experience recompiling the openframeworks source code on their machine to run with more cpus, and if
so could they please shed some light on the process of recompiling?


Short answer: ./ -j8
The long one: take a look at the script You’ll find where the command line options are assembled:

while getopts tj: opt ; do
        case "$opt" in
                t)  # testing, only build Debug
                    BUILD="test" ;;
                j)  # make job count for parallel build

if you don’t know shell scripting it’s not so easy to read, but using linux it’s a common task, so i suggest you try to learn it

If your question was not about command line compilation, but from some IDE, you have to check the IDE docs

hi, thanks for your reply.

just working my way through Brian Ward’s book on linux, where he covers shell scripting in one of the later chapters, so will be going into a bit more detail there soon.

I guess my question is: having already run ./ -j3 , what is the effect of simply running ./ -j8 - does this simply recompile the source and essentially update the current build, or will it build a second version?

if you’ve already compiled OF with -j3 option, compiling again with -j8 does nothing… Two points, that should make clear what’s going on:

  • the -j option tells make how many CPUs using when compile. OF, or any other program. It’s a matter of time needed to compile VS occupied resources. With -j4 it takes (about) double the time needed to compile with -j8. The result it’s exactly the same
  • the makefile system simply check if some file has changed from last run. If something has changed recompile (only what’s needed), otherwise does nothing. This is useful if you change just a line in you program, only your program need to be recompiled, no every linked library (in example). So every time you modify your app written for OF, only your app it’s recompiled, not the entire OF library

Here’s a simple guide/explanation of what make do:

Oh, in case i’ve missed the obvious link: it’s just a shell script that invokes make with the correct options. The -j stuff it’s just an option passed to make

aha, yeah okay, I was overlooking the fact that the -j option is just affecting the initial build.
I was thinking that this would affect all future programs built with the framework.

so, if I understand you correctly: any program that I build with openframeworks can utilize the maximum number of cpus to build the program, despite the fact that the initial build of the framework was done using only 3.
or put in another way: the number of cores used to build any project can be specified in the makefile at build time

thanks so much for your help!

exactly. You’re just telling make if you’re in an hurry (-j8) or not (-j4, -j2 or even no -j at all). Just for the current build.
And, more important, the final result will always be the same.

yep, with you all the way - thanks again for the help!