Lisp HUG Maillist Archive

Multithreading on multiple processor machine ...

Is Lispworks set up to make use of multiple processors?  I'm testing  
a multithreaded application on couple of machines (one with two  
processors and one with a single one) and there doesn't seem to be  
any difference in performance.  I sort of expected the dual processor  
machine to be faster, but maybe things don't work that way or maybe  
I'm using the mp package incorrectly ...

I don't have to use process-allow-scheduling explicitly in my code,  
right?  sleep should allow other processes to run too, right? All my  
threads are created with process-run-function, but the main thread is  
also being used for processing.

I'm running within Lispworks version 5.0 environment using default  
image with all the patches under OS X 10.4.11.

Thanks for your help.

-- Magda 


Re: Multithreading on multiple processor machine ...

On Tue, 15 Jan 2008 18:23:16 -0500, Magdalena Bugajska <magda@aic.nrl.navy.mil> wrote:

> Is Lispworks set up to make use of multiple processors?

No, not in the sense that several processors (or cores) can run Lisp
code from the same image at the same time:

  http://www.lispworks.com/documentation/lw50/LWUG/html/lwuser-192.htm

Edi.


Re: Multithreading on multiple processor machine ...


Magdalena Bugajska <magda@aic.nrl.navy.mil> writes:
> Is there any chance that it ever will? Seems like everything has
> multiple processors in it nowadays ...

You'll need to ask LispWorks, but I don't believe they have committed
to that feature.

> But I guess that explains the purpose of process-allow- 
> scheduling ...  

Not really. P-A-S is similar to pthread_yield in Posix threads and
allows a thread to explicitly and voluntary be interrupted instead of
waiting for the scheduler to do it.

> Although given that I have none in my program currently, that means
> that something else also controls interrupts.  What are the
> conditions under which processes are interrupted?  

To first order, it's the same conditions that allow any thread to be
interrupted.  Commonly, it will be because the current thread/process
time slice has expired.

> I.e. what determines the output of the following program?
> (let ((listener *standard-output*)) (mp:process-run-function
> "helloer" nil #'(lambda () (dotimes (n 100000) (format listener "~A"
> hello)))) (dotimes (n 100000) (format listener "~A" 'bye)))

The scheduler determines the output.  And in general HELLO will be
mixed in with BYE.  Here's my example with some time wasting code in
the middle:

    (defun run-2 (how-many)
      (let ((listener *standard-output*)) 
        (mp:process-run-function "helloer" nil 
                                 #'(lambda () (dotimes (n how-many)
                                                (format listener "hello ")
                                                (fact 100))))
        (dotimes (n how-many) 
          (format listener "bye ")
          (fact 10000))
        (sleep 1)
        (format listener"~&")))

    (defun fact (n)
      (if (< n 2)
          1
          (* n (fact (1- n)))))

Try (run-2 100) 

Cheers,
Chris Dean


Updated at: 2020-12-10 08:44 UTC