From: Victor Kryukov
Subject: Using both cores on Intel Mac with SBCL
Date: 
Message-ID: <1172953432.117144.175590@8g2000cwh.googlegroups.com>
Hey group,

I'm doing some heavy calculations with SBCL on Mac, and I observed
that SBCL utilizes only one CPU core. I assume that for utilizing both
of them, I need to manually start another thread inside my lisp
program, and make sure that calculations are distributed among the
threads - e.g. none of the processes makes the same calculation twice.

I never done multiprocessor programming before; could anybody provide
any example of lisp code utilizing several CPUs that I could use as a
starting point for my own program?

Many thanks,
Victor.

From: ············@gmail.com
Subject: Re: Using both cores on Intel Mac with SBCL
Date: 
Message-ID: <1173036799.702638.215600@p10g2000cwp.googlegroups.com>
On Mar 3, 12:23 pm, "Victor Kryukov" <··············@gmail.com> wrote:
> I'm doing some heavy calculations with SBCL on Mac, and I observed
> that SBCL utilizes only one CPU core. I assume that for utilizing both
> of them, I need to manually start another thread inside my lisp
> program, and make sure that calculations are distributed among the
> threads - e.g. none of the processes makes the same calculation twice.

That's right:  the standard approach to parallel programming is to
deal with explicit threads / processes.  Lisp is not in itself a
parallel programming language, although it could (and has in the
past!) be extended to include parallel programming constructs.
"Automatic parallelization" is a hard research topic and probably
isn't in your compiler.  (OpenMP offers "semi-automatic
parallelization" for C and Fortran programs; you still have to direct
the compiler with little #pragmas in your code.)

> I never done multiprocessor programming before; could anybody provide
> any example of lisp code utilizing several CPUs that I could use as a
> starting point for my own program?

What you might want to do first is read something about parallel
programming that's somewhat language-independent.  It's chock full of
traps for the inexperienced and unwary:  deadlocks, race conditions,
and the like (these are bad things).  What you want is probably a book
on shared-memory (as opposed to distributed-memory) parallel coding,
as you are working with threads within a single instance of SBCL.

Hey, does anybody out there have a recommendation for such a book?  I
do mostly distributed-memory hacking myself.

mfh
From: Victor Kryukov
Subject: Re: Using both cores on Intel Mac with SBCL
Date: 
Message-ID: <1173150005.919539.74880@h3g2000cwc.googlegroups.com>
On Mar 4, 1:33 pm, ·············@gmail.com" <············@gmail.com>
wrote:

> What you might want to do first is read something about parallel
> programming that's somewhat language-independent.  It's chock full of
> traps for the inexperienced and unwary:  deadlocks, race conditions,
> and the like (these are bad things).  What you want is probably a book
> on shared-memory (as opposed to distributed-memory) parallel coding,
> as you are working with threads within a single instance of SBCL.
>
> Hey, does anybody out there have a recommendation for such a book?  I
> do mostly distributed-memory hacking myself.
>
> mfh

Thanks, Mark - I'll try to find some reading in a library.

Best,
Victor.
From: George Neuner
Subject: Re: Using both cores on Intel Mac with SBCL
Date: 
Message-ID: <00spu2dd8ish2619vr9m1m864org16kfj2@4ax.com>
On 4 Mar 2007 11:33:19 -0800, ·············@gmail.com"
<············@gmail.com> wrote:

>What you might want to do first is read something about parallel
>programming that's somewhat language-independent.  It's chock full of
>traps for the inexperienced and unwary:  deadlocks, race conditions,
>and the like (these are bad things).  What you want is probably a book
>on shared-memory (as opposed to distributed-memory) parallel coding,
>as you are working with threads within a single instance of SBCL.
>
>Hey, does anybody out there have a recommendation for such a book?  I
>do mostly distributed-memory hacking myself.

Most books that are both about "parallel programming" and language
neutral tend to focus on algorithms and program architecture rather
than the issues of communication and synchronization.

I have found much better discussions of the issues of shared memory
parallel programming are found in books on operating systems, albeit
seen from a different perspective.  But I have found that people who
know what's going on under the hood make better programmers.


Tanenbaum's "Operating Systems Concepts" has good discussions of
threading and shared data structure access.  His "Minix" books have
less theory but show gory details of implementation (in C) from the
Minix OS and walk the reader through the problems and solutions.

Comer's XINU books are similar to the "Minix" books but go even
heavier on implementation detail (also in C) with walk-throughs and
just enough theory to get you thinking.  Comer covers everything but I
think Tanenbaum's treatment in the "Minix" books is more balanced.

Bach's "Design of the Unix Operating System" is relatively easy
reading and a good balance between theory and implementation example.

Mullender's "Distributed Systems", while geared to separate memory
systems, has excellent abstract discussions of program global state,
scheduling, communication, synchronization, replication and fault
tolerance.  Highly recommended as a concept book.

YMMV.
George
--
for email reply remove "/" from address
From: Alex Mizrahi
Subject: Re: Using both cores on Intel Mac with SBCL
Date: 
Message-ID: <45eda4da$0$90268$14726298@news.sunsite.dk>
(message (Hello 'Victor)
(you :wrote  :on '(3 Mar 2007 12:23:52 -0800))
(

 VK> I never done multiprocessor programming before; could anybody provide
 VK> any example of lisp code utilizing several CPUs that I could use as a
 VK> starting point for my own program?

uh, some people sent you to the library, but i'd say you opposite -- in 
simple cases multithreading is very simple.
just spawn a new thread -- (sb-thread:make-thread function )
that's actually all.. you can find full examples in SBCL's documentation 
[1].

you have more problems when you try to get result from thread :). and when 
you have some shared data.
if both threads are reading shared data, that's ok. if one or both threads 
are writing -- you can have problems, unless you use synchronization.

in simple cases synchronization is very simple -- create a mutex object, and 
lock it each time you want to access (read or write) some shared data.

in many cases producer/consumer threading pattern is very helpful. it's not 
that hard to implement -- you can find and example in SBCL manual page about 
waitqueue.

in general, SBCL threading manual [1] would be enough to do some simple 
cases of threading. but if you'd need some complex scenarios, you'd need to 
read some books.

i think you can post a brief description of your algorithms here. we can 
check if multiprocessing would be simple in your case or not, what patterns 
you should read about etc.

it's very tricky in interactive, mission-critical applications. but if 
that's just some computation that you can restart in case of failure, you 
can freely experiment with this..

[1]: http://www.sbcl.org/manual/Threading.html

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"?? ???? ??????? ?????") 
From: Victor Kryukov
Subject: Re: Using both cores on Intel Mac with SBCL
Date: 
Message-ID: <1173327806.631967.256740@t69g2000cwt.googlegroups.com>
On Mar 6, 11:28 am, "Alex Mizrahi" <········@users.sourceforge.net>
wrote:
> (message (Hello 'Victor)
> (you :wrote  :on '(3 Mar 2007 12:23:52 -0800))
> (
>
>  VK> I never done multiprocessor programming before; could anybody provide
>  VK> any example of lisp code utilizing several CPUs that I could use as a
>  VK> starting point for my own program?
>
> uh, some people sent you to the library, but i'd say you opposite -- in
> simple cases multithreading is very simple.
> just spawn a new thread -- (sb-thread:make-thread function )
> that's actually all.. you can find full examples in SBCL's documentation
> [1].
>
> you have more problems when you try to get result from thread :). and when
> you have some shared data.
> if both threads are reading shared data, that's ok. if one or both threads
> are writing -- you can have problems, unless you use synchronization.
>
> in simple cases synchronization is very simple -- create a mutex object, and
> lock it each time you want to access (read or write) some shared data.
>
> in many cases producer/consumer threading pattern is very helpful. it's not
> that hard to implement -- you can find and example in SBCL manual page about
> waitqueue.
>
> in general, SBCL threading manual [1] would be enough to do some simple
> cases of threading. but if you'd need some complex scenarios, you'd need to
> read some books.
>
> i think you can post a brief description of your algorithms here. we can
> check if multiprocessing would be simple in your case or not, what patterns
> you should read about etc.
>
> it's very tricky in interactive, mission-critical applications. but if
> that's just some computation that you can restart in case of failure, you
> can freely experiment with this..
>
> [1]:http://www.sbcl.org/manual/Threading.html
>
> )
> (With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
> "?? ???? ??????? ?????")


Thanks a lot, Alex - the manual is really helpful!

Best,
Victor
From: Nicolas Neuss
Subject: Re: Using both cores on Intel Mac with SBCL
Date: 
Message-ID: <87wt1q4won.fsf@ma-patru.mathematik.uni-karlsruhe.de>
"Victor Kryukov" <··············@gmail.com> writes:

> On Mar 6, 11:28 am, "Alex Mizrahi" <········@users.sourceforge.net>
> wrote:
> > (message (Hello 'Victor)
> > (you :wrote  :on '(3 Mar 2007 12:23:52 -0800))
> > (
> >
> >  VK> I never done multiprocessor programming before; could anybody provide
> >  VK> any example of lisp code utilizing several CPUs that I could use as a
> >  VK> starting point for my own program?

Almost a year ago, I asked the same question on the SBCL list.  Juho gave
me an example which worked just fine:

<http://sourceforge.net/mailarchive/message.php?msg_id=15278788>

Yours, Nicolas
From: Victor Kryukov
Subject: Re: Using both cores on Intel Mac with SBCL
Date: 
Message-ID: <1173592277.944738.134900@64g2000cwx.googlegroups.com>
On Mar 9, 3:02 am, Nicolas Neuss <········@mathematik.uni-
karlsruhe.de> wrote:
> "Victor Kryukov" <··············@gmail.com> writes:
> > On Mar 6, 11:28 am, "Alex Mizrahi" <········@users.sourceforge.net>
> > wrote:
> > > (message (Hello 'Victor)
> > > (you :wrote  :on '(3 Mar 2007 12:23:52 -0800))
> > > (
>
> > >  VK> I never done multiprocessor programming before; could anybody provide
> > >  VK> any example of lisp code utilizing several CPUs that I could use as a
> > >  VK> starting point for my own program?
>
> Almost a year ago, I asked the same question on the SBCL list.  Juho gave
> me an example which worked just fine:
>
> <http://sourceforge.net/mailarchive/message.php?msg_id=15278788>
>
> Yours, Nicolas

Thanks, Nicolas - that works fine for me.