Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Weird problem with nested functions in Mata


From   "Ben Jann" <[email protected]>
To   <[email protected]>
Subject   RE: st: Weird problem with nested functions in Mata
Date   Thu, 13 Apr 2006 22:21:29 +0200

> I assume that there is a problem with my computer or OS.
> I'll check using another machine.

Here are some timings (the script can be found below):

L  (a)   (b)   (c)   (d)   (e)   (f)   (g)   (h)    (i)   (j)
0  2.21  1.80  2.12  1.94  2.02  3.71  1.49  11.50  3.28  2.34
1  3.68  3.55  2.10  1.93  2.03  3.73  1.47  11.50  3.29  2.36
2  2.18  1.79  2.10  1.93  2.02  3.73  1.46  11.51  5.08  2.33
3  3.64  3.96  2.10  1.90  2.02  3.75  1.47  11.42  3.45  2.34
4  2.19  1.80  2.10  1.91  2.03  3.73  1.50  11.34  3.30  2.35
5  3.92  3.01  2.83  2.63  2.70  3.84  1.48  11.34  3.28  2.34
6  2.19  1.80  2.10  1.91  2.02  3.94  1.50  11.34  3.31  2.34

Relative to L=0:
1  1.67  1.97  0.99  0.99  1.00  1.01  0.99  1.00   1.00  1.01
2  0.99  0.99  0.99  0.99  1.00  1.01  0.98  1.00   1.55  1.00
3  1.65  2.20  0.99  0.98  1.00  1.01  0.99  0.99   1.05  1.00
4  0.99  1.00  0.99  0.98  1.00  1.01  1.01  0.99   1.01  1.00
5  1.77  1.67  1.33  1.36  1.34  1.04  0.99  0.99   1.00  1.00
6  0.99  1.00  0.99  0.98  1.00  1.06  1.01  0.99   1.01  1.00

L = level of nesting

Processor and OS:
(a) Intel Centrino 1.3Ghz, Win XP SP2
(b) Intel Centrino 1.6Ghz, Win XP SP2
(c) Intel Pentium 4 3.0GHz, Win XP SP2
(d) Intel Pentium 4 3.8GHz, Win XP SP2
(e) Intel Xenon (dual) 3.3GHz, Win Server 2003 SP1
(f) PowerBook G4 1 GHz, Mac OS X 10.4.6
(g) xServe G5 (dual) 2.3 GHz, Mac OS X 10.4.5
(h) Sun Enterprise Server 450 (4 CPU), Solaris 9
(i) Intel Pentium 4 2.66GHz, Linux, Stata GUI
(j) Intel Pentium 4 2.66GHz, Linux, Stata Console

Stata:
(a-e) Stata/SE 9.1 for Windows
(f) Stata/SE 9.1 for Macintosh
(g-i) Stata/SE 9.1 for Unix
(j) Intercooled Stata 9.0 for Unix


Timings (a) are from my Intel Centrino (Dell) computer. 
Level 1 nesting is slow, level 2 is fast, level 3 is 
slow again, and so on. My colleagues Intel Centrino (HP) 
seems to have the same problem (b). A similar problems 
can be observed with Intel Pentium and Xenon. However, now
only level 5 nesting is slow!

On Mac OS things seem to be more or less ok (f, g). Same
an old Solaris (h). 

On Linux there seems to be a problem with level 2 
nesting if Stata GUI is used (i). No problem on Linux
with Stata console (j). (Although note that the last 
test uses Intercooled Stata 9.0 whereas all other tests
use Stata/SE 9.1.)

So the problem somehow seems to depend on OS and/or CPU,
although I cannot really make sense of it. One thing is 
clear to me, however: There is a serious problem at least
on Windows systems. And note that the speed loss caused 
by this problem is not peanuts. In my "real" application 
where I first observed the problem (density estimation), 
the command ran about 30% slower after I added an 
additional level of nesting somewhere in the program
(no, not within a loop).

Does anyone have an idea what exactly might cause the 
problem and whether there is a chance that it will be
fixed in near future or not?

ben

Thanks to Kit Baum, Ulrich Kohler, and Stefan Wehrli for 
running tests.


---test.do---------------------------
set rmsg on
mata:
real colvector test1(x) return(x:*x:*x:*x:*x)
real colvector test2(x) return(test1(x))
real colvector test3(x) return(test2(x))
real colvector test4(x) return(test3(x))
real colvector test5(x) return(test4(x))
real colvector test6(x) return(test5(x))
end

mata: x = uniform(10000,1)
mata: for (i=1;i<=1000;i++) {; z = x:*x:*x:*x:*x; }
mata: for (i=1;i<=1000;i++) {; z = test1(x); }
mata: for (i=1;i<=1000;i++) {; z = test2(x); }
mata: for (i=1;i<=1000;i++) {; z = test3(x); }
mata: for (i=1;i<=1000;i++) {; z = test4(x); }
mata: for (i=1;i<=1000;i++) {; z = test5(x); }
mata: for (i=1;i<=1000;i++) {; z = test6(x); }
--------------------------------------


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index