bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parallelism a la make -j <n> / GNU parallel


From: Greg Wooledge
Subject: Re: Parallelism a la make -j <n> / GNU parallel
Date: Thu, 3 May 2012 16:30:57 -0400
User-agent: Mutt/1.4.2.3i

On Thu, May 03, 2012 at 10:12:17PM +0200, John Kearney wrote:
>     function runJobParrell {
>         local mjobCnt=${1} && shift
>         jcnt=0
>         function WrapJob {
>             "${@}"
>             kill -s USR2 $$
>         }
>         function JobFinised {
>             jcnt=$((${jcnt}-1))
>         }
>         trap JobFinised USR2
>         while [ $# -gt 0 ] ; do
>             while [ ${jcnt} -lt ${mjobCnt} ]; do
>                 jcnt=$((${jcnt}+1))
>                 echo WrapJob "${1}" "${2}"
>                 WrapJob "${1}" "${2}" &
>                 shift 2
>         done
>         sleep 1
>         done
>     }
>     function testProcess {
>         echo "${*}"
>         sleep 1
>     }
>     runJobParrell 2  testProcess "jiji#" testProcess "jiji#" testProcess
> "jiji#"
> 
>     tends to work well enough.
> it gets a bit more complex if you want to recover output but not too much.

The real issue here is that there is no generalizable way to store an
arbitrary command for later execution.  Your example assumes that each
pair of arguments constitutes one simple command, which is fine if that's
all you need it to do.  But the next guy asking for this will want to
schedule arbitrarily complex shell pipelines and complex commands with
here documents and brace expansions and ....



reply via email to

[Prev in Thread] Current Thread [Next in Thread]