zsh-users
 help / color / mirror / code / Atom feed
From: "Thomas Köhler" <jean-luc@picard.franken.de>
To: zsh-users@sunsite.auc.dk
Subject: Re: Prompt expansion, multi-job for
Date: Thu, 6 Jan 2000 15:19:42 +0100	[thread overview]
Message-ID: <20000106151942.A18295@picard.franken.de> (raw)
In-Reply-To: <3874847D.A2ED4AE3@u.genie.co.uk>; from opk@u.genie.co.uk on Thu, Jan 06, 2000 at 01:04:55PM +0100

On Thu, Jan 06, 2000 at 01:04:55PM +0100,
Oliver Kiddle <opk@u.genie.co.uk> wrote:
> 
> Andre Pang wrote:
> 
> >     2) Is there any way to emulate make's -jn option in the for command?
> > This would be *really* useful for SMP systems.  Currently, doing something
> > like "for i in ***/***.wav; do l3enc $i; done" doesn't take advantage of
> > multiple CPUs (on a Linux system, at least); hacking the for command to
> > accept a 'make -j'-like parameter (eg: for -j2 i in *; do l3enc $i; done)
> > would allow us lucky ones who have SMP systems to do many things similar to
> > the above without going mad and writing silly Makefiles simply so we can
> > utilise make -j.  If someone's written a function to do this already (Bart?
> > ;) it'd be *very* cool.
> 
> If I'm not mistaken, you should be able to do this by running l3enc as a
> background process, i.e. for i in *.wav; do l3enc $i& done. I haven't
> got an SMP system available to me to test but I'd assume that it would
> allocate different l3enc processes to different processors. Putting the
> process in the background means that zsh will get control back
> straight-away and can run the next l3enc.

Well, bad idea if you have a few hundred wavs :)

> The trouble with this is that it will attempt to run all the l3encs
> together. If you have say 4 processors, it may be most efficient to run
> a maximum of 4 l3encs at once. This would be a bit messy to implement in
> Zsh (compared to something like Ada) but can be done.

Well - let's try something like this:

for i in **/*.wav ; do jspool l3enc "'$i'" ; done
jrun 4

Now, we need jspool and jrun. jspool is simple:
function jspool() {
   print $@ >> ~/.zjspool/jobs
}

Now, jrun:
function jrun() {
   print rm -f ~/.zjspool/jobs >> ~/.zjspool/jobs
   print 1 > ~/.zjspool/current
   i=0
   while [ $i -lt $1 ] ; do
      zjrun $i &!
      i=$[i+1]
   done
}

zjrun is a shell script:

#!/usr/bin/zsh
while : ; do
   sleep 1
   while [ -f ~/.zjspool/lock ] ; do sleep 5 ; done
   print $$ >> ~/.zjspool/lock
   PID=$(head -1 ~/.zjspool/lock)
   if [ $PID -ne $$ ] ; then continue ; fi
   LINE=$(cat ~/.zjspool/current)
   if [ ! -f ~/.zjspool/jobs ] ; then
      rm -f ~/.zjspool/lock
      exit
   fi
   JOB=$(head -$LINE ~/.zjspool/jobs | tail -1)
   print $[LINE + 1] > ~/.zjspool/current
   rm -f ~/.zjspool/lock
   print -n "$1: "
   eval $JOB
done

You get the idea...

Ah - you have 4 jobs running, but you want another important job to run
in between?
echo "XXX" > ~/.zjspool/lock
wait for the 4 running jobs to finish
run your important other stuff 
rm ~/.zjspool/lock

> Oliver Kiddle

CU,
Thomas

-- 
 Thomas Köhler Email:   jean-luc@picard.franken.de   | LCARS - Linux for
     <><        WWW:  http://home.pages.de/~jeanluc/ | Computers on All
                IRC:             jeanluc             | Real Starships
   PGP public key: http://www.mayn.de/users/jean-luc/PGP-Public.asc


  reply	other threads:[~2000-01-06 14:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-06  8:44 Andre Pang
2000-01-06 12:03 ` Oliver Kiddle
2000-01-06 14:19   ` Thomas Köhler [this message]
2000-01-06 15:21     ` Oliver Kiddle
     [not found]       ` <14452.47479.5744.410474@gargle.gargle.HOWL>
2000-01-06 17:47         ` Oliver Kiddle
2000-01-09  0:59       ` Bart Schaefer
2000-01-06 14:54   ` Andre Pang
2000-01-06 12:44 ` Andrej Borsenkow
2000-01-06 14:46   ` Andre Pang
2000-01-06 20:18 ` Peter Stephenson
2000-01-06 11:41 Sven Wischnowsky

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=20000106151942.A18295@picard.franken.de \
    --to=jean-luc@picard.franken.de \
    --cc=zsh-users@sunsite.auc.dk \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).