Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

perl threads and dual core hyper-threading

by JFarr (Sexton)
on Apr 25, 2006 at 22:01 UTC ( #545653=perlquestion: print w/replies, xml ) Need Help??

JFarr has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks I have an odd problem. We are running dual core pentium 4's with hyper-threading enabled. The perl scripts that we have run threads or multiple threads. And run just fine with the hyper-threading enabled. We ran into a machine with hyper-threading DISABLED, and the scripts did not even get off the ground. We had our first print statement execute, then the threads went into lala land. The threads are created and join'd as follows:
foreach $host (@syshosts) { threads->new(\&locateSysHost_Parallel, $host); } (threads->list)[0]->join while threads->list;
When we changed the join to
foreach $host (@syshosts) { threads->new(\&locateSysHost_Parallel, $host)->join; }
the threads ran as we expected. Has anyone else had these weird issues occur?

Replies are listed 'Best First'.
Re: perl threads and dual core hyper-threading
by liz (Monsignor) on Apr 25, 2006 at 22:10 UTC
    FWIW,
    foreach $host (@syshosts) { threads->new(\&locateSysHost_Parallel, $host)->join; }
    starts threads sequentially, since join waits until the thread is finished. So if there are issues with threads running simultaneously, then you're not testing that in this case.
Re: perl threads and dual core hyper-threading
by BrowserUk (Patriarch) on Apr 25, 2006 at 22:37 UTC

    This probably won't affect the outcome of your tests, which seem backward to me, but without seeing what you are doing in locateSysHost_Parallel() it's not really possible to comment on what might or might not be the causes of the symptoms you are seeing beyond liz's observation about your second example serialising the threads, but this line from your first snippet:

    (threads->list)[0]->join while threads->list;

    is a horribly inefficient way to do things.

    The first call to threads->list walks a linked list, constructing an object for each thread, expands the stack to accomodate it, and then pushes it on. It the returns to your code, where you promptly discard all but the first of them and call join on it.

    The second call repeats the process of walking the linked list, but because of the scalar context, skips building the list and just accumulates a count and returns it to you. Which you then promptly discard by turning the count into a boolean.

    You then repeat the above two steps for each thread running. That's is a O(2n!) (factorial) O(n*(n-1)) process where n is the number of threads. The following is simply O(n).

    $_->join for threads->list;
    and the scripts did not even get off the ground. We had our first print statement execute, then the threads went into lala land.

    "did not get off the ground" and "lala land" are not very useful descriptions for attempting to diagnose a problem from :). A cut down script that demonstrates the problem would be much more useful.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      That's is a O(2n!) (factorial) process where n is the number of threads.

      It's just a minor detail (since O(n) is much better than O(n^2)), but I don't see where you get that factorial.

      O( 2n + 2(n-1) + 2(n-2) + ... + 2(2) + 2(1) ) 2n + 2(n-1) + 2(n-2) + ... + 2(2) + 2(1) = 2(n + n-1 + n-2 + ... + 2 + 1) = 2(n*(n+1)/2) = n^2 + n = O( n^2 + n ) = O( n^2 )

      Or if you ignore the fact that the list is shrinking:

      O( n * 2n ) = O( 2n^2 ) = O( n^2 )

        You're right. It's additive not multiplicative, so O(n*(n-1)). Near as damn it n^2 as you said. Still bloody wasteful ;)


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://545653]
Approved by ikegami
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2023-05-31 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?