Dear Nick Stoughton,

Nick Stoughton wrote in
 <CAA3V+jTspAu-5+z0hQ8dz8gM8s-ezAXZ6NnDhFGFHNnwE=a...@mail.gmail.com>:

[i resort a bit]

 |On Tue, Oct 29, 2024 at 5:00 PM Steffen Nurpmeso via austin-group-l at The
 |Open Group <[email protected]> wrote:
 |> Rob Landley via austin-group-l at The Open Group wrote in
 |>  <[email protected]>:
 |>|On 10/22/24 00:42, Andrew via austin-group-l at The Open Group wrote:
 |>|> Both GNU and BSD make support parallelism with -j flags.
 |>|>
 |>|> Can POSIX make adopt a -j flag to indicate the maximum number of \
 |>|> concurrent jobs, default 4?
 |>|>
 |>|> This can help to accelerate a lot of existing makefiles.
 ...

 |The latest edition, Issue 8, includes this. Here is an excerpt from the
 |make page:
 ...

i think your answer was meant for Andrew.

  ...
 |>|Why not autodetect? I use -j $(nproc) a lot, although on BSD/mac it's
 |>|"sysctl -n hw.ncpu" instead.
 |>|
 |>|Arbitrary limit seems a bit silly when the ability to probe exists. (The
 |>|linux one even responds to taskset by default, dunno about bsd-land...)
 |>
 |> nproc is broken in namespaces, and the glibc maintainers will not
 |> fix it.  I have forgotten other details, responsible persons are
 |> on this list if i recall correctly, though.  (A search may show up
 |> bug report(s) (of which there are at least two).)
 |> Ie: no reason for this "even [does] xxx".
 |> 'Must be said, FreeBSD introduced nproc(1) too not too (double
 |> too!!) long ago, maybe that works correctly in jails or wherever
 |> cpusets etc are used.

Other than that POSIX.1-2024 POSIX.1 2024 brought in getconf(1)s

  • The names NPROCESSORS_CONF and NPROCESSORS_ONLN. The
    values of these configuration variables shall be determined
    as if they were obtained by calling the function sysconf( )
    with the argument _SC_NPROCESSORS_CONF or _SC_NPROCESSORS_ONLN,
    respectively.

But it must be said that inside my horizon people use nproc(1)
whenever available, and, like i said, FreeBSD newly introduced
that not too long ago.  So even if POSIX now comes with it, which
is very good (in my opinion), i can only hardly imagine it makes
it to the very front.  (nproc(1) could now be implemented in an
easy way through it, though.)
I personally, fwiw, have this in my ~/.profile, and make use of
the $NPROC variable that is mentioned in "Base Definitions":

  NPROC=
  if command -v nproc >/dev/null 2>&1; then
          NPROC=$(nproc)
  elif command -v getconf >/dev/null 2>&1; then
          NPROC=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
          [ $? -ne 0 ] && NPROC=$(getconf NPROCESSORS_ONLN 2>/dev/null)
  fi
  if [ -n "$NPROC" ]; then
          :
  elif [ -f /proc/cpuinfo ]; then
          i=$(< /proc/cpuinfo awk '
                  BEGIN{no=0; FS=":"}
                  /^processor[[:space:]]*/{if($2 > no) no = $2; next}
                  END{print ++no}
                  ')
          [ $? -eq 0 ] && NPROC=$i
  elif command -v sysctl >/dev/null 2>&1; then
          i=$(sysctl -n hw.ncpu)
          [ $? -eq 0 ] && NPROC=$i
  elif command -v kstat >/dev/null 2>&1; then
          i=$(PERL5OPT= kstat -p cpu | awk '
                  BEGIN{no=0; FS=":"}
                  {if($2 > no) max = $2; next}
                  END{print ++max}
                  ')
          [ $? -eq 0 ] && NPROC=$i
  fi
  export NPROC

which gets me going on Linux, *BSD i'd say, and SunOS/Solaris.
It is a constant, however, and as such often not the truth.

And that is the problem that exists in practice with the above in
general, as there cpusets / cgroups / whatever, and not rarely
real facts are not shown: you have to use system specifics for the
truth.

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
|
|And in Fall, feel "The Dropbear Bard"s ball(s).
|
|The banded bear
|without a care,
|Banged on himself fore'er and e'er
|
|Farewell, dear collar bear

        • Re: req... Paul Smith via austin-group-l at The Open Group
          • Re:... David A. Wheeler via austin-group-l at The Open Group
            • ... Paul Smith via austin-group-l at The Open Group
            • ... Steffen Nurpmeso via austin-group-l at The Open Group
    • Re: request: ma... Rob Landley via austin-group-l at The Open Group
  • Re: request: make [-... Steffen Nurpmeso via austin-group-l at The Open Group
    • Re: request: ma... Nick Stoughton via austin-group-l at The Open Group
      • Re: request... Steffen Nurpmeso via austin-group-l at The Open Group
        • Re: req... Joshua M. Clulow via austin-group-l at The Open Group
          • Re:... Steffen Nurpmeso via austin-group-l at The Open Group

Reply via email to