Announcement

Collapse
No announcement yet.

Cofigure gcc and make to use multiple threads by default

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Cofigure gcc and make to use multiple threads by default

    I have a pc with a lot of cores and threads and I wish to compile and make using as many threads as possible to save time. In Arch there is a way to do this, by default so that you con't have to type arguments every time, but I don't know how in Ubuntu.
    My google is not finding anything.

    #2
    it very possibly is done the same way as in Arch, or something similar.
    From what I can remember, calling make with the '-jN' flag will use multiple threads/jobs, where N is the number you want.

    Comment


      #3
      There are many ways to do this. I do it in a hacky way with MAKEFLAGS; f.ex.:
      Code:
      time make > make.log
      make > make.log  2.43s user 0.92s system 100% cpu 3.330 total
      make clean
      export MAKEFLAGS=j2
      time make > make.log
      make > make.log  2.34s user 0.95s system 196% cpu 1.669 total
      make clean
      export MAKEFLAGS=j8
      time make > make.log
      make > make.log  3.36s user 1.26s system 675% cpu 0.683 total
      -jn with recursive makes gets tricky, so Gnu make used to just take the number off and pass -j to all the sub-make invocations, but since Gnu make 4.2 it supposedly does something more clever, sharing out the processes, so that the total number of jobs stays under or close to the limit given. But this is the case putting -jn on the command line anyway.
      Regards, John Little

      Comment


        #4
        Arch uses mkpkg and grabs source via the AUR so there is a mkpkge config file, Ubuntu doesn't.

        Comment


          #5
          Originally posted by jlittle View Post
          There are many ways to do this. I do it in a hacky way with MAKEFLAGS; f.ex.:
          Code:
          time make > make.log
          make > make.log  2.43s user 0.92s system 100% cpu 3.330 total
          make clean
          export MAKEFLAGS=j2
          time make > make.log
          make > make.log  2.34s user 0.95s system 196% cpu 1.669 total
          make clean
          export MAKEFLAGS=j8
          time make > make.log
          make > make.log  3.36s user 1.26s system 675% cpu 0.683 total
          -jn with recursive makes gets tricky, so Gnu make used to just take the number off and pass -j to all the sub-make invocations, but since Gnu make 4.2 it supposedly does something more clever, sharing out the processes, so that the total number of jobs stays under or close to the limit given. But this is the case putting -jn on the command line anyway.
          Is that a config file that I edit? If so where is it or where would I create one? I have 16 threads on my CPU so I would like to be able to compile using between 14 -16 threads.

          Comment


            #6
            MAKEFLAGS is (if you want it to be) an ordinary environment variable. Ordinary environment variables are visible in make.

            I set these in my ~/.bashrc file for simplicity, though maybe ~/.profile is more proper. Just chuck "export MAKEFLAGS=j16" into ~/.bashrc (if indeed, your login shell is bash, the default shell in Kubuntu). Put it near the beginning if you might be compiling non-interactively, because .bashrc files can exit early if non-interactive.
            Regards, John Little

            Comment

            Working...
            X