[R-SIG-Mac]more explanation

Jan de Leeuw deleeuw@stat.ucla.edu
Fri, 4 Jan 2002 11:25:54 -0800


R uses the BLAS for basic linear algebra operations, such as addition
and multiplication of vectors and matrices. This is just a library
of efficiently programmed routines for these operations that almost
all numerical software uses. R comes with its own version of the BLAS
in the source code.

Now it is clear that one could optimize the BLAS for a given architecture
by using information on the CPU (cache, latency, etc). This is what Sun
and IBM have done for their versions of the BLAS. But there is also a
portable self-optimizing version, which runs a large number of test
problems, modifies the BLAS source code, and then tries to optimize
the code for the processor it is building itself on. This is ATLAS, an
automatically optimized version of the BLAS. R uses ATLAS in the
building process, whenever it can find it (unless it is explicitly
instructed not to use it).

The version of ATLAS I use in building R is optimized for my machine,
which has two 800 MHz G4 CPU's. This is significant for two reasons:
Altivec and pthreads.

Altivec is only available on G4 processors, not on G3. Altivec uses
specialized vector registers on the G4 chip to load vectors of numbers,
which means that various operations can be carried out by the CPU on 
vectors
of numbers instead of on single numbers. This speeds up integer and
short floating point processing a great deal, but it requires special
coding.

Threading is mainly useful if one has more than one CPU on board. A
task (for instance a long loop) is split up in various threads of
execution, and each thread does its own part of the job. If you have
more than one CPU, the threads can run simultaneously. Again, this
requires special coding. Thread libraries are build into the basic
C library in OS X.

My version of ATLAS tells the compiler to generate Altivec instructions
and it also uses threading in the BLAS code. The G3 does not know what
to do with Altivec instructions. Threading is not really a problem,
although you do not get the benefits with a single CPU.

The solution to the problem is either to build a version of ATLAS which
does not use Altivec instructions, or to use the BLAS that comes with R.
Both are suboptimal. A better solutions is for everybody to build their
own R, using an ATLAS optimized for their machine. Once you have fink
installed, that's easy.

This is probably all irrelevant for the Carbon version, which does not 
use
ATLAS or multithreading.
===
Jan de Leeuw; Professor and Chair, UCLA Department of Statistics;
US mail: 9432 Boelter Hall, Box 951554, Los Angeles, CA 90095-1554
phone (310)-825-9550;  fax (310)-206-5658;  email: deleeuw@stat.ucla.edu
homepage: http://www.stat.ucla.edu/~deleeuw
========================================================
           No matter where you go, there you are. --- Buckaroo Banzai
                    http://www.stat.ucla.edu/~deleeuw/sounds/nomatter.au
========================================================