Everybody:

Thank you very much for your  advice. I believe that I have gotten the 
loops  working  now.

The method conductivity(), 2 million triangles
With loops expanded: 25.294999069 seconds (5253831296 bytes
With matrix operations: 29.744513256 seconds (6564763296

So now the loops  win by about 15%  of time consumed.

The key was apparently  to have  every single variable  declared. I'm not  
quite sure  how the compiler is able to pursue the tree of  interdependent 
modules to ferret out  the types, but I think it must have missed a few 
(the modules  properly declared  the types, but I'm not sure if the 
compiler  saw them). Therefore I believe  the loops were losing heavily  
compared to matrix operations.

So I went in and  declared  everything I could get my hands on. That made 
the loops competitive.

The moral of this story is: If you can't or  won't  declare every single 
variable, don't do loops. They are likely to be a losing proposition.

The updated code is at 
https://gist.github.com/PetrKryslUCSD/7bd14515e1a853275923

Petr

PS: One particular problem was  that I was calling the function  stored  
as  type  Function. Being new to the language,  I don't know if I can 
declare the function  to have a type  that would indicate the type of the 
return value. (Is it possible?) Without this information,  the compiler is 
apparently stuck with  data whose types need to be determined  at runtime. 
Unfortunately, the compiler  does not throw fits  when it does not know the 
type, and  then  bad things can happen  as in the present example  where 
expanding the loops  was  twice as slow  as doing a matrix operation.

Reply via email to