http://www.perlmonks.org?node_id=1051901


in reply to Re: Sharing statics variable between Threads
in thread Sharing statics variable between Threads

The sizes of @ysurf and @alfas are round about 10...15. $data->{count} more than 50.000.000. The count of center is thousands and more
  • Comment on Re^2: Sharing statics variable between Threads

Replies are listed 'Best First'.
Re^3: Sharing statics variable between Threads
by BrowserUk (Patriarch) on Sep 02, 2013 at 10:14 UTC

    Your code is full of silly inefficiencies; like these 3 calculations:

    $data->{magX}[ $dataIdx ] * cos( $data->{phX}[ $dataIdx ] ) $data->{magY}[ $dataIdx ] * cos( $data->{phY}[ $dataIdx ] ) $data->{magZ}[ $dataIdx ] * cos( $data->{phZ}[ $dataIdx ] )

    being performed for all 50 million $data points; and all 50 million being repeated for every one of the "thousands" of $center points. That's 3 * "thousands" * "50.000.000" of redundant, repeated calculations.

    Also, whilst I won't pretend to fully understand your code in isolation of what TransfNorVec(), coordSystTransf() & Check() subs do, it seems fairly clear you are checking a bunch of 3D points against another bunch of 3D points and accumulating statistics about how many of the former are within some distance of some of the latter.

    And you are going about it by brute force.

    With a clearer picture of the data (in $data (what an awful name) and $center), it ought to be possible to order (sort or structure -- perhaps 3-dimensionally) them, so that for any given $input only a small subset of the 'thousands by millions' of comparisons (and associated calculations) need be done.

    For example, if the point's X value is 50 and the radius of the compare is 5, there is no point in comparing against any other point who's X-value is outside of 45 thru 55. Sub-setting the larger range early could save billions of calculations, comparisons, object constructions and function calls.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      You are right, but is Perl effective and fast in sorting the data of the structure? There are functions to do it?
        but is Perl effective and fast in sorting the data of the structure?

        Honorable monk Salva provides numerous functions that can sort just about any perl structure, in just about any way possible, (almost) as fast as C; with a simple and intuitive interface.

        So, yes. Perl can order your data in what ever way you require and save you scads of time.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Sharing statics variable between Threads
by BrowserUk (Patriarch) on Sep 02, 2013 at 08:22 UTC

    Where does $data come from?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.