Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: perl threads and dual core hyper-threading

by BrowserUk (Patriarch)
on Apr 25, 2006 at 22:37 UTC ( [id://545656]=note: print w/replies, xml ) Need Help??


in reply to perl threads and dual core hyper-threading

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.

Replies are listed 'Best First'.
Re^2: perl threads and dual core hyper-threading
by ikegami (Patriarch) on Apr 25, 2006 at 22:57 UTC
    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: note [id://545656]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found