Thanks, I knew that some time ago but I didn't think about it, that makes much more sense then. | [reply] |
Thanks, the Alias module really made a big difference. It gives some strange errors in my multiprocessed code (using threads):
"thread x terminated abnormally: can't use an undefined value as a hash reference at [program_name] line [line with alias]", <[file I'm opening]> [random line]
It must be something involving the order in which alias and threads get around to doing that voodoo they do so well, because sometimes it works fine other times it gives errors. Oh well, it's a cool module I think I'll find many uses for it and it makes it fast enough that multiprocessing isn't really necessary.
| [reply] [d/l] |
| [reply] |
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. | [reply] [d/l] |