BroswerUK, Sorry to keep this thread going but could you give a little more detail about this?

The code above is part of the subroutine &find_symmetry which the "threads" execute. I feed the threads input data, a string, from a queue and they output a hash ref to another queue. Other than the queues, the threads do not share variables between them. I would like them to be able to use the alias functionality shown above in that portion of code, which is part of &find_symmetry. So to me, I'm not wanting to alias across threads but rather within threads? Is this impossible?

More confusing to me, sometimes they will work fine if I keep retrying to run the script. They either fail very early or it will work fine and the output from the program is correct. I don't understand this, I would understand if it always failed or always worked, but on the same input every time, the sometimes working behavior confuses me. I think this requires sharing the code for the subroutine to give some context, there is more but all of the aliasing would be within here. Basically the input queue has a list of files, each thread opens the file, parses the file and makes the $compound hash ref. This is given to two subs to make Mapping and Adjacency, then to &find_symmetry, then the ref is placed on the output queue.

sub find_symmetry { my $compound = shift @_; $$compound{Symmetries} = []; my $M_matrix = $$compound{Mapping}; my $A_matrix = $$compound{Adjacency}; my @isomorphs; my $row = 0; my $dimension = $#$A_matrix; my @indices = (0..$dimension); my @reverse = reverse @indices; my @used = map {0;} (@indices); my @mapping = map {-1;} (@indices); my (@sm_rows, @same_rows); foreach my $row (@$A_matrix) { push @sm_rows, $row; } foreach my $row (@$M_matrix) { push @same_rows, $row;} my $equate_sub = sub { for (reverse(0..$row)) { my (@smrow, @omrow); alias @smrow = @{$sm_rows[$_]}; alias @omrow = @{$sm_rows[$mapping[$_]]}; for (0..$row) { if ($smrow[$_] != $omrow[$mapping[$_]]) { return 0; } } } return 1; }; LOOP: while(1) { do { $mapping[$row] ++ } while ( $mapping[$row] <= $dimension and +($used[$mapping[$row]] == 1 || $same_rows[$row][$mapping[$row]] == 0 +)); next if ($mapping[$row] > $dimension); if ( $row == $dimension ) { OUTER: { for (@indices) { my (@smrow2, @omrow2); alias @smrow2 = @{$sm_rows[$_]}; alias @omrow2 = @{$sm_rows[$mapping[$_]]}; for (@reverse) { if ( $smrow2[$_] != $omrow2[$mapping[$_]] ) { last OUTER; } } } push @{$$compound{Symmetries}}, [@mapping]; # print join(",",@mapping), "\n"; } } elsif ( $row == 0 or &$equate_sub == 1 ) { $used[$mapping[$row]] = 1; $row++; } } continue { while ( $row >= 0 and $mapping[$row] >= $dimension ) { last LOOP if ($row == 0); $mapping[$row] = -1; $row --; $used[$mapping[$row]] = 0; } } $$compound{Mapping} = undef; $$compound{Adjacency} = undef; # return \@isomorphs; }

Any clarity you can give on this would be great, threads always confuse me with what sometimes works with them and what sometimes won't. They are really useful but sometimes annoying.


In reply to Re^4: Dereferencing Performance - Confused by Results by jmmitc06
in thread Dereferencing Performance - Confused by Results by jmmitc06

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.