From: Brian Harring <ferringb@gmail.com>
To: Mike Frysinger <vapier@gentoo.org>
Cc: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] multiprocessing.eclass: doing parallel work in bash
Date: Sat, 2 Jun 2012 16:59:02 -0700 [thread overview]
Message-ID: <20120602235902.GC9296@localhost> (raw)
In-Reply-To: <201206011841.23302.vapier@gentoo.org>
On Fri, Jun 01, 2012 at 06:41:22PM -0400, Mike Frysinger wrote:
> # @FUNCTION: multijob_post_fork
> # @DESCRIPTION:
> # You must call this in the parent process after forking a child process.
> # If the parallel limit has been hit, it will wait for one to finish and
> # return the child's exit status.
> multijob_post_fork() {
> [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments"
>
> : $(( ++mj_num_jobs ))
> if [[ ${mj_num_jobs} -ge ${mj_max_jobs} ]] ; then
> multijob_finish_one
> fi
> return $?
> }
Minor note; the design of this (fork then check), means when a job
finishes, we'll not be ready with more work. This implicitly means
that given a fast job identification step (main thread), and a slower
job execution (what's backgrounded), we'll not breach #core of
parallelism, nor will we achieve that level either (meaning
potentially some idle cycles left on the floor).
Realistically, the main thread (what invokes post_fork) is *likely*,
(if the consumer isn't fricking retarded) to be doing minor work-
mostly just poking about figuring out what the next task/arguments
are to submit to the pool. That work isn't likely to be a full core
worth of work, else as I said, the consumer is being a retard.
The original form of this was designed around the assumption that the
main thread was light, and the backgrounded jobs weren't, thus it
basically did the equivalent of make -j<cores>+1, allowing #cores
background jobs running, while allowing the main thread to continue on
and get the next job ready, once it had that ready, it would block
waiting for a slot to open, then immediately submit the job once it
had done a reclaim.
On the surface of it, it's a minor difference, but having the next
job immediately ready to fire makes it easier to saturate cores.
Unfortunately, that also changes your API a bit; your call.
~harring
next prev parent reply other threads:[~2012-06-02 23:59 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-01 22:41 [gentoo-dev] multiprocessing.eclass: doing parallel work in bash Mike Frysinger
2012-06-01 22:50 ` Mike Frysinger
2012-06-02 4:11 ` Brian Harring
2012-06-02 4:57 ` Mike Frysinger
2012-06-02 9:23 ` Cyprien Nicolas
2012-06-02 9:52 ` David Leverton
2012-06-02 19:18 ` Mike Frysinger
2012-06-02 19:54 ` Mike Frysinger
2012-06-02 20:39 ` Zac Medico
2012-06-02 21:12 ` Mike Frysinger
2012-06-02 23:29 ` Zac Medico
2012-06-02 23:58 ` Mike Frysinger
2012-06-02 21:31 ` Michał Górny
2012-06-02 22:50 ` Zac Medico
2012-06-02 23:47 ` Brian Harring
2012-06-03 1:04 ` Zac Medico
2012-06-03 1:10 ` Zac Medico
2012-06-03 7:15 ` Michał Górny
2012-06-03 7:18 ` Zac Medico
2012-06-02 23:59 ` Brian Harring [this message]
2012-06-03 5:05 ` Mike Frysinger
2012-06-03 6:53 ` Zac Medico
2012-06-03 5:08 ` Mike Frysinger
2012-06-03 22:16 ` Zac Medico
2012-06-05 6:10 ` Mike Frysinger
2012-06-03 22:21 ` Zac Medico
2012-06-04 1:41 ` Zac Medico
2012-06-05 6:14 ` Mike Frysinger
2012-06-07 4:57 ` Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120602235902.GC9296@localhost \
--to=ferringb@gmail.com \
--cc=gentoo-dev@lists.gentoo.org \
--cc=vapier@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox