performance - Perl fast matrix multiply -


i have implemented following statistical computation in perl http://en.wikipedia.org/wiki/fisher_information.
results correct. know because have 100's of test cases match input , output. problem need compute many times every single time run script. average number of calls function around 530. used devel::nytprof find out out slow parts are. have optimized algorithm traverse top half of matrix , reflect onto bottom same. i'm not perl expert, need know if there can try speed perl. script distributed clients compiling c file not option. there perl library can try? needs sub second in speed if possible.

more information $matrixref matrix of floating point numbers $rows $variables. here nytprof dump function.

#----------------------------------------------- # #----------------------------------------------- sub computexpx # spent 4.27s within computexpx called 526 times, avg 8.13ms/call: # 526 times (4.27s+0s) computeefficiency @ line 7121, avg 8.13ms/call { 526 0s                  ($matrixref, $rows, $variables) = @_;  526 0s                  $r = 0; 526 0s                  $c = 0; 526 0s                  $k = 0; 526 0s                  $sum = 0; 526 0s                  @xpx = ();  526 11.0ms              ($r = 0; $r < $variables; $r++)                         { 14202   19.0ms                @temp = (0) x $variables; 14202   6.01ms                push(@xpx, \@temp); 526 0s                  } 526 7.01ms              ($r = 0; $r < $variables; $r++)                         { 14202   144ms                   ($c = $r; $c < $variables; $c++)                                 { 198828  43.0ms                                  $sum = 0;                                         #for ($k = 0; $k < $rows; $k++) 198828  101ms                           foreach $rowref (@{$matrixref})                                         {                                                 #$sum += $matrixref->[$k]->[$r]*$matrixref->[$k]->[$c]; 6362496 3.77s                                   $sum += $rowref->[$r]*$rowref->[$c];                                         }  198828  80.1ms                                  $xpx[$r]->[$c] = $sum;                                                 #reflect on other side of matrix 198828  82.1ms                                  $xpx[$c]->[$r] = $sum if ($r != $c); 14202   1.00ms                          } 526 2.00ms                  }  526 2.00ms                  return \@xpx; } 

since each element of result matrix can calculated independently, should possible calculate some/all of them in parallel. in other words, none of instances of innermost loop depend on results of other, run simultaneously on own threads.


Comments