home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 1: Linux / CD1.iso / doc / HOWTO / Parallel-Processing-HOWTO < prev    next >
Text File  |  1998-10-14  |  194KB  |  4,040 lines

  1.   Linux Parallel Processing HOWTO
  2.   Hank Dietz, pplinux@ecn.purdue.edu
  3.   v980105, 5 January 1998
  4.  
  5.   Parallel Processing refers to the concept of speeding-up the execution
  6.   of a program by dividing the program into multiple fragments that can
  7.   execute simultaneously, each on its own processor.  A program being
  8.   executed across N processors might execute N times faster than it
  9.   would using a single processor.  This document discusses the four
  10.   basic approaches to parallel processing that are available to Linux
  11.   users:  SMP Linux systems, clusters of networked Linux systems, paral¡
  12.   lel execution using multimedia instructions (i.e., MMX), and attached
  13.   (parallel) processors hosted by a Linux system.
  14.  
  15.   1.  Introduction
  16.  
  17.   Parallel Processing refers to the concept of speeding-up the execution
  18.   of a program by dividing the program into multiple fragments that can
  19.   execute simultaneously, each on its own processor.  A program being
  20.   executed across n processors might execute n times faster than it
  21.   would using a single processor.
  22.  
  23.   Traditionally, multiple processors were provided within a specially
  24.   designed "parallel computer"; along these lines, Linux now supports
  25.   SMP systems (often sold as "servers") in which multiple processors
  26.   share a single memory and bus interface within a single computer.  It
  27.   is also possible for a group of computers (for example, a group of PCs
  28.   each running Linux) to be interconnected by a network to form a
  29.   parallel-processing cluster.  The third alternative for parallel
  30.   computing using Linux is to use the multimedia instruction extensions
  31.   (i.e., MMX) to operate in parallel on vectors of integer data.
  32.   Finally, it is also possible to use a Linux system as a "host" for a
  33.   specialized attached parallel processing compute engine.  All these
  34.   approaches are discussed in detail in this document.
  35.  
  36.   1.1.  Is Parallel Processing What I Want?
  37.  
  38.   Although use of multiple processors can speed-up many operations, most
  39.   applications cannot yet benefit from parallel processing.  Basically,
  40.   parallel processing is appropriate only if:
  41.  
  42.   ╖  Your application has enough parallelism to make good use of
  43.      multiple processors.  In part, this is a matter of identifying
  44.      portions of the program that can execute independently and
  45.      simultaneously on separate processors, but you will also find that
  46.      some things that could execute in parallel might actually slow
  47.      execution if executed in parallel using a particular system.  For
  48.      example, a program that takes four seconds to execute within a
  49.      single machine might be able to execute in only one second of
  50.      processor time on each of four machines, but no speedup would be
  51.      achieved if it took three seconds or more for these machines to
  52.      coordinate their actions.
  53.  
  54.   ╖  Either the particular application program you are interested in
  55.      already has been parallelized (rewritten to take advantage of
  56.      parallel processing) or you are willing to do at least some new
  57.      coding to take advantage of parallel processing.
  58.  
  59.   ╖  You are interested in researching, or at least becoming familiar
  60.      with, issues involving parallel processing.  Parallel processing
  61.      using Linux systems isn't necessarily difficult, but it is not
  62.      familiar to most computer users, and there isn't any book called
  63.      "Parallel Processing for Dummies"...  at least not yet.  This HOWTO
  64.      is a good starting point, not all you need to know.
  65.  
  66.   The good news is that if all the above are true, you'll find that
  67.   parallel processing using Linux can yield supercomputer performance
  68.   for some programs that perform complex computations or operate on
  69.   large data sets.  What's more, it can do that using cheap hardware...
  70.   which you might already own.  As an added bonus, it is also easy to
  71.   use a parallel Linux system for other things when it is not busy
  72.   executing a parallel job.
  73.  
  74.   If parallel processing is not what you want, but you would like to
  75.   achieve at least a modest improvement in performance, there are still
  76.   things you can do.  For example, you can improve performance of
  77.   sequential programs by moving to a faster processor, adding memory,
  78.   replacing an IDE disk with fast wide SCSI, etc.  If that's all you are
  79.   interested in, jump to section 6.2; otherwise, read on.
  80.  
  81.   1.2.  Terminology
  82.  
  83.   Although parallel processing has been used for many years in many
  84.   systems, it is still somewhat unfamiliar to most computer users.
  85.   Thus, before discussing the various alternatives, it is important to
  86.   become familiar with a few commonly used terms.
  87.  
  88.      SIMD:
  89.         SIMD (Single Instruction stream, Multiple Data stream) refers to
  90.         a parallel execution model in which all processors execute the
  91.         same operation at the same time, but each processor is allowed
  92.         to operate upon its own data.  This model naturally fits the
  93.         concept of performing the same operation on every element of an
  94.         array, and is thus often associated with vector or array
  95.         manipulation.  Because all operations are inherently
  96.         synchronized, interactions among SIMD processors tend to be
  97.         easily and efficiently implemented.
  98.  
  99.      MIMD:
  100.         MIMD (Multiple Instruction stream, Multiple Data stream) refers
  101.         to a parallel execution model in which each processor is
  102.         essentially acting independently.  This model most naturally
  103.         fits the concept of decomposing a program for parallel execution
  104.         on a functional basis; for example, one processor might update a
  105.         database file while another processor generates a graphic
  106.         display of the new entry.  This is a more flexible model than
  107.         SIMD execution, but it is achieved at the risk of debugging
  108.         nightmares called race conditions, in which a program may
  109.         intermittently fail due to timing variations reordering the
  110.         operations of one processor relative to those of another.
  111.  
  112.      SPMD:
  113.         SPMD (Single Program, Multiple Data) is a restricted version of
  114.         MIMD in which all processors are running the same program.
  115.         Unlike SIMD, each processor executing SPMD code may take a
  116.         different control flow path through the program.
  117.  
  118.      Communication Bandwidth:
  119.         The bandwidth of a communication system is the maximum amount of
  120.         data that can be transmitted in a unit of time...  once data
  121.         transmission has begun.  Bandwidth for serial connections is
  122.         often measured in baud or bits/second (b/s), which generally
  123.         correspond to 1/10 to 1/8 that many Bytes/second (B/s).  For
  124.         example, a 1,200 baud modem transfers about 120 B/s, whereas a
  125.         155 Mb/s ATM network connection is nearly 130,000 times faster,
  126.         transferring about about 17 MB/s.  High bandwidth allows large
  127.         blocks of data to be transferred efficiently between processors.
  128.  
  129.      Communication Latency:
  130.         The latency of a communication system is the minimum time taken
  131.         to transmit one object, including any send and receive software
  132.         overhead.  Latency is very important in parallel processing
  133.         because it determines the minimum useful grain size, the minimum
  134.         run time for a segment of code to yield speed-up through
  135.         parallel execution.  Basically, if a segment of code runs for
  136.         less time than it takes to transmit its result value (i.e.,
  137.         latency), executing that code segment serially on the processor
  138.         that needed the result value would be faster than parallel
  139.         execution; serial execution would avoid the communication
  140.         overhead.
  141.  
  142.      Message Passing:
  143.         Message passing is a model for interactions between processors
  144.         within a parallel system.  In general, a message is constructed
  145.         by software on one processor and is sent through an
  146.         interconnection network to another processor, which then must
  147.         accept and act upon the message contents.  Although the overhead
  148.         in handling each message (latency) may be high, there are
  149.         typically few restrictions on how much information each message
  150.         may contain.  Thus, message passing can yield high bandwidth
  151.         making it a very effective way to transmit a large block of data
  152.         from one processor to another.  However, to minimize the need
  153.         for expensive message passing operations, data structures within
  154.         a parallel program must be spread across the processors so that
  155.         most data referenced by each processor is in its local memory...
  156.         this task is known as data layout.
  157.  
  158.      Shared Memory:
  159.         Shared memory is a model for interactions between processors
  160.         within a parallel system.  Systems like the multi-processor
  161.         Pentium machines running Linux physically share a single memory
  162.         among their processors, so that a value written to shared memory
  163.         by one processor can be directly accessed by any processor.
  164.         Alternatively, logically shared memory can be implemented for
  165.         systems in which each processor has it own memory by converting
  166.         each non-local memory reference into an appropriate inter-
  167.         processor communication.  Either implementation of shared memory
  168.         is generally considered easier to use than message passing.
  169.         Physically shared memory can have both high bandwidth and low
  170.         latency, but only when multiple processors do not try to access
  171.         the bus simultaneously; thus, data layout still can seriously
  172.         impact performance, and cache effects, etc., can make it
  173.         difficult to determine what the best layout is.
  174.  
  175.      Aggregate Functions:
  176.         In both the message passing and shared memory models, a
  177.         communication is initiated by a single processor; in contrast,
  178.         aggregate function communication is an inherently parallel
  179.         communication model in which an entire group of processors act
  180.         together.  The simplest such action is a barrier
  181.         synchronization, in which each individual processor waits until
  182.         every processor in the group has arrived at the barrier.  By
  183.         having each processor output a datum as a side-effect of
  184.         reaching a barrier, it is possible to have the communication
  185.         hardware return a value to each processor which is an arbitrary
  186.         function of the values collected from all processors.  For
  187.         example, the return value might be the answer to the question
  188.         "did any processor find a solution?"  or it might be the sum of
  189.         one value from each processor.  Latency can be very low, but
  190.         bandwidth per processor also tends to be low.  Traditionally,
  191.         this model is used primarily to control parallel execution
  192.         rather than to distribute data values.
  193.  
  194.      Collective Communication:
  195.         This is another name for aggregate functions, most often used
  196.         when referring to aggregate functions that are constructed using
  197.         multiple message-passing operations.
  198.  
  199.      SMP:
  200.         SMP (Symmetric Multi-Processor) refers to the operating system
  201.         concept of a group of processors working together as peers, so
  202.         that any piece of work could be done equally well by any
  203.         processor.  Typically, SMP implies the combination of MIMD and
  204.         shared memory.  In the IA32 world, SMP generally means compliant
  205.         with MPS (the Intel MultiProcessor Specification); in the
  206.         future, it may mean "Slot 2"....
  207.  
  208.      SWAR:
  209.         SWAR (SIMD Within A Register) is a generic term for the concept
  210.         of partitioning a register into multiple integer fields and
  211.         using register-width operations to perform SIMD-parallel
  212.         computations across those fields.  Given a machine with k-bit
  213.         registers, data paths, and function units, it has long been
  214.         known that ordinary register operations can function as SIMD
  215.         parallel operations on as many as n, k/n-bit, field values.
  216.         Although this type of parallelism can be implemented using
  217.         ordinary integer registers and instructions, many high-end
  218.         microprocessors have recently added specialized instructions to
  219.         enhance the performance of this technique for multimedia-
  220.         oriented tasks.  In addition to the Intel/AMD/Cyrix MMX
  221.         (MultiMedia eXtensions), there are: Digital Alpha MAX
  222.         (MultimediA eXtensions), Hewlett-Packard PA-RISC MAX (Multimedia
  223.         Acceleration eXtensions), MIPS MDMX (Digital Media eXtension,
  224.         pronounced "Mad Max"), and Sun SPARC V9 VIS (Visual Instruction
  225.         Set).  Aside from the three vendors who have agreed on MMX, all
  226.         of these instruction set extensions are roughly comparable, but
  227.         mutually incompatible.
  228.  
  229.      Attached Processors:
  230.         Attached processors are essentially special-purpose computers
  231.         that are connected to a host system to accelerate specific types
  232.         of computation.  For example, many video and audio cards for PCs
  233.         contain attached processors designed, respectively, to
  234.         accelerate common graphics operations and audio DSP (Digital
  235.         Signal Processing).  There is also a wide range of attached
  236.         array processors, so called because they are designed to
  237.         accelerate arithmetic operations on arrays.  In fact, many
  238.         commercial supercomputers are really attached processors with
  239.         workstation hosts.
  240.  
  241.      RAID:
  242.         RAID (Redundant Array of Inexpensive Disks) is a simple
  243.         technology for increasing both the bandwidth and reliability of
  244.         disk I/O.  Although there are many different variations, all
  245.         have two key concepts in common.  First, each data block is
  246.         striped across a group of n+k disk drives such that each drive
  247.         only has to read or write 1/n of the data...  yielding n times
  248.         the bandwidth of one drive.  Second, redundant data is written
  249.         so that data can be recovered if a disk drive fails; this is
  250.         important because otherwise if any one of the n+k drives were to
  251.         fail, the entire file system could be lost.  A good overview of
  252.         RAID in general is given at  <http://www.dpt.com/uraiddoc.html>,
  253.         and information about RAID options for Linux systems is at
  254.         <http://linas.org/linux/raid.html>.  Aside from specialized RAID
  255.         hardware support, Linux also supports software RAID 0, 1, 4, and
  256.         5 across multiple disks hosted by a single Linux system; see the
  257.         Software RAID mini-HOWTO and the Multi-Disk System Tuning mini-
  258.         HOWTO for details.  RAID across disk drives on multiple machines
  259.         in a cluster is not directly supported.
  260.  
  261.      IA32:
  262.         IA32 (Intel Architecture, 32-bit) really has nothing to do with
  263.         parallel processing, but rather refers to the class of
  264.         processors whose instruction sets are generally compatible with
  265.         that of the Intel 386.  Basically, any Intel x86 processor after
  266.         the 286 is compatible with the 32-bit flat memory model that
  267.         characterizes IA32.  AMD and Cyrix also make a multitude of
  268.         IA32-compatible processors.  Because Linux evolved primarily on
  269.         IA32 processors and that is where the commodity market is
  270.         centered, it is convenient to use IA32 to distinguish any of
  271.         these processors from the PowerPC, Alpha, PA-RISC, MIPS, SPARC,
  272.         etc.  The upcoming IA64 (64-bit with EPIC, Explicitly Parallel
  273.         Instruction Computing) will certainly complicate matters, but
  274.         Merced, the first IA64 processor, is not scheduled for
  275.         production until 1999.
  276.  
  277.      COTS:
  278.         Since the demise of many parallel supercomputer companies, COTS
  279.         (Commercial Off-The-Shelf) is commonly discussed as a
  280.         requirement for parallel computing systems.  Being fanatically
  281.         pure, the only COTS parallel processing techniques using PCs are
  282.         things like SMP Windows NT servers and various MMX Windows
  283.         applications; it really doesn't pay to be that fanatical.  The
  284.         underlying concept of COTS is really minimization of development
  285.         time and cost.  Thus, a more useful, more common, meaning of
  286.         COTS is that at least most subsystems benefit from commodity
  287.         marketing, but other technologies are used where they are
  288.         effective.  Most often, COTS parallel processing refers to a
  289.         cluster in which the nodes are commodity PCs, but the network
  290.         interface and software are somewhat customized...  typically
  291.         running Linux and applications codes that are freely available
  292.         (e.g., copyleft or public domain), but not literally COTS.
  293.  
  294.   1.3.  Example Algorithm
  295.  
  296.   In order to better understand the use of the various parallel
  297.   programming approaches outlined in this HOWTO, it is useful to have an
  298.   example problem.  Although just about any simple parallel algorithm
  299.   would do, by selecting an algorithm that has been used to demonstrate
  300.   various other parallel programming systems, it becomes a bit easier to
  301.   compare and contrast approaches.  M. J.  Quinn's book, Parallel
  302.   Computing Theory And Practice, second edition, McGraw Hill, New York,
  303.   1994, uses a parallel algorithm that computes the value of Pi to
  304.   demonstrate a variety of different parallel supercomputer programming
  305.   environments (e.g., nCUBE message passing, Sequent shared memory).  In
  306.   this HOWTO, we use the same basic algorithm.
  307.  
  308.   The algorithm computes the approximate value of Pi by summing the area
  309.   under x squared.  As a purely sequential C program, the algorithm
  310.   looks like:
  311.  
  312.   ______________________________________________________________________
  313.   #include <stdlib.h>;
  314.   #include <stdio.h>;
  315.  
  316.   main(int argc, char **argv)
  317.   {
  318.     register double width, sum;
  319.     register int intervals, i;
  320.  
  321.     /* get the number of intervals */
  322.     intervals = atoi(argv[1]);
  323.     width = 1.0 / intervals;
  324.  
  325.     /* do the computation */
  326.     sum = 0;
  327.     for (i=0; i<intervals; ++i) {
  328.       register double x = (i + 0.5) * width;
  329.       sum += 4.0 / (1.0 + x * x);
  330.     }
  331.     sum *= width;
  332.  
  333.     printf("Estimation of pi is %f\n", sum);
  334.  
  335.     return(0);
  336.   }
  337.   ______________________________________________________________________
  338.  
  339.   However, this sequential algorithm easily yields an "embarrassingly
  340.   parallel" implementation.  The area is subdivided into intervals, and
  341.   any number of processors can each independently sum the intervals
  342.   assigned to it, with no need for interaction between processors.  Once
  343.   the local sums have been computed, they are added together to create a
  344.   global sum; this step requires some level of coordination and
  345.   communication between processors.  Finally, this global sum is printed
  346.   by one processor as the approximate value of Pi.
  347.  
  348.   In this HOWTO, the various parallel implementations of this algorithm
  349.   appear where each of the different programming methods is discussed.
  350.  
  351.   1.4.  Organization Of This Document
  352.  
  353.   The remainder of this document is divided into five parts.  Sections
  354.   2, 3, 4, and 5 correspond to the three different types of hardware
  355.   configurations supporting parallel processing using Linux:
  356.  
  357.   ╖  Section 2 discusses SMP Linux systems.  These directly support MIMD
  358.      execution using shared memory, although message passing also is
  359.      implemented easily.  Although Linux supports SMP configurations up
  360.      to 16 processors, most SMP PC systems have either two or four
  361.      identical processors.
  362.  
  363.   ╖  Section 3 discusses clusters of networked machines, each running
  364.      Linux.  A cluster can be used as a parallel processing system that
  365.      directly supports MIMD execution and message passing, perhaps also
  366.      providing logically shared memory.  Simulated SIMD execution and
  367.      aggregate function communication also can be supported, depending
  368.      on the networking method used.  The number of processors in a
  369.      cluster can range from two to thousands, primarily limited by the
  370.      physical wiring constraints of the network.  In some cases, various
  371.      types of machines can be mixed within a cluster; for example, a
  372.      network combining DEC Alpha and Pentium Linux systems would be a
  373.      heterogeneous cluster.
  374.  
  375.   ╖  Section 4 discusses SWAR, SIMD Within A Register.  This is a very
  376.      restrictive type of parallel execution model, but on the other
  377.      hand, it is a built-in capability of ordinary processors.
  378.      Recently, MMX (and other) instruction set extensions to modern
  379.      processors have made this approach even more effective.
  380.  
  381.   ╖  Section 5 discusses the use of Linux PCs as hosts for simple
  382.      parallel computing systems.  Either as an add-in card or as an
  383.      external box, attached processors can provide a Linux system with
  384.      formidable processing power for specific types of applications.
  385.      For example, inexpensive ISA cards are available that provide
  386.      multiple DSP processors offering hundreds of MFLOPS for compute-
  387.      bound problems.  However, these add-in boards are just processors;
  388.      they generally do not run an OS, have disk or console I/O
  389.      capability, etc.  To make such systems useful, the Linux "host"
  390.      must provide these functions.
  391.  
  392.   The final section of this document covers aspects that are of general
  393.   interest for parallel processing using Linux, not specific to a
  394.   particular one of the approaches listed above.
  395.  
  396.   As you read this document, keep in mind that we haven't tested
  397.   everything, and a lot of stuff reported here "still has a research
  398.   character" (a nice way to say "doesn't quite work like it should" ;-).
  399.   However, parallel processing using Linux is useful now, and an
  400.   increasingly large group is working to make it better.
  401.  
  402.   The author of this HOWTO is Hank Dietz, Ph.D., currently Associate
  403.   Professor of Electrical and Computer Engineering at Purdue University,
  404.   in West Lafayette, IN, 47907-1285.  Dietz retains rights to this
  405.   document as per the Linux Documentation Project guidelines.  Although
  406.   an effort has been made to ensure the correctness and fairness of this
  407.   presentation, neither Dietz nor Purdue University can be held
  408.   responsible for any problems or errors, and Purdue University does not
  409.   endorse any of the work/products discussed.
  410.  
  411.   2.  SMP Linux
  412.  
  413.   This document gives a brief overview of how to use SMP Linux
  414.   <http://www.uk.linux.org/SMP/title.html> systems for parallel
  415.   processing.  The most up-to-date information on SMP Linux is probably
  416.   available via the SMP Linux project mailing list; send email to
  417.   majordomo@vger.rutgers.edu with the text subscribe linux-smp to join
  418.   the list.
  419.  
  420.   Does SMP Linux really work?  In June 1996, I purchased a brand new
  421.   (well, new off-brand ;-) two-processor 100MHz Pentium system.  The
  422.   fully assembled system, including both processors, Asus motherboard,
  423.   256K cache, 32M RAM, 1.6G disk, 6X CDROM, Stealth 64, and 15" Acer
  424.   monitor, cost a total of $1,800.  This was just a few hundred dollars
  425.   more than a comparable uniprocessor system.  Getting SMP Linux running
  426.   was simply a matter of installing the "stock" uniprocessor Linux,
  427.   recompiling the kernel with the SMP=1 line in the makefile uncommented
  428.   (although I find setting SMP to 1 a bit ironic ;-), and informing lilo
  429.   about the new kernel.  This system performs well enough, and has been
  430.   stable enough, to serve as my primary workstation ever since.  In
  431.   summary, SMP Linux really does work.
  432.  
  433.   The next question is how much high-level support is available for
  434.   writing and executing shared memory parallel programs under SMP Linux.
  435.   Through early 1996, there wasn't much.  Things have changed.  For
  436.   example, there is now a very complete POSIX threads library.
  437.  
  438.   Although performance may be lower than for native shared-memory
  439.   mechanisms, an SMP Linux system also can use most parallel processing
  440.   software that was originally developed for a workstation cluster using
  441.   socket communication.  Sockets (see section 3.3) work within an SMP
  442.   Linux system, and even for multiple SMPs networked as a cluster.
  443.   However, sockets imply a lot of unnecessary overhead for an SMP.  Much
  444.   of that overhead is within the kernel or interrupt handlers; this
  445.   worsens the problem because SMP Linux generally allows only one
  446.   processor to be in the kernel at a time and the interrupt controller
  447.   is set so that only the boot processor can process interrupts.
  448.   Despite this, typical SMP communication hardware is so much better
  449.   than most cluster networks that cluster software will often run better
  450.   on an SMP than on the cluster for which it was designed.
  451.  
  452.   The remainder of this section discusses SMP hardware, reviews the
  453.   basic Linux mechanisms for sharing memory across the processes of a
  454.   parallel program, makes a few observations about atomicity,
  455.   volatility, locks, and cache lines, and finally gives some pointers to
  456.   other shared memory parallel processing resources.
  457.  
  458.   2.1.  SMP Hardware
  459.  
  460.   Although SMP systems have been around for many years, until very
  461.   recently, each such machine tended to implement basic functions
  462.   differently enough so that operating system support was not portable.
  463.   The thing that has changed this situation is Intel's Multiprocessor
  464.   Specification, often referred to as simply MPS.  The MPS 1.4
  465.   specification is currently available as a PDF file at
  466.   <http://www.intel.com/design/pro/datashts/242016.htm>, and there is a
  467.   brief overview of MPS 1.1 at
  468.   <http://support.intel.com/oem_developer/ial/support/9300.HTM>, but be
  469.   aware that Intel does re-arrange their WWW site often.  A wide range
  470.   of vendors <http://www.uruk.org/~erich/mps-hw.html> are building MPS-
  471.   compliant systems supporting up to four processors, but MPS
  472.   theoretically allows many more processors.
  473.  
  474.   The only non-MPS, non-IA32, systems supported by SMP Linux are Sun4m
  475.   multiprocessor SPARC machines.  SMP Linux supports most Intel MPS
  476.   version 1.1 or 1.4 compliant machines with up to sixteen 486DX,
  477.   Pentium, Pentium MMX, Pentium Pro, or Pentium II processors.
  478.   Unsupported IA32 processors include the Intel 386, Intel 486SX/SLC
  479.   processors (the lack of floating point hardware interferes with the
  480.   SMP mechanisms), and AMD & Cyrix processors (they require different
  481.   SMP support chips that do not seem to be available at this writing).
  482.  
  483.   It is important to understand that the performance of MPS-compliant
  484.   systems can vary widely.  As expected, one cause for performance
  485.   differences is processor speed:  faster clock speeds tend to yield
  486.   faster systems, and a Pentium Pro processor is faster than a Pentium.
  487.   However, MPS does not really specify how hardware implements shared
  488.   memory, but only how that implementation must function from a software
  489.   point of view; this means that performance is also a function of how
  490.   the shared memory implementation interacts with the characteristics of
  491.   SMP Linux and your particular programs.
  492.  
  493.   The primary way in which systems that comply with MPS differ is in how
  494.   they implement access to physically shared memory.
  495.  
  496.   2.1.1.  Does each processor have its own L2 cache?
  497.  
  498.   Some MPS Pentium systems, and all MPS Pentium Pro and Pentium II
  499.   systems, have independent L2 caches.  (The L2 cache is packaged within
  500.   the Pentium Pro or Pentium II modules.)  Separate L2 caches are
  501.   generally viewed as maximizing compute performance, but things are not
  502.   quite so obvious under Linux.  The primary complication is that the
  503.   current SMP Linux scheduler does not attempt to keep each process on
  504.   the same processor, a concept known as processor affinity.  This may
  505.   change soon; there has recently been some discussion about this in the
  506.   SMP Linux development community under the title "processor binding."
  507.   Without processor affinity, having separate L2 caches may introduce
  508.   significant overhead when a process is given a timeslice on a
  509.   processor other than the one that was executing it last.
  510.  
  511.   Many relatively inexpensive systems are organized so that two Pentium
  512.   processors share a single L2 cache.  The bad news is that this causes
  513.   contention for the cache, seriously degrading performance when running
  514.   multiple independent sequential programs.  The good news is that many
  515.   parallel programs might actually benefit from the shared cache because
  516.   if both processors will want to access the same line from shared
  517.   memory, only one had to fetch it into cache and contention for the bus
  518.   is averted.  The lack of processor affinity also causes less damage
  519.   with a shared L2 cache.  Thus, for parallel programs, it isn't really
  520.   clear that sharing L2 cache is as harmful as one might expect.
  521.  
  522.   Experience with our dual Pentium shared 256K cache system shows quite
  523.   a wide range of performance depending on the level of kernel activity
  524.   required.  At worst, we see only about 1.2x speedup.  However, we also
  525.   have seen up to 2.1x speedup, which suggests that compute-intensive
  526.   SPMD-style code really does profit from the "shared fetch" effect.
  527.  
  528.   2.1.2.  Bus configuration?
  529.  
  530.   The first thing to say is that most modern systems connect the
  531.   processors to one or more PCI buses that in turn are "bridged" to one
  532.   or more ISA/EISA buses.  These bridges add latency, and both EISA and
  533.   ISA generally offer lower bandwidth than PCI (ISA being the lowest),
  534.   so disk drives, video cards, and other high-performance devices
  535.   generally should be connected via a PCI bus interface.
  536.  
  537.   Although an MPS system can achieve good speed-up for many compute-
  538.   intensive parallel programs even if there is only one PCI bus, I/O
  539.   operations occur at no better than uniprocessor performance...  and
  540.   probably a little worse due to bus contention from the processors.
  541.   Thus, if you are looking to speed-up I/O, make sure that you get an
  542.   MPS system with multiple independent PCI busses and I/O controllers
  543.   (e.g., multiple SCSI chains).  You will need to be careful to make
  544.   sure SMP Linux supports what you get.  Also keep in mind that the
  545.   current SMP Linux essentially allows only one processor in the kernel
  546.   at any time, so you should choose your I/O controllers carefully to
  547.   pick ones that minimize the kernel time required for each I/O
  548.   operation.  For really high performance, you might even consider doing
  549.   raw device I/O directly from user processes, without a system call...
  550.   this isn't necessarily as hard as it sounds, and need not compromise
  551.   security (see section 3.3 for a description of the basic techniques).
  552.  
  553.   It is important to note that the relationship between bus speed and
  554.   processor clock rate has become very fuzzy over the past few years.
  555.   Although most systems now use the same PCI clock rate, it is not
  556.   uncommon to find a faster processor clock paired with a slower bus
  557.   clock.  The classic example of this was that the Pentium 133 generally
  558.   used a faster bus than a Pentium 150, with appropriately strange-
  559.   looking performance on various benchmarks.  These effects are
  560.   amplified in SMP systems; it is even more important to have a faster
  561.   bus clock.
  562.  
  563.   2.1.3.  Memory interleaving and DRAM technologies?
  564.  
  565.   Memory interleaving actually has nothing whatsoever to do with MPS,
  566.   but you will often see it mentioned for MPS systems because these
  567.   systems are typically more demanding of memory bandwidth.  Basically,
  568.   two-way or four-way interleaving organizes RAM so that a block access
  569.   is accomplished using multiple banks of RAM rather than just one.
  570.   This provides higher memory access bandwidth, particularly for cache
  571.   line loads and stores.
  572.  
  573.   The waters are a bit muddied about this, however, because EDO DRAM and
  574.   various other memory technologies tend to improve similar kinds of
  575.   operations.  An excellent overview of DRAM technologies is given in
  576.   <http://www.pcguide.com/ref/ram/tech.htm>.
  577.  
  578.   So, for example, is it better to have 2-way interleaved EDO DRAM or
  579.   non-interleaved SDRAM?  That is a very good question with no simple
  580.   answer, because both interleaving and exotic DRAM technologies tend to
  581.   be expensive.  The same dollar investment in more ordinary memory
  582.   configurations generally will give you a significantly larger main
  583.   memory.  Even the slowest DRAM is still a heck of a lot faster than
  584.   using disk-based virtual memory....
  585.  
  586.   2.2.  Introduction To Shared Memory Programming
  587.  
  588.   Ok, so you have decided that parallel processing on an SMP is a great
  589.   thing to do...  how do you get started?  Well, the first step is to
  590.   learn a little bit about how shared memory communication really works.
  591.  
  592.   It sounds like you simply have one processor store a value into memory
  593.   and another processor load it; unfortunately, it isn't quite that
  594.   simple.  For example, the relationship between processes and
  595.   processors is very blurry; however, if we have no more active
  596.   processes than there are processors, the terms are roughly
  597.   interchangeable.  The remainder of this section briefly summarizes the
  598.   key issues that could cause serious problems, if you were not aware of
  599.   them:  the two different models used to determine what is shared,
  600.   atomicity issues, the concept of volatility, hardware lock
  601.   instructions, cache line effects, and Linux scheduler issues.
  602.  
  603.   2.2.1.  Shared Everything Vs. Shared Something
  604.  
  605.   There are two fundamentally different models commonly used for shared
  606.   memory programming:  shared everything and shared something.  Both of
  607.   these models allow processors to communicate by loads and stores
  608.   from/into shared memory; the distinction comes in the fact that shared
  609.   everything places all data structures in shared memory, while shared
  610.   something requires the user to explicitly indicate which data
  611.   structures are potentially shared and which are private to a single
  612.   processor.
  613.  
  614.   Which shared memory model should you use?  That is mostly a question
  615.   of religion.  A lot of people like the shared everything model because
  616.   they do not really need to identify which data structures should be
  617.   shared at the time they are declared...  you simply put locks around
  618.   potentially-conflicting accesses to shared objects to ensure that only
  619.   one process(or) has access at any moment.  Then again, that really
  620.   isn't all that simple...  so many people prefer the relative safety of
  621.   shared something.
  622.  
  623.   2.2.1.1.  Shared Everything
  624.  
  625.   The nice thing about sharing everything is that you can easily take an
  626.   existing sequential program and incrementally convert it into a shared
  627.   everything parallel program.  You do not have to first determine which
  628.   data need to be accessible by other processors.
  629.  
  630.   Put simply, the primary problem with sharing everything is that any
  631.   action taken by one processor could affect the other processors.  This
  632.   problem surfaces in two ways:
  633.  
  634.   ╖  Many libraries use data structures that simply are not sharable.
  635.      For example, the UNIX convention is that most functions can return
  636.      an error code in a variable called errno; if two shared everything
  637.      processes perform various calls, they would interfere with each
  638.      other because they share the same errno.  Although there is now a
  639.      library version that fixes the errno problem, similar problems
  640.      still exist in most libraries.  For example, unless special
  641.      precautions are taken, the X library will not work if calls are
  642.      made from multiple shared everything processes.
  643.  
  644.   ╖  Normally, the worst-case behavior for a program with a bad pointer
  645.      or array subscript is that the process that contains the offending
  646.      code dies.  It might even generate a core file that clues you in to
  647.      what happened.  In shared everything parallel processing, it is
  648.      very likely that the stray accesses will bring the demise of a
  649.      process other than the one at fault, making it nearly impossible to
  650.      localize and correct the error.
  651.  
  652.   Neither of these types of problems is common when shared something is
  653.   used, because only the explicitly-marked data structures are shared.
  654.   It also is fairly obvious that shared everything only works if all
  655.   processors are executing the exact same memory image; you cannot use
  656.   shared everything across multiple different code images (i.e., can use
  657.   only SPMD, not general MIMD).
  658.  
  659.   The most common type of shared everything programming support is a
  660.   threads library.  Threads
  661.   <http://liinwww.ira.uka.de/bibliography/Os/threads.html> are
  662.   essentially "light-weight" processes that might not be scheduled in
  663.   the same way as regular UNIX processes and, most importantly, share
  664.   access to a single memory map.  The POSIX Pthreads
  665.   <http://www.mit.edu:8001/people/proven/pthreads.html> package has been
  666.   the focus of a number of porting efforts; the big question is whether
  667.   any of these ports actually run the threads of a program in parallel
  668.   under SMP Linux (ideally, with a processor for each thread).  The
  669.   POSIX API doesn't require it, and versions like
  670.   <http://www.aa.net/~mtp/PCthreads.html> apparently do not implement
  671.   parallel thread execution - all the threads of a program are kept
  672.   within a single Linux process.
  673.  
  674.   The first threads library that supported SMP Linux parallelism was the
  675.   now somewhat obsolete bb_threads library,
  676.   <ftp://caliban.physics.utoronto.ca/pub/linux/>, a very small library
  677.   that used the Linux clone() call to fork new, independently scheduled,
  678.   Linux processes all sharing a single address space.  SMP Linux
  679.   machines can run multiple of these "threads" in parallel because each
  680.   "thread" is a full Linux process; the trade-off is that you do not get
  681.   the same "light-weight" scheduling control provided by some thread
  682.   libraries under other operating systems.  The library used a bit of C-
  683.   wrapped assembly code to install a new chunk of memory as each
  684.   thread's stack and to provide atomic access functions for an array of
  685.   locks (mutex objects).  Documentation consisted of a README and a
  686.   short sample program.
  687.  
  688.   More recently, a version of POSIX threads using clone() has been
  689.   developed.  This library, LinuxThreads
  690.   <http://pauillac.inria.fr/~xleroy/linuxthreads/>, is clearly the
  691.   preferred shared everything library for use under SMP Linux.  POSIX
  692.   threads are well documented, and the LinuxThreads README
  693.   <http://pauillac.inria.fr/~xleroy/linuxthreads/README> and
  694.   LinuxThreads FAQ
  695.   <http://pauillac.inria.fr/~xleroy/linuxthreads/faq.html> are very well
  696.   done.  The primary problem now is simply that POSIX threads have a lot
  697.   of details to get right and LinuxThreads is still a work in progress.
  698.   There is also the problem that the POSIX thread standard has evolved
  699.   through the standardization process, so you need to be a bit careful
  700.   not to program for obsolete early versions of the standard.
  701.  
  702.   2.2.1.2.  Shared Something
  703.  
  704.   Shared something is really "only share what needs to be shared."  This
  705.   approach can work for general MIMD (not just SPMD) provided that care
  706.   is taken for the shared objects to be allocated at the same places in
  707.   each processor's memory map.  More importantly, shared something makes
  708.   it easier to predict and tune performance, debug code, etc.  The only
  709.   problems are:
  710.  
  711.   ╖  It can be hard to know beforehand what really needs to be shared.
  712.  
  713.   ╖  The actual allocation of objects in shared memory may be awkward,
  714.      especially for what would have been stack-allocated objects.  For
  715.      example, it may be necessary to explicitly allocate shared objects
  716.      in a separate memory segment, requiring separate memory allocation
  717.      routines and introducing extra pointer indirections in each
  718.      reference.
  719.  
  720.   Currently, there are two very similar mechanisms that allow groups of
  721.   Linux processes to have independent memory spaces, all sharing only a
  722.   relatively small memory segment.  Assuming that you didn't foolishly
  723.   exclude "System V IPC" when you configured your Linux system, Linux
  724.   supports a very portable mechanism that has generally become known as
  725.   "System V Shared Memory."  The other alternative is a memory mapping
  726.   facility whose implementation varies widely across different UNIX
  727.   systems:  the mmap() system call.  You can, and should, learn about
  728.   these calls from the manual pages...  but a brief overview of each is
  729.   given in sections 2.5 and 2.6 to help get you started.
  730.  
  731.   2.2.2.  Atomicity And Ordering
  732.  
  733.   No matter which of the above two models you use, the result is pretty
  734.   much the same:  you get a pointer to a chunk of read/write memory that
  735.   is accessible by all processes within your parallel program.  Does
  736.   that mean I can just have my parallel program access shared memory
  737.   objects as though they were in ordinary local memory?  Well, not
  738.   quite....
  739.  
  740.   Atomicity refers to the concept that an operation on an object is
  741.   accomplished as an indivisible, uninterruptible, sequence.
  742.   Unfortunately, sharing memory access does not imply that all
  743.   operations on data in shared memory occur atomically.  Unless special
  744.   precautions are taken, only simple load or store operations that occur
  745.   within a single bus transaction (i.e., aligned 8, 16, or 32-bit
  746.   operations, but not misaligned nor 64-bit operations) are atomic.
  747.   Worse still, "smart" compilers like GCC will often perform
  748.   optimizations that could eliminate the memory operations needed to
  749.   ensure that other processors can see what this processor has done.
  750.   Fortunately, both these problems can be remedied...  leaving only the
  751.   relationship between access efficiency and cache line size for us to
  752.   worry about.
  753.  
  754.   However, before discussing these issues, it is useful to point-out
  755.   that all of this assumes that memory references for each processor
  756.   happen in the order in which they were coded.  The Pentium does this,
  757.   but also notes that future Intel processors might not.  So, for future
  758.   processors, keep in mind that it may be necessary to surround some
  759.   shared memory accesses with instructions that cause all pending memory
  760.   accesses to complete, thus providing memory access ordering.  The
  761.   CPUID instruction apparently is reserved to have this side-effect.
  762.  
  763.   2.2.3.  Volatility
  764.  
  765.   To prevent GCC's optimizer from buffering values of shared memory
  766.   objects in registers, all objects in shared memory should be declared
  767.   as having types with the volatile attribute.  If this is done, all
  768.   shared object reads and writes that require just one word access will
  769.   occur atomically.  For example, suppose that p is a pointer to an
  770.   integer, where both the pointer and the integer it will point at are
  771.   in shared memory; the ANSI C declaration might be:
  772.  
  773.   ______________________________________________________________________
  774.   volatile int * volatile p;
  775.   ______________________________________________________________________
  776.  
  777.   In this code, the first volatile refers to the int that p will
  778.   eventually point at; the second volatile refers to the pointer itself.
  779.   Yes, it is annoying, but it is the price one pays for enabling GCC to
  780.   perform some very powerful optimizations.  At least in theory, the
  781.   -traditional option to GCC might suffice to produce correct code at
  782.   the expense of some optimization, because pre-ANSI K&R C essentially
  783.   claimed that all variables were volatile unless explicitly declared as
  784.   register.  Still, if your typical GCC compile looks like cc -O6 ...,
  785.   you really will want to explicitly mark things as volatile only where
  786.   necessary.
  787.  
  788.   There has been a rumor to the effect that using assembly-language
  789.   locks that are marked as modifying all processor registers will cause
  790.   GCC to appropriately flush all variables, thus avoiding the
  791.   "inefficient" compiled code associated with things declared as
  792.   volatile.  This hack appears to work for statically allocated global
  793.   variables using version 2.7.0 of GCC...  however, that behavior is not
  794.   required by the ANSI C standard.  Still worse, other processes that
  795.   are making only read accesses can buffer the values in registers
  796.   forever, thus never noticing that the shared memory value has actually
  797.   changed.  In summary, do what you want, but only variables accessed
  798.   through volatile are guaranteed to work correctly.
  799.   Note that you can cause a volatile access to an ordinary variable by
  800.   using a type cast that imposes the volatile attribute.  For example,
  801.   the ordinary int i; can be referenced as a volatile by *((volatile int
  802.   *) &i); thus, you can explicitly invoke the "overhead" of volatility
  803.   only where it is critical.
  804.  
  805.   2.2.4.  Locks
  806.  
  807.   If you thought that ++i; would always work to add one to a variable i
  808.   in shared memory, you've got a nasty little surprise coming:  even if
  809.   coded as a single instruction, the load and store of the result are
  810.   separate memory transactions, and other processors could access i
  811.   between these two transactions.  For example, having two processes
  812.   both perform ++i; might only increment i by one, rather than by two.
  813.   According to the Intel Pentium "Architecture and Programming Manual,"
  814.   the LOCK prefix can be used to ensure that any of the following
  815.   instructions is atomic relative to the data memory location it
  816.   accesses:
  817.  
  818.   ______________________________________________________________________
  819.   BTS, BTR, BTC                     mem, reg/imm
  820.   XCHG                              reg, mem
  821.   XCHG                              mem, reg
  822.   ADD, OR, ADC, SBB, AND, SUB, XOR  mem, reg/imm
  823.   NOT, NEG, INC, DEC                mem
  824.   CMPXCHG, XADD
  825.   ______________________________________________________________________
  826.  
  827.   However, it probably is not a good idea to use all these operations.
  828.   For example, XADD did not even exist for the 386, so coding it may
  829.   cause portability problems.
  830.  
  831.   The XCHG instruction always asserts a lock, even without the LOCK
  832.   prefix, and thus is clearly the preferred atomic operation from which
  833.   to build higher-level atomic constructs such as semaphores and shared
  834.   queues.  Of course, you can't get GCC to generate this instruction
  835.   just by writing C code...  instead, you must use a bit of in-line
  836.   assembly code.  Given a word-size volatile object obj and a word-size
  837.   register value reg, the GCC in-line assembly code is:
  838.  
  839.   ______________________________________________________________________
  840.   __asm__ __volatile__ ("xchgl %1,%0"
  841.                         :"=r" (reg), "=m" (obj)
  842.                         :"r" (reg), "m" (obj));
  843.   ______________________________________________________________________
  844.  
  845.   Examples of GCC in-line assembly code using bit operations for locking
  846.   are given in the source code for the bb_threads library
  847.   <ftp://caliban.physics.utoronto.ca/pub/linux/>.
  848.  
  849.   It is important to remember, however, that there is a cost associated
  850.   with making memory transactions atomic.  A locking operation carries a
  851.   fair amount of overhead and may delay memory activity from other
  852.   processors, whereas ordinary references may use local cache.  The best
  853.   performance results when locking operations are used as infrequently
  854.   as possible.  Further, these IA32 atomic instructions obviously are
  855.   not portable to other systems.
  856.  
  857.   There are many alternative approaches that allow ordinary instructions
  858.   to be used to implement various synchronizations, including mutual
  859.   exclusion - ensuring that at most one processor is updating a given
  860.   shared object at any moment.  Most OS textbooks discuss at least one
  861.   of these techniques.  There is a fairly good discussion in the Fourth
  862.   Edition of Operating System Concepts, by Abraham Silberschatz and
  863.   Peter B. Galvin, ISBN 0-201-50480-4.
  864.  
  865.   2.2.5.  Cache Line Size
  866.  
  867.   One more fundamental atomicity concern can have a dramatic impact on
  868.   SMP performance:  cache line size.  Although the MPS standard requires
  869.   references to be coherent no matter what caching is used, the fact is
  870.   that when one processor writes to a particular line of memory, every
  871.   cached copy of the old line must be invalidated or updated.  This
  872.   implies that if two or more processors are both writing data to
  873.   different portions of the same line a lot of cache and bus traffic may
  874.   result, effectively to pass the line from cache to cache.  This
  875.   problem is known as false sharing.  The solution is simply to try to
  876.   organize data so that what is accessed in parallel tends to come from
  877.   a different cache line for each process.
  878.  
  879.   You might be thinking that false sharing is not a problem using a
  880.   system with a shared L2 cache, but remember that there are still
  881.   separate L1 caches.  Cache organization and number of separate levels
  882.   can both vary, but the Pentium L1 cache line size is 32 bytes and
  883.   typical external cache line sizes are around 256 bytes.  Suppose that
  884.   the addresses (physical or virtual) of two items are a and b and that
  885.   the largest per-processor cache line size is c, which we assume to be
  886.   a power of two.  To be very precise, if ((int) a) & ~(c - 1) is equal
  887.   to ((int) b) & ~(c - 1), then both references are in the same cache
  888.   line.  A simpler rule is that if shared objects being referenced in
  889.   parallel are at least c bytes apart, they should map to different
  890.   cache lines.
  891.  
  892.   2.2.6.  Linux Scheduler Issues
  893.  
  894.   Although the whole point of using shared memory for parallel
  895.   processing is to avoid OS overhead, OS overhead can come from things
  896.   other than communication per se.  We have already said that the number
  897.   of processes that should be constructed is less than or equal to the
  898.   number of processors in the machine.  But how do you decide exactly
  899.   how many processes to make?
  900.  
  901.   For best performance, the number of processes in your parallel program
  902.   should be equal to the expected number of your program's processes
  903.   that simultaneously can be running on different processors.  For
  904.   example, if a four-processor SMP typically has one process actively
  905.   running for some other purpose (e.g., a WWW server), then your
  906.   parallel program should use only three processes.  You can get a rough
  907.   idea of how many other processes are active on your system by looking
  908.   at the "load average" quoted by the uptime command.
  909.  
  910.   Alternatively, you could boost the priority of the processes in your
  911.   parallel program using, for example, the renice command or nice()
  912.   system call.  You must be privileged to increase priority.  The idea
  913.   is simply to force the other processes out of processors so that your
  914.   program can run simultaneously across all processors.  This can be
  915.   accomplished somewhat more explicitly using the prototype version of
  916.   SMP Linux at  <http://luz.cs.nmt.edu/~rtlinux/>, which offers real-
  917.   time schedulers.
  918.  
  919.   If you are not the only user treating your SMP system as a parallel
  920.   machine, you may also have conflicts between the two or more parallel
  921.   programs trying to execute simultaneously.  This standard solution is
  922.   gang scheduling - i.e., manipulating scheduling priority so that at
  923.   any given moment, only the processes of a single parallel program are
  924.   running.  It is useful to recall, however, that using more parallelism
  925.   tends to have diminishing returns and scheduler activity adds
  926.   overhead.  Thus, for example, it is probably better for a four-
  927.   processor machine to run two programs with two processes each rather
  928.   than gang scheduling between two programs with four processes each.
  929.  
  930.   There is one more twist to this.  Suppose that you are developing a
  931.   program on a machine that is heavily used all day, but will be fully
  932.   available for parallel execution at night.  You need to write and test
  933.   your code for correctness with the full number of processes, even
  934.   though you know that your daytime test runs will be slow.  Well, they
  935.   will be very slow if you have processes busy waiting for shared memory
  936.   values to be changed by other processes that are not currently running
  937.   (on other processors).  The same problem occurs if you develop and
  938.   test your code on a single-processor system.
  939.  
  940.   The solution is to embed calls in your code, wherever it may loop
  941.   awaiting an action from another processor, so that Linux will give
  942.   another process a chance to run.  I use a C macro, call it IDLE_ME, to
  943.   do this:  for a test run, compile with cc -DIDLE_ME=usleep(1); ...;
  944.   for a "production" run, compile with cc -DIDLE_ME={} ....  The
  945.   usleep(1) call requests a 1 microsecond sleep, which has the effect of
  946.   allowing the Linux scheduler to select a different process to run on
  947.   that processor.  If the number of processes is more than twice the
  948.   number of processors available, it is not unusual for codes to run ten
  949.   times faster with usleep(1) calls than without them.
  950.  
  951.   2.3.  bb_threads
  952.  
  953.   The bb_threads ("Bare Bones" threads) library,
  954.   <ftp://caliban.physics.utoronto.ca/pub/linux/>, is a remarkably simple
  955.   library that demonstrates use of the Linux clone() call.  The gzip tar
  956.   file is only 7K bytes!  Although this library is essentially made
  957.   obsolete by the LinuxThreads library discussed in section 2.4,
  958.   bb_threads is still usable, and it is small and simple enough to serve
  959.   well as an introduction to use of Linux thread support.  Certainly, it
  960.   is far less daunting to read this source code than to browse the
  961.   source code for LinuxThreads.  In summary, the bb_threads library is a
  962.   good starting point, but is not really suitable for coding large
  963.   projects.
  964.  
  965.   The basic program structure for using the bb_threads library is:
  966.  
  967.   1. Start the program running as a single process.
  968.  
  969.   2. You will need to estimate the maximum stack space that will be
  970.      required for each thread.  Guessing large is relatively harmless
  971.      (that is what virtual memory is for ;-), but remember that all the
  972.      stacks are coming from a single virtual address space, so guessing
  973.      huge is not a great idea.  The demo suggests 64K.  This size is set
  974.      to b bytes by bb_threads_stacksize(b).
  975.  
  976.   3. The next step is to initialize any locks that you will need.  The
  977.      lock mechanism built-into this library numbers locks from 0 to
  978.      MAX_MUTEXES, and initializes lock i by bb_threads_mutexcreate(i).
  979.  
  980.   4. Spawning a new thread is done by calling a library routine that
  981.      takes arguments specifying what function the new thread should
  982.      execute and what arguments should be transmitted to it.  To start a
  983.      new thread executing the void-returning function f with the single
  984.      argument arg, you do something like bb_threads_newthread(f, &arg),
  985.      where f should be declared something like void f(void *arg, size_t
  986.      dummy).  If you need to pass more than one argument, pass a pointer
  987.      to a structure initialized to hold the argument values.
  988.  
  989.   5. Run parallel code, being careful to use bb_threads_lock(n) and
  990.      bb_threads_unlock(n) where n is an integer identifying which lock
  991.      to use.  Note that the lock and unlock operations in this library
  992.      are very basic spin locks using atomic bus-locking instructions,
  993.      which can cause excessive memory-reference interference and do not
  994.      make any attempt to ensure fairness.
  995.  
  996.      The demo program packaged with bb_threads did not correctly use
  997.      locks to prevent printf() from being executed simultaneously from
  998.      within the functions fnn and main...  and because of this, the demo
  999.      does not always work.  I'm not saying this to knock the demo, but
  1000.      rather to emphasize that this stuff is very tricky; also, it is
  1001.      only slightly easier using LinuxThreads.
  1002.  
  1003.   6. When a thread executes a return, it actually destroys the
  1004.      process...  but the local stack memory is not automatically
  1005.      deallocated.  To be precise, Linux doesn't support deallocation,
  1006.      but the memory space is not automatically added back to the
  1007.      malloc() free list.  Thus, the parent process should reclaim the
  1008.      space for each dead child by bb_threads_cleanup(wait(NULL)).
  1009.  
  1010.   The following C program uses the algorithm discussed in section 1.3 to
  1011.   compute the approximate value of Pi using two bb_threads threads.
  1012.  
  1013.   ______________________________________________________________________
  1014.   #include <stdio.h>
  1015.   #include <stdlib.h>
  1016.   #include <unistd.h>
  1017.   #include <sys/types.h>
  1018.   #include <sys/wait.h>
  1019.   #include "bb_threads.h"
  1020.  
  1021.   volatile double pi = 0.0;
  1022.   volatile int intervals;
  1023.   volatile int pids[2];      /* Unix PIDs of threads */
  1024.  
  1025.   void
  1026.   do_pi(void *data, size_t len)
  1027.   {
  1028.     register double width, localsum;
  1029.     register int i;
  1030.     register int iproc = (getpid() != pids[0]);
  1031.  
  1032.     /* set width */
  1033.     width = 1.0 / intervals;
  1034.  
  1035.     /* do the local computations */
  1036.     localsum = 0;
  1037.     for (i=iproc; i<intervals; i+=2) {
  1038.       register double x = (i + 0.5) * width;
  1039.       localsum += 4.0 / (1.0 + x * x);
  1040.     }
  1041.     localsum *= width;
  1042.  
  1043.     /* get permission, update pi, and unlock */
  1044.     bb_threads_lock(0);
  1045.     pi += localsum;
  1046.     bb_threads_unlock(0);
  1047.   }
  1048.  
  1049.   int
  1050.   main(int argc, char **argv)
  1051.   {
  1052.     /* get the number of intervals */
  1053.     intervals = atoi(argv[1]);
  1054.  
  1055.     /* set stack size and create lock... */
  1056.     bb_threads_stacksize(65536);
  1057.     bb_threads_mutexcreate(0);
  1058.  
  1059.     /* make two threads... */
  1060.     pids[0] = bb_threads_newthread(do_pi, NULL);
  1061.     pids[1] = bb_threads_newthread(do_pi, NULL);
  1062.  
  1063.     /* cleanup after two threads (really a barrier sync) */
  1064.     bb_threads_cleanup(wait(NULL));
  1065.     bb_threads_cleanup(wait(NULL));
  1066.  
  1067.     /* print the result */
  1068.     printf("Estimation of pi is %f\n", pi);
  1069.  
  1070.     /* check-out */
  1071.     exit(0);
  1072.   }
  1073.   ______________________________________________________________________
  1074.  
  1075.   2.4.  LinuxThreads
  1076.  
  1077.   LinuxThreads  <http://pauillac.inria.fr/~xleroy/linuxthreads/> is a
  1078.   fairly complete and solid implementation of "shared everything" as per
  1079.   the POSIX 1003.1c threads standard.  Unlike other POSIX threads ports,
  1080.   LinuxThreads uses the same Linux kernel threads facility (clone())
  1081.   that is used by bb_threads.  POSIX compatibility means that it is
  1082.   relatively easy to port quite a few threaded applications from other
  1083.   systems and various tutorial materials are available.  In short, this
  1084.   is definitely the threads package to use under Linux for developing
  1085.   large-scale threaded programs.
  1086.  
  1087.   The basic program structure for using the LinuxThreads library is:
  1088.  
  1089.   1. Start the program running as a single process.
  1090.  
  1091.   2. The next step is to initialize any locks that you will need.
  1092.      Unlike bb_threads locks, which are identified by numbers, POSIX
  1093.      locks are declared as variables of type pthread_mutex_t lock.  Use
  1094.      pthread_mutex_init(&lock,val) to initialize each one you will need
  1095.      to use.
  1096.  
  1097.   3. As with bb_threads, spawning a new thread is done by calling a
  1098.      library routine that takes arguments specifying what function the
  1099.      new thread should execute and what arguments should be transmitted
  1100.      to it.  However, POSIX requires the user to declare a variable of
  1101.      type pthread_t to identify each thread.  To create a thread
  1102.      pthread_t thread running f(), one calls
  1103.      pthread_create(&thread,NULL,f,&arg).
  1104.  
  1105.   4. Run parallel code, being careful to use pthread_mutex_lock(&lock)
  1106.      and pthread_mutex_unlock(&lock) as appropriate.
  1107.  
  1108.   5. Use pthread_join(thread,&retval) to clean-up after each thread.
  1109.  
  1110.   6. Use -D_REENTRANT when compiling your C code.
  1111.  
  1112.   An example parallel computation of Pi using LinuxThreads follows.  The
  1113.   algorithm of section 1.3 is used and, as for the bb_threads example,
  1114.   two threads execute in parallel.
  1115.  
  1116.   ______________________________________________________________________
  1117.   #include <stdio.h>
  1118.   #include <stdlib.h>
  1119.   #include "pthread.h"
  1120.  
  1121.   volatile double pi = 0.0;  /* Approximation to pi (shared) */
  1122.   pthread_mutex_t pi_lock;   /* Lock for above */
  1123.   volatile double intervals; /* How many intervals? */
  1124.  
  1125.   void *
  1126.   process(void *arg)
  1127.   {
  1128.     register double width, localsum;
  1129.     register int i;
  1130.     register int iproc = (*((char *) arg) - '0');
  1131.  
  1132.     /* Set width */
  1133.     width = 1.0 / intervals;
  1134.  
  1135.     /* Do the local computations */
  1136.     localsum = 0;
  1137.     for (i=iproc; i<intervals; i+=2) {
  1138.       register double x = (i + 0.5) * width;
  1139.       localsum += 4.0 / (1.0 + x * x);
  1140.     }
  1141.     localsum *= width;
  1142.  
  1143.     /* Lock pi for update, update it, and unlock */
  1144.     pthread_mutex_lock(&pi_lock);
  1145.     pi += localsum;
  1146.     pthread_mutex_unlock(&pi_lock);
  1147.  
  1148.     return(NULL);
  1149.   }
  1150.  
  1151.   int
  1152.   main(int argc, char **argv)
  1153.   {
  1154.     pthread_t thread0, thread1;
  1155.     void * retval;
  1156.  
  1157.     /* Get the number of intervals */
  1158.     intervals = atoi(argv[1]);
  1159.  
  1160.     /* Initialize the lock on pi */
  1161.     pthread_mutex_init(&pi_lock, NULL);
  1162.  
  1163.     /* Make the two threads */
  1164.     if (pthread_create(&thread0, NULL, process, "0") ||
  1165.         pthread_create(&thread1, NULL, process, "1")) {
  1166.       fprintf(stderr, "%s: cannot make thread\n", argv[0]);
  1167.       exit(1);
  1168.     }
  1169.  
  1170.     /* Join (collapse) the two threads */
  1171.     if (pthread_join(thread0, &retval) ||
  1172.         pthread_join(thread1, &retval)) {
  1173.       fprintf(stderr, "%s: thread join failed\n", argv[0]);
  1174.       exit(1);
  1175.     }
  1176.  
  1177.     /* Print the result */
  1178.     printf("Estimation of pi is %f\n", pi);
  1179.  
  1180.     /* Check-out */
  1181.     exit(0);
  1182.   }
  1183.   ______________________________________________________________________
  1184.  
  1185.   2.5.  System V Shared Memory
  1186.  
  1187.   The System V IPC (Inter-Process Communication) support consists of a
  1188.   number of system calls providing message queues, semaphores, and a
  1189.   shared memory mechanism.  Of course, these mechanisms were originally
  1190.   intended to be used for multiple processes to communicate within a
  1191.   uniprocessor system.  However, that implies that it also should work
  1192.   to communicate between processes under SMP Linux, no matter which
  1193.   processors they run on.
  1194.  
  1195.   Before going into how these calls are used, it is important to
  1196.   understand that although System V IPC calls exist for things like
  1197.   semaphores and message transmission, you probably should not use them.
  1198.   Why not?  These functions are generally slow and serialized under SMP
  1199.   Linux.  Enough said.
  1200.  
  1201.   The basic procedure for creating a group of processes sharing access
  1202.   to a shared memory segment is:
  1203.  
  1204.   1. Start the program running as a single process.
  1205.  
  1206.   2. Typically, you will want each run of a parallel program to have its
  1207.      own shared memory segment, so you will need to call shmget() to
  1208.      create a new segment of the desired size.  Alternatively, this call
  1209.      can be used to get the ID of a pre-existing shared memory segment.
  1210.      In either case, the return value is either the shared memory
  1211.      segment ID or -1 for error.  For example, to create a shared memory
  1212.      segment of b bytes, the call might be shmid = shmget(IPC_PRIVATE,
  1213.      b, (IPC_CREAT | 0666)).
  1214.  
  1215.   3. The next step is to attach this shared memory segment to this
  1216.      process, literally adding it to the virtual memory map of this
  1217.      process.  Although the shmat() call allows the programmer to
  1218.      specify the virtual address at which the segment should appear, the
  1219.      address selected must be aligned on a page boundary (i.e., be a
  1220.      multiple of the page size returned by getpagesize(), which is
  1221.      usually 4096 bytes), and will override the mapping of any memory
  1222.      formerly at that address.  Thus, we instead prefer to let the
  1223.      system pick the address.  In either case, the return value is a
  1224.      pointer to the base virtual address of the segment just mapped.
  1225.      The code is shmptr = shmat(shmid, 0, 0).
  1226.  
  1227.      Notice that you can allocate all your static shared variables into
  1228.      this shared memory segment by simply declaring all shared variables
  1229.      as members of a struct type, and declaring shmptr to be a pointer
  1230.      to that type.  Using this technique, shared variable x would be
  1231.      accessed as shmptr->x.
  1232.  
  1233.   4. Since this shared memory segment should be destroyed when the last
  1234.      process with access to it terminates or detaches from it, we need
  1235.      to call shmctl() to set-up this default action.  The code is
  1236.      something like shmctl(shmid, IPC_RMID, 0).
  1237.  
  1238.   5. Use the standard Linux fork() call to make the desired number of
  1239.      processes...  each will inherit the shared memory segment.
  1240.  
  1241.   6. When a process is done using a shared memory segment, it really
  1242.      should detach from that shared memory segment.  This is done by
  1243.      shmdt(shmptr).
  1244.  
  1245.   Although the above set-up does require a few system calls, once the
  1246.   shared memory segment has been established, any change made by one
  1247.   processor to a value in that memory will automatically be visible to
  1248.   all processes.  Most importantly, each communication operation will
  1249.   occur without the overhead of a system call.
  1250.  
  1251.   An example C program using System V shared memory segments follows.
  1252.   It computes Pi, using the same algorithm given in section 1.3.
  1253.  
  1254.   ______________________________________________________________________
  1255.   #include <stdio.h>
  1256.   #include <stdlib.h>
  1257.   #include <unistd.h>
  1258.   #include <sys/types.h>
  1259.   #include <sys/stat.h>
  1260.   #include <fcntl.h>
  1261.   #include <sys/ipc.h>
  1262.   #include <sys/shm.h>
  1263.  
  1264.   volatile struct shared { double pi; int lock; } *shared;
  1265.  
  1266.   inline extern int xchg(register int reg,
  1267.   volatile int * volatile obj)
  1268.   {
  1269.     /* Atomic exchange instruction */
  1270.   __asm__ __volatile__ ("xchgl %1,%0"
  1271.                         :"=r" (reg), "=m" (*obj)
  1272.                         :"r" (reg), "m" (*obj));
  1273.     return(reg);
  1274.   }
  1275.  
  1276.   main(int argc, char **argv)
  1277.   {
  1278.     register double width, localsum;
  1279.     register int intervals, i;
  1280.     register int shmid;
  1281.     register int iproc = 0;;
  1282.  
  1283.     /* Allocate System V shared memory */
  1284.     shmid = shmget(IPC_PRIVATE,
  1285.                    sizeof(struct shared),
  1286.                    (IPC_CREAT | 0600));
  1287.     shared = ((volatile struct shared *) shmat(shmid, 0, 0));
  1288.     shmctl(shmid, IPC_RMID, 0);
  1289.  
  1290.     /* Initialize... */
  1291.     shared->pi = 0.0;
  1292.     shared->lock = 0;
  1293.  
  1294.     /* Fork a child */
  1295.     if (!fork()) ++iproc;
  1296.  
  1297.     /* get the number of intervals */
  1298.     intervals = atoi(argv[1]);
  1299.     width = 1.0 / intervals;
  1300.  
  1301.     /* do the local computations */
  1302.     localsum = 0;
  1303.     for (i=iproc; i<intervals; i+=2) {
  1304.       register double x = (i + 0.5) * width;
  1305.       localsum += 4.0 / (1.0 + x * x);
  1306.     }
  1307.     localsum *= width;
  1308.  
  1309.     /* Atomic spin lock, add, unlock... */
  1310.     while (xchg((iproc + 1), &(shared->lock))) ;
  1311.     shared->pi += localsum;
  1312.     shared->lock = 0;
  1313.  
  1314.     /* Terminate child (barrier sync) */
  1315.     if (iproc == 0) {
  1316.       wait(NULL);
  1317.       printf("Estimation of pi is %f\n", shared->pi);
  1318.     }
  1319.  
  1320.     /* Check out */
  1321.     return(0);
  1322.   }
  1323.   ______________________________________________________________________
  1324.  
  1325.   In this example, I have used the IA32 atomic exchange instruction to
  1326.   implement locking.  For better performance and portability, substitute
  1327.   a synchronization technique that avoids atomic bus-locking
  1328.   instructions (discussed in section 2.2).
  1329.  
  1330.   When debugging your code, it is useful to remember that the ipcs
  1331.   command will report the status of the System V IPC facilities
  1332.   currently in use.
  1333.  
  1334.   2.6.  Memory Map Call
  1335.  
  1336.   Using system calls for file I/O can be very expensive; in fact, that
  1337.   is why there is a user-buffered file I/O library (getchar(), fwrite(),
  1338.   etc.).  But user buffers don't work if multiple processes are
  1339.   accessing the same writeable file, and the user buffer management
  1340.   overhead is significant.  The BSD UNIX fix for this was the addition
  1341.   of a system call that allows a portion of a file to be mapped into
  1342.   user memory, essentially using virtual memory paging mechanisms to
  1343.   cause updates.  This same mechanism also has been used in systems from
  1344.   Sequent for many years as the basis for their shared memory parallel
  1345.   processing support.  Despite some very negative comments in the (quite
  1346.   old) man page, Linux seems to correctly perform at least some of the
  1347.   basic functions, and it supports the degenerate use of this system
  1348.   call to map an anonymous segment of memory that can be shared across
  1349.   multiple processes.
  1350.  
  1351.   In essence, the Linux implementation of mmap() is a plug-in
  1352.   replacement for steps 2, 3, and 4 in the System V shared memory scheme
  1353.   outlined in section 2.5.  To create an anonymous shared memory
  1354.   segment:
  1355.  
  1356.   ______________________________________________________________________
  1357.   shmptr =
  1358.       mmap(0,                        /* system assigns address */
  1359.            b,                        /* size of shared memory segment */
  1360.            (PROT_READ | PROT_WRITE), /* access rights, can be rwx */
  1361.            (MAP_ANON | MAP_SHARED),  /* anonymous, shared */
  1362.            0,                        /* file descriptor (not used) */
  1363.            0);                       /* file offset (not used) */
  1364.   ______________________________________________________________________
  1365.  
  1366.   The equivalent to the System V shared memory shmdt() call is munmap():
  1367.  
  1368.   ______________________________________________________________________
  1369.   munmap(shmptr, b);
  1370.   ______________________________________________________________________
  1371.  
  1372.   In my opinion, there is no real benefit in using mmap() instead of the
  1373.   System V shared memory support.
  1374.  
  1375.   3.  Clusters Of Linux Systems
  1376.  
  1377.   This section attempts to give an overview of cluster parallel
  1378.   processing using Linux.  Clusters are currently both the most popular
  1379.   and the most varied approach, ranging from a conventional network of
  1380.   workstations (NOW) to essentially custom parallel machines that just
  1381.   happen to use Linux PCs as processor nodes.  There is also quite a lot
  1382.   of software support for parallel processing using clusters of Linux
  1383.   machines.
  1384.  
  1385.   3.1.  Why A Cluster?
  1386.  
  1387.   Cluster parallel processing offers several important advantages:
  1388.  
  1389.   ╖  Each of the machines in a cluster can be a complete system, usable
  1390.      for a wide range of other computing applications.  This leads many
  1391.      people to suggest that cluster parallel computing can simply claim
  1392.      all the "wasted cycles" of workstations sitting idle on people's
  1393.      desks.  It is not really so easy to salvage those cycles, and it
  1394.      will probably slow your co-worker's screen saver, but it can be
  1395.      done.
  1396.  
  1397.   ╖  The current explosion in networked systems means that most of the
  1398.      hardware for building a cluster is being sold in high volume, with
  1399.      correspondingly low "commodity" prices as the result.  Further
  1400.      savings come from the fact that only one video card, monitor, and
  1401.      keyboard are needed for each cluster (although you may need to swap
  1402.      these into each machine to perform the initial installation of
  1403.      Linux, once running, a typical Linux PC does not need a "console").
  1404.      In comparison, SMP and attached processors are much smaller
  1405.      markets, tending toward somewhat higher price per unit performance.
  1406.  
  1407.   ╖  Cluster computing can scale to very large systems.  While it is
  1408.      currently hard to find a Linux-compatible SMP with many more than
  1409.      four processors, most commonly available network hardware easily
  1410.      builds a cluster with up to 16 machines.  With a little work,
  1411.      hundreds or even thousands of machines can be networked.  In fact,
  1412.      the entire Internet can be viewed as one truly huge cluster.
  1413.  
  1414.   ╖  The fact that replacing a "bad machine" within a cluster is trivial
  1415.      compared to fixing a partly faulty SMP yields much higher
  1416.      availability for carefully designed cluster configurations.  This
  1417.      becomes important not only for particular applications that cannot
  1418.      tolerate significant service interruptions, but also for general
  1419.      use of systems containing enough processors so that single-machine
  1420.      failures are fairly common.  (For example, even though the average
  1421.      time to failure of a PC might be two years, in a cluster with 32
  1422.      machines, the probability that at least one will fail within 6
  1423.      months is quite high.)
  1424.  
  1425.   OK, so clusters are free or cheap and can be very large and highly
  1426.   available...  why doesn't everyone use a cluster?  Well, there are
  1427.   problems too:
  1428.  
  1429.   ╖  With a few exceptions, network hardware is not designed for
  1430.      parallel processing.  Typically latency is very high and bandwidth
  1431.      relatively low compared to SMP and attached processors.  For
  1432.      example, SMP latency is generally no more than a few microseconds,
  1433.      but is commonly hundreds or thousands of microseconds for a
  1434.      cluster.  SMP communication bandwidth is often more than 100
  1435.      MBytes/second; although the fastest network hardware (e.g.,
  1436.      "Gigabit Ethernet") offers comparable speed, the most commonly used
  1437.      networks are between 10 and 1000 times slower.
  1438.  
  1439.      The performance of network hardware is poor enough as an isolated
  1440.      cluster network.  If the network is not isolated from other
  1441.      traffic, as is often the case using "machines that happen to be
  1442.      networked" rather than a system designed as a cluster, performance
  1443.      can be substantially worse.
  1444.  
  1445.   ╖  There is very little software support for treating a cluster as a
  1446.      single system.  For example, the ps command only reports the
  1447.      processes running on one Linux system, not all processes running
  1448.      across a cluster of Linux systems.
  1449.  
  1450.   Thus, the basic story is that clusters offer great potential, but that
  1451.   potential may be very difficult to achieve for most applications.  The
  1452.   good news is that there is quite a lot of software support that will
  1453.   help you achieve good performance for programs that are well suited to
  1454.   this environment, and there are also networks designed specifically to
  1455.   widen the range of programs that can achieve good performance.
  1456.  
  1457.   3.2.  Network Hardware
  1458.  
  1459.   Computer networking is an exploding field...  but you already knew
  1460.   that.  An ever-increasing range of networking technologies and
  1461.   products are being developed, and most are available in forms that
  1462.   could be applied to make a parallel-processing cluster out of a group
  1463.   of machines (i.e., PCs each running Linux).
  1464.  
  1465.   Unfortunately, no one network technology solves all problems best; in
  1466.   fact, the range of approach, cost, and performance is at first hard to
  1467.   believe.  For example, using standard commercially-available hardware,
  1468.   the cost per machine networked ranges from less than $5 to over
  1469.   $4,000.  The delivered bandwidth and latency each also vary over four
  1470.   orders of magnitude.
  1471.  
  1472.   Before trying to learn about specific networks, it is important to
  1473.   recognize that these things change like the wind (see
  1474.   <http://www.uk.linux.org/NetNews.html> for Linux networking news), and
  1475.   it is very difficult to get accurate data about some networks.
  1476.  
  1477.   Where I was particularly uncertain, I've placed a ?.  I have spent a
  1478.   lot of time researching this topic, but I'm sure my summary is full of
  1479.   errors and has omitted many important things.  If you have any
  1480.   corrections or additions, please send email to pplinux@ecn.purdue.edu.
  1481.  
  1482.   Summaries like the LAN Technology Scorecard at
  1483.   <http://web.syr.edu/~jmwobus/comfaqs/lan-technology.html> give some
  1484.   characteristics of many different types of networks and LAN standards.
  1485.   However, the summary in this HOWTO centers on the network properties
  1486.   that are most relevant to construction of Linux clusters.  The section
  1487.   discussing each network begins with a short list of characteristics.
  1488.   The following defines what these entries mean.
  1489.  
  1490.      Linux support:
  1491.         If the answer is no, the meaning is pretty clear.  Other answers
  1492.         try to describe the basic program interface that is used to
  1493.         access the network.  Most network hardware is interfaced via a
  1494.         kernel driver, typically supporting TCP/UDP communication.  Some
  1495.         other networks use more direct (e.g., library) interfaces to
  1496.         reduce latency by bypassing the kernel.
  1497.         Years ago, it used to be considered perfectly acceptable to
  1498.         access a floating point unit via an OS call, but that is now
  1499.         clearly ludicrous; in my opinion, it is just as awkward for each
  1500.         communication between processors executing a parallel program to
  1501.         require an OS call.  The problem is that computers haven't yet
  1502.         integrated these communication mechanisms, so non-kernel
  1503.         approaches tend to have portability problems.  You are going to
  1504.         hear a lot more about this in the near future, mostly in the
  1505.         form of the new Virtual Interface (VI) Architecture,
  1506.         <http://www.viarch.org/>, which is a standardized method for
  1507.         most network interface operations to bypass the usual OS call
  1508.         layers.  The VI standard is backed by Compaq, Intel, and
  1509.         Microsoft, and is sure to have a strong impact on SAN (System
  1510.         Area Network) designs over the next few years.
  1511.  
  1512.      Maximum bandwidth:
  1513.         This is the number everybody cares about.  I have generally used
  1514.         the theoretical best case numbers; your mileage will vary.
  1515.  
  1516.      Minimum latency:
  1517.         In my opinion, this is the number everybody should care about
  1518.         even more than bandwidth.  Again, I have used the unrealistic
  1519.         best-case numbers, but at least these numbers do include all
  1520.         sources of latency, both hardware and software.  In most cases,
  1521.         the network latency is just a few microseconds; the much larger
  1522.         numbers reflect layers of inefficient hardware and software
  1523.         interfaces.
  1524.  
  1525.      Available as:
  1526.         Simply put, this describes how you get this type of network
  1527.         hardware.  Commodity stuff is widely available from many
  1528.         vendors, with price as the primary distinguishing factor.
  1529.         Multiple-vendor things are available from more than one
  1530.         competing vendor, but there are significant differences and
  1531.         potential interoperability problems.  Single-vendor networks
  1532.         leave you at the mercy of that supplier (however benevolent it
  1533.         may be).  Public domain designs mean that even if you cannot
  1534.         find somebody to sell you one, you or anybody else can buy parts
  1535.         and make one.  Research prototypes are just that; they are
  1536.         generally neither ready for external users nor available to
  1537.         them.
  1538.  
  1539.      Interface port/bus used:
  1540.         How does one hook-up this network?  The highest performance and
  1541.         most common now is a PCI bus interface card.  There are also
  1542.         EISA, VESA local bus (VL bus), and ISA bus cards.  ISA was there
  1543.         first, and is still commonly used for low-performance cards.
  1544.         EISA is still around as the second bus in a lot of PCI machines,
  1545.         so there are a few cards.  These days, you don't see much VL
  1546.         stuff (although  <http://www.vesa.org/> would beg to differ).
  1547.  
  1548.         Of course, any interface that you can use without having to open
  1549.         your PC's case has more than a little appeal.  IrDA and USB
  1550.         interfaces are appearing with increasing frequency.  The
  1551.         Standard Parallel Port (SPP) used to be what your printer was
  1552.         plugged into, but it has seen a lot of use lately as an external
  1553.         extension of the ISA bus; this new functionality is enhanced by
  1554.         the IEEE 1284 standard, which specifies EPP and ECP
  1555.         improvements.  There is also the old, reliable, slow RS232
  1556.         serial port.  I don't know of anybody connecting machines using
  1557.         VGA video connectors, keyboard, mouse, or game ports...  so
  1558.         that's about it.
  1559.  
  1560.      Network structure:
  1561.         A bus is a wire, set of wires, or fiber.  A hub is a little box
  1562.         that knows how to connect different wires/fibers plugged into
  1563.         it; switched hubs allow multiple connections to be actively
  1564.         transmitting data simultaneously.
  1565.  
  1566.      Cost per machine connected:
  1567.         Here's how to use these numbers.  Suppose that, not counting the
  1568.         network connection, it costs $2,000 to purchase a PC for use as
  1569.         a node in your cluster.  Adding a Fast Ethernet brings the per
  1570.         node cost to about $2,400; adding a Myrinet instead brings the
  1571.         cost to about $3,800.  If you have about $20,000 to spend, that
  1572.         means you could have either 8 machines connected by Fast
  1573.         Ethernet or 5 machines connected by Myrinet.  It also can be
  1574.         very reasonable to have multiple networks; e.g., $20,000 could
  1575.         buy 8 machines connected by both Fast Ethernet and TTL_PAPERS.
  1576.         Pick the network, or set of networks, that is most likely to
  1577.         yield a cluster that will run your application fastest.
  1578.  
  1579.         By the time you read this, these numbers will be wrong...  heck,
  1580.         they're probably wrong already.  There may also be quantity
  1581.         discounts, special deals, etc.  Still, the prices quoted here
  1582.         aren't likely to be wrong enough to lead you to a totally
  1583.         inappropriate choice.  It doesn't take a PhD (although I do have
  1584.         one ;-) to see that expensive networks only make sense if your
  1585.         application needs their special properties or if the PCs being
  1586.         clustered are relatively expensive.
  1587.  
  1588.   Now that you have the disclaimers, on with the show....
  1589.  
  1590.   3.2.1.  ArcNet
  1591.  
  1592.   ╖  Linux support: kernel drivers
  1593.  
  1594.   ╖  Maximum bandwidth: 2.5 Mb/s
  1595.  
  1596.   ╖  Minimum latency: 1,000 microseconds?
  1597.  
  1598.   ╖  Available as: multiple-vendor hardware
  1599.  
  1600.   ╖  Interface port/bus used: ISA
  1601.  
  1602.   ╖  Network structure: unswitched hub or bus (logical ring)
  1603.  
  1604.   ╖  Cost per machine connected: $200
  1605.  
  1606.   ARCNET is a local area network that is primarily intended for use in
  1607.   embedded real-time control systems.  Like Ethernet, the network is
  1608.   physically organized either as taps on a bus or one or more hubs,
  1609.   however, unlike Ethernet, it uses a token-based protocol logically
  1610.   structuring the network as a ring.  Packet headers are small (3 or 4
  1611.   bytes) and messages can carry as little as a single byte of data.
  1612.   Thus, ARCNET yields more consistent performance than Ethernet, with
  1613.   bounded delays, etc.  Unfortunately, it is slower than Ethernet and
  1614.   less popular, making it more expensive.  More information is available
  1615.   from the ARCNET Trade Association at  <http://www.arcnet.com/>.
  1616.   3.2.2.  ATM
  1617.  
  1618.   ╖  Linux support: kernel driver, AAL* library
  1619.  
  1620.   ╖  Maximum bandwidth: 155 Mb/s (soon, 1,200 Mb/s)
  1621.  
  1622.   ╖  Minimum latency: 120 microseconds
  1623.  
  1624.   ╖  Available as: multiple-vendor hardware
  1625.  
  1626.   ╖  Interface port/bus used: PCI
  1627.  
  1628.   ╖  Network structure: switched hubs
  1629.  
  1630.   ╖  Cost per machine connected: $3,000
  1631.  
  1632.   Unless you've been in a coma for the past few years, you have probably
  1633.   heard a lot about how ATM (Asynchronous Transfer Mode) is the
  1634.   future...  well, sort-of.  ATM is cheaper than HiPPI and faster than
  1635.   Fast Ethernet, and it can be used over the very long distances that
  1636.   the phone companies care about.  The ATM network protocol is also
  1637.   designed to provide a lower-overhead software interface and to more
  1638.   efficiently manage small messages and real-time communications (e.g.,
  1639.   digital audio and video).  It is also one of the highest-bandwidth
  1640.   networks that Linux currently supports.  The bad news is that ATM
  1641.   isn't cheap, and there are still some compatibility problems across
  1642.   vendors.  An overview of Linux ATM development is available at
  1643.   <http://lrcwww.epfl.ch/linux-atm/>.
  1644.  
  1645.   3.2.3.  CAPERS
  1646.  
  1647.   ╖  Linux support: AFAPI library
  1648.  
  1649.   ╖  Maximum bandwidth: 1.2 Mb/s
  1650.  
  1651.   ╖  Minimum latency: 3 microseconds
  1652.  
  1653.   ╖  Available as: commodity hardware
  1654.  
  1655.   ╖  Interface port/bus used: SPP
  1656.  
  1657.   ╖  Network structure: cable between 2 machines
  1658.  
  1659.   ╖  Cost per machine connected: $2
  1660.  
  1661.   CAPERS (Cable Adapter for Parallel Execution and Rapid
  1662.   Synchronization) is a spin-off of the PAPERS project,
  1663.   <http://garage.ecn.purdue.edu/~papers/>, at the Purdue University
  1664.   School of Electrical and Computer Engineering.  In essence, it defines
  1665.   a software protocol for using an ordinary "LapLink" SPP-to-SPP cable
  1666.   to implement the PAPERS library for two Linux PCs.  The idea doesn't
  1667.   scale, but you can't beat the price.  As with TTL_PAPERS, to improve
  1668.   system security, there is a minor kernel patch recommended, but not
  1669.   required:  <http://garage.ecn.purdue.edu/~papers/giveioperm.html>.
  1670.  
  1671.   3.2.4.  Ethernet
  1672.  
  1673.   ╖  Linux support: kernel drivers
  1674.  
  1675.   ╖  Maximum bandwidth: 10 Mb/s
  1676.  
  1677.   ╖  Minimum latency: 100 microseconds
  1678.  
  1679.   ╖  Available as: commodity hardware
  1680.  
  1681.   ╖  Interface port/bus used: PCI
  1682.  
  1683.   ╖  Network structure: switched or unswitched hubs, or hubless bus
  1684.  
  1685.   ╖  Cost per machine connected: $100 (hubless, $50)
  1686.  
  1687.   For some years now, 10 Mbits/s Ethernet has been the standard network
  1688.   technology.  Good Ethernet interface cards can be purchased for well
  1689.   under $50, and a fair number of PCs now have an Ethernet controller
  1690.   built-into the motherboard.  For lightly-used networks, Ethernet
  1691.   connections can be organized as a multi-tap bus without a hub; such
  1692.   configurations can serve up to 200 machines with minimal cost, but are
  1693.   not appropriate for parallel processing.  Adding an unswitched hub
  1694.   does not really help performance.  However, switched hubs that can
  1695.   provide full bandwidth to simultaneous connections cost only about
  1696.   $100 per port.  Linux supports an amazing range of Ethernet
  1697.   interfaces, but it is important to keep in mind that variations in the
  1698.   interface hardware can yield significant performance differences.  See
  1699.   the Hardware Compatibility HOWTO for comments on which are supported
  1700.   and how well they work; also see
  1701.   <http://cesdis1.gsfc.nasa.gov/linux/drivers/>.
  1702.  
  1703.   An interesting way to improve performance is offered by the 16-machine
  1704.   Linux cluster work done in the Beowulf project,
  1705.   <http://cesdis.gsfc.nasa.gov/linux/beowulf/beowulf.html>, at NASA
  1706.   CESDIS.  There, Donald Becker, who is the author of many Ethernet card
  1707.   drivers, has developed support for load sharing across multiple
  1708.   Ethernet networks that shadow each other (i.e., share the same network
  1709.   addresses).  This load sharing is built-into the standard Linux
  1710.   distribution, and is done invisibly below the socket operation level.
  1711.   Because hub cost is significant, having each machine connected to two
  1712.   or more hubless or unswitched hub Ethernet networks can be a very
  1713.   cost-effective way to improve performance.  In fact, in situations
  1714.   where one machine is the network performance bottleneck, load sharing
  1715.   using shadow networks works much better than using a single switched
  1716.   hub network.
  1717.  
  1718.   3.2.5.  Ethernet (Fast Ethernet)
  1719.  
  1720.   ╖  Linux support: kernel drivers
  1721.  
  1722.   ╖  Maximum bandwidth: 100 Mb/s
  1723.  
  1724.   ╖  Minimum latency: 80 microseconds
  1725.  
  1726.   ╖  Available as: commodity hardware
  1727.  
  1728.   ╖  Interface port/bus used: PCI
  1729.  
  1730.   ╖  Network structure: switched or unswitched hubs
  1731.  
  1732.   ╖  Cost per machine connected: $400?
  1733.  
  1734.   Although there are really quite a few different technologies calling
  1735.   themselves "Fast Ethernet," this term most often refers to a hub-based
  1736.   100 Mbits/s Ethernet that is somewhat compatible with older "10 BaseT"
  1737.   10 Mbits/s devices and cables.  As might be expected, anything called
  1738.   Ethernet is generally priced for a volume market, and these interfaces
  1739.   are generally a small fraction of the price of 155 Mbits/s ATM cards.
  1740.   The catch is that having a bunch of machines dividing the bandwidth of
  1741.   a single 100 Mbits/s "bus" (using an unswitched hub) yields
  1742.   performance that might not even be as good on average as using 10
  1743.   Mbits/s Ethernet with a switched hub that can give each machine's
  1744.   connection a full 10 Mbits/s.
  1745.  
  1746.   Switched hubs that can provide 100 Mbits/s for each machine
  1747.   simultaneously are expensive, but prices are dropping every day, and
  1748.   these switches do yield much higher total network bandwidth than
  1749.   unswitched hubs.  The thing that makes ATM switches so expensive is
  1750.   that they must switch for each (relatively short) ATM cell; some Fast
  1751.   Ethernet switches take advantage of the expected lower switching
  1752.   frequency by using techniques that may have low latency through the
  1753.   switch, but take multiple milliseconds to change the switch path...
  1754.   if your routing pattern changes frequently, avoid those switches.  See
  1755.   <http://cesdis1.gsfc.nasa.gov/linux/drivers/> for information about
  1756.   the various cards and drivers.
  1757.  
  1758.   Also note that, as described for Ethernet, the Beowulf project,
  1759.   <http://cesdis.gsfc.nasa.gov/linux/beowulf/beowulf.html>, at NASA has
  1760.   been developing support that offers improved performance by load
  1761.   sharing across multiple Fast Ethernets.
  1762.  
  1763.   3.2.6.  Ethernet (Gigabit Ethernet)
  1764.  
  1765.   ╖  Linux support: kernel drivers
  1766.  
  1767.   ╖  Maximum bandwidth: 1,000 Mb/s
  1768.  
  1769.   ╖  Minimum latency: 300 microseconds?
  1770.  
  1771.   ╖  Available as: multiple-vendor hardware
  1772.  
  1773.   ╖  Interface port/bus used: PCI
  1774.  
  1775.   ╖  Network structure: switched hubs or FDRs
  1776.  
  1777.   ╖  Cost per machine connected: $2,500?
  1778.  
  1779.   I'm not sure that Gigabit Ethernet,  <http://www.gigabit-
  1780.   ethernet.org/>, has a good technological reason to be called
  1781.   Ethernet...  but the name does accurately reflect the fact that this
  1782.   is intended to be a cheap, mass-market, computer network technology
  1783.   with native support for IP.  However, current pricing reflects the
  1784.   fact that Gb/s hardware is still a tricky thing to build.
  1785.  
  1786.   Unlike other Ethernet technologies, Gigabit Ethernet provides for a
  1787.   level of flow control that should make it a more reliable network.
  1788.   FDRs, or Full-Duplex Repeaters, simply multiplex lines, using
  1789.   buffering and localized flow control to improve performance.  Most
  1790.   switched hubs are being built as new interface modules for existing
  1791.   gigabit-capable switch fabrics.  Switch/FDR products have been shipped
  1792.   or announced by at least  <http://www.acacianet.com/>,
  1793.   <http://www.baynetworks.com/>,  <http://www.cabletron.com/>,
  1794.   <http://www.networks.digital.com/>,
  1795.   <http://www.extremenetworks.com/>,  <http://www.foundrynet.com/>,
  1796.   <http://www.gigalabs.com/>,  <http://www.packetengines.com/>.
  1797.   <http://www.plaintree.com/>,  <http://www.prominet.com/>,
  1798.   <http://www.sun.com/>, and  <http://www.xlnt.com/>.
  1799.  
  1800.   There is a Linux driver,
  1801.   <http://cesdis.gsfc.nasa.gov/linux/drivers/yellowfin.html>, for the
  1802.   Packet Engines "Yellowfin" G-NIC,  <http://www.packetengines.com/>.
  1803.   Early tests under Linux achieved about 2.5x higher bandwidth than
  1804.   could be achieved with the best 100 Mb/s Fast Ethernet; with gigabit
  1805.   networks, careful tuning of PCI bus use is a critical factor.  There
  1806.   is little doubt that driver improvements, and Linux drivers for other
  1807.   NICs, will follow.
  1808.  
  1809.   3.2.7.  FC (Fibre Channel)
  1810.  
  1811.   ╖  Linux support: no
  1812.  
  1813.   ╖  Maximum bandwidth: 1,062 Mb/s
  1814.  
  1815.   ╖  Minimum latency: ?
  1816.  
  1817.   ╖  Available as: multiple-vendor hardware
  1818.  
  1819.   ╖  Interface port/bus used: PCI?
  1820.  
  1821.   ╖  Network structure: ?
  1822.  
  1823.   ╖  Cost per machine connected: ?
  1824.  
  1825.   The goal of FC (Fibre Channel) is to provide high-performance block
  1826.   I/O (an FC frame carries a 2,048 byte data payload), particularly for
  1827.   sharing disks and other storage devices that can be directly connected
  1828.   to the FC rather than connected through a computer.  Bandwidth-wise,
  1829.   FC is specified to be relatively fast, running anywhere between 133
  1830.   and 1,062 Mbits/s.  If FC becomes popular as a high-end SCSI
  1831.   replacement, it may quickly become a cheap technology; for now, it is
  1832.   not cheap and is not supported by Linux.  A good collection of FC
  1833.   references is maintained by the Fibre Channel Association at
  1834.   <http://www.amdahl.com/ext/CARP/FCA/FCA.html>
  1835.  
  1836.   3.2.8.  FireWire (IEEE 1394)
  1837.  
  1838.   ╖  Linux support: no
  1839.  
  1840.   ╖  Maximum bandwidth: 196.608 Mb/s (soon, 393.216 Mb/s)
  1841.  
  1842.   ╖  Minimum latency: ?
  1843.  
  1844.   ╖  Available as: multiple-vendor hardware
  1845.  
  1846.   ╖  Interface port/bus used: PCI
  1847.  
  1848.   ╖  Network structure: random without cycles (self-configuring)
  1849.  
  1850.   ╖  Cost per machine connected: $600
  1851.  
  1852.   FireWire,  <http://www.firewire.org/>, the IEEE 1394-1995 standard, is
  1853.   destined to be the low-cost high-speed digital network for consumer
  1854.   electronics.  The showcase application is connecting DV digital video
  1855.   camcorders to computers, but FireWire is intended to be used for
  1856.   applications ranging from being a SCSI replacement to interconnecting
  1857.   the components of your home theater.  It allows up to 64K devices to
  1858.   be connected in any topology using busses and bridges that does not
  1859.   create a cycle, and automatically detects the configuration when
  1860.   components are added or removed.  Short (four-byte "quadlet") low-
  1861.   latency messages are supported as well as ATM-like isochronous
  1862.   transmission (used to keep multimedia messages synchronized).  Adaptec
  1863.   has FireWire products that allow up to 63 devices to be connected to a
  1864.   single PCI interface card, and also has good general FireWire
  1865.   information at  <http://www.adaptec.com/serialio/>.
  1866.  
  1867.   Although FireWire will not be the highest bandwidth network available,
  1868.   the consumer-level market (which should drive prices very low) and low
  1869.   latency support might make this one of the best Linux PC cluster
  1870.   message-passing network technologies within the next year or so.
  1871.  
  1872.   3.2.9.  HiPPI And Serial HiPPI
  1873.  
  1874.   ╖  Linux support: no
  1875.  
  1876.   ╖  Maximum bandwidth: 1,600 Mb/s (serial is 1,200 Mb/s)
  1877.  
  1878.   ╖  Minimum latency: ?
  1879.  
  1880.   ╖  Available as: multiple-vendor hardware
  1881.  
  1882.   ╖  Interface port/bus used: EISA, PCI
  1883.  
  1884.   ╖  Network structure: switched hubs
  1885.  
  1886.   ╖  Cost per machine connected: $3,500 (serial is $4,500)
  1887.  
  1888.   HiPPI (High Performance Parallel Interface) was originally intended to
  1889.   provide very high bandwidth for transfer of huge data sets between a
  1890.   supercomputer and another machine (a supercomputer, frame buffer, disk
  1891.   array, etc.), and has become the dominant standard for supercomputers.
  1892.   Although it is an oxymoron, Serial HiPPI is also becoming popular,
  1893.   typically using a fiber optic cable instead of the 32-bit wide
  1894.   standard (parallel) HiPPI cables.  Over the past few years, HiPPI
  1895.   crossbar switches have become common and prices have dropped sharply;
  1896.   unfortunately, serial HiPPI is still pricey, and that is what PCI bus
  1897.   interface cards generally support.  Worse still, Linux doesn't yet
  1898.   support HiPPI.  A good overview of HiPPI is maintained by CERN at
  1899.   <http://www.cern.ch/HSI/hippi/>; they also maintain a rather long list
  1900.   of HiPPI vendors at
  1901.   <http://www.cern.ch/HSI/hippi/procintf/manufact.htm>.
  1902.  
  1903.   3.2.10.  IrDA (Infrared Data Association)
  1904.  
  1905.   ╖  Linux support: no?
  1906.  
  1907.   ╖  Maximum bandwidth: 1.15 Mb/s and 4 Mb/s
  1908.  
  1909.   ╖  Minimum latency: ?
  1910.  
  1911.   ╖  Available as: multiple-vendor hardware
  1912.  
  1913.   ╖  Interface port/bus used: IrDA
  1914.  
  1915.   ╖  Network structure: thin air ;-)
  1916.  
  1917.   ╖  Cost per machine connected: $0
  1918.  
  1919.   IrDA (Infrared Data Association,  <http://www.irda.org/>) is that
  1920.   little infrared device on the side of a lot of laptop PCs.  It is
  1921.   inherently difficult to connect more than two machines using this
  1922.   interface, so it is unlikely to be used for clustering.  Don Becker
  1923.   did some preliminary work with IrDA.
  1924.  
  1925.   3.2.11.  Myrinet
  1926.  
  1927.   ╖  Linux support: library
  1928.  
  1929.   ╖  Maximum bandwidth: 1,280 Mb/s
  1930.  
  1931.   ╖  Minimum latency: 9 microseconds
  1932.  
  1933.   ╖  Available as: single-vendor hardware
  1934.  
  1935.   ╖  Interface port/bus used: PCI
  1936.  
  1937.   ╖  Network structure: switched hubs
  1938.  
  1939.   ╖  Cost per machine connected: $1,800
  1940.  
  1941.   Myrinet  <http://www.myri.com/> is a local area network (LAN) designed
  1942.   to also serve as a "system area network" (SAN), i.e., the network
  1943.   within a cabinet full of machines connected as a parallel system.  The
  1944.   LAN and SAN versions use different physical media and have somewhat
  1945.   different characteristics; generally, the SAN version would be used
  1946.   within a cluster.
  1947.  
  1948.   Myrinet is fairly conventional in structure, but has a reputation for
  1949.   being particularly well-implemented.  The drivers for Linux are said
  1950.   to perform very well, although shockingly large performance variations
  1951.   have been reported with different PCI bus implementations for the host
  1952.   computers.
  1953.  
  1954.   Currently, Myrinet is clearly the favorite network of cluster groups
  1955.   that are not too severely "budgetarily challenged."  If your idea of a
  1956.   Linux PC is a high-end Pentium Pro or Pentium II with at least 256 MB
  1957.   RAM and a SCSI RAID, the cost of Myrinet is quite reasonable.
  1958.   However, using more ordinary PC configurations, you may find that your
  1959.   choice is between N machines linked by Myrinet or 2N linked by
  1960.   multiple Fast Ethernets and TTL_PAPERS.  It really depends on what
  1961.   your budget is and what types of computations you care about most.
  1962.  
  1963.   3.2.12.  Parastation
  1964.  
  1965.   ╖  Linux support: HAL or socket library
  1966.  
  1967.   ╖  Maximum bandwidth: 125 Mb/s
  1968.  
  1969.   ╖  Minimum latency: 2 microseconds
  1970.  
  1971.   ╖  Available as: single-vendor hardware
  1972.  
  1973.   ╖  Interface port/bus used: PCI
  1974.  
  1975.   ╖  Network structure: hubless mesh
  1976.  
  1977.   ╖  Cost per machine connected: > $1,000
  1978.  
  1979.   The ParaStation project  <http://wwwipd.ira.uka.de/parastation> at
  1980.   University of Karlsruhe Department of Informatics is building a PVM-
  1981.   compatible custom low-latency network.  They first constructed a two-
  1982.   processor ParaPC prototype using a custom EISA card interface and PCs
  1983.   running BSD UNIX, and then built larger clusters using DEC Alphas.
  1984.   Since January 1997, ParaStation has been available for Linux.  The PCI
  1985.   cards are being made in cooperation with a company called Hitex (see
  1986.   <http://www.hitex.com:80/parastation/>).  Parastation hardware
  1987.   implements both fast, reliable, message transmission and simple
  1988.   barrier synchronization.
  1989.  
  1990.   3.2.13.  PLIP
  1991.  
  1992.   ╖  Linux support: kernel driver
  1993.  
  1994.   ╖  Maximum bandwidth: 1.2 Mb/s
  1995.  
  1996.   ╖  Minimum latency: 1,000 microseconds?
  1997.  
  1998.   ╖  Available as: commodity hardware
  1999.  
  2000.   ╖  Interface port/bus used: SPP
  2001.  
  2002.   ╖  Network structure: cable between 2 machines
  2003.  
  2004.   ╖  Cost per machine connected: $2
  2005.  
  2006.   For just the cost of a "LapLink" cable, PLIP (Parallel Line Interface
  2007.   Protocol) allows two Linux machines to communicate through standard
  2008.   parallel ports using standard socket-based software.  In terms of
  2009.   bandwidth, latency, and scalability, this is not a very serious
  2010.   network technology; however, the near-zero cost and the software
  2011.   compatibility are useful.  The driver is part of the standard Linux
  2012.   kernel distributions.
  2013.  
  2014.   3.2.14.  SCI
  2015.  
  2016.   ╖  Linux support: no
  2017.  
  2018.   ╖  Maximum bandwidth: 4,000 Mb/s
  2019.  
  2020.   ╖  Minimum latency: 2.7 microseconds
  2021.  
  2022.   ╖  Available as: multiple-vendor hardware
  2023.  
  2024.   ╖  Interface port/bus used: PCI, proprietary
  2025.  
  2026.   ╖  Network structure: ?
  2027.  
  2028.   ╖  Cost per machine connected: > $1,000
  2029.  
  2030.   The goal of SCI (Scalable Coherent Interconnect, ANSI/IEEE 1596-1992)
  2031.   is essentially to provide a high performance mechanism that can
  2032.   support coherent shared memory access across large numbers of
  2033.   machines, as well various types of block message transfers.  It is
  2034.   fairly safe to say that the designed bandwidth and latency of SCI are
  2035.   both "awesome" in comparison to most other network technologies.  The
  2036.   catch is that SCI is not widely available as cheap production units,
  2037.   and there isn't any Linux support.
  2038.  
  2039.   SCI primarily is used in various proprietary designs for logically-
  2040.   shared physically-distributed memory machines, such as the HP/Convex
  2041.   Exemplar SPP and the Sequent NUMA-Q 2000 (see
  2042.   <http://www.sequent.com/>).  However, SCI is available as a PCI
  2043.   interface card and 4-way switches (up to 16 machines can be connected
  2044.   by cascading four 4-way switches) from Dolphin,
  2045.   <http://www.dolphinics.com/>, as their CluStar product line.  A good
  2046.   set of links overviewing SCI is maintained by CERN at
  2047.   <http://www.cern.ch/HSI/sci/sci.html>.
  2048.  
  2049.   3.2.15.  SCSI
  2050.  
  2051.   ╖  Linux support: kernel drivers
  2052.  
  2053.   ╖  Maximum bandwidth: 5 Mb/s to over 20 Mb/s
  2054.  
  2055.   ╖  Minimum latency: ?
  2056.  
  2057.   ╖  Available as: multiple-vendor hardware
  2058.  
  2059.   ╖  Interface port/bus used: PCI, EISA, ISA card
  2060.  
  2061.   ╖  Network structure: inter-machine bus sharing SCSI devices
  2062.  
  2063.   ╖  Cost per machine connected: ?
  2064.  
  2065.   SCSI (Small Computer Systems Interconnect) is essentially an I/O bus
  2066.   that is used for disk drives, CD ROMS, image scanners, etc.  There are
  2067.   three separate standards SCSI-1, SCSI-2, and SCSI-3; Fast and Ultra
  2068.   speeds; and data path widths of 8, 16, or 32 bits (with FireWire
  2069.   compatibility also mentioned in SCSI-3).  It is all pretty confusing,
  2070.   but we all know a good SCSI is somewhat faster than EIDE and can
  2071.   handle more devices more efficiently.
  2072.  
  2073.   What many people do not realize is that it is fairly simple for two
  2074.   computers to share a single SCSI bus.  This type of configuration is
  2075.   very useful for sharing disk drives between machines and implementing
  2076.   fail-over - having one machine take over database requests when the
  2077.   other machine fails.  Currently, this is the only mechanism supported
  2078.   by Microsoft's PC cluster product, WolfPack.  However, the inability
  2079.   to scale to larger systems renders shared SCSI uninteresting for
  2080.   parallel processing in general.
  2081.  
  2082.   3.2.16.  ServerNet
  2083.  
  2084.   ╖  Linux support: no
  2085.  
  2086.   ╖  Maximum bandwidth: 400 Mb/s
  2087.  
  2088.   ╖  Minimum latency: 3 microseconds
  2089.  
  2090.   ╖  Available as: single-vendor hardware
  2091.  
  2092.   ╖  Interface port/bus used: PCI
  2093.  
  2094.   ╖  Network structure: hexagonal tree/tetrahedral lattice of hubs
  2095.  
  2096.   ╖  Cost per machine connected: ?
  2097.  
  2098.   ServerNet is the high-performance network hardware from Tandem,
  2099.   <http://www.tandem.com>.  Especially in the online transation
  2100.   processing (OLTP) world, Tandem is well known as a leading producer of
  2101.   high-reliability systems, so it is not surprising that their network
  2102.   claims not just high performance, but also "high data integrity and
  2103.   reliability."  Another interesting aspect of ServerNet is that it
  2104.   claims to be able to transfer data from any device directly to any
  2105.   device; not just between processors, but also disk drives, etc., in a
  2106.   one-sided style similar to that suggested by the MPI remote memory
  2107.   access mechanisms described in section 3.5.  One last comment about
  2108.   ServerNet:  although there is just a single vendor, that vendor is
  2109.   powerful enough to potentially establish ServerNet as a major
  2110.   standard...  Tandem is owned by Compaq.
  2111.  
  2112.   3.2.17.  SHRIMP
  2113.  
  2114.   ╖  Linux support: user-level memory mapped interface
  2115.  
  2116.   ╖  Maximum bandwidth: 180 Mb/s
  2117.  
  2118.   ╖  Minimum latency: 5 microseconds
  2119.  
  2120.   ╖  Available as: research prototype
  2121.  
  2122.   ╖  Interface port/bus used: EISA
  2123.  
  2124.   ╖  Network structure: mesh backplane (as in Intel Paragon)
  2125.  
  2126.   ╖  Cost per machine connected: ?
  2127.  
  2128.   The SHRIMP project,  <http://www.CS.Princeton.EDU/shrimp/>, at the
  2129.   Princeton University Computer Science Department is building a
  2130.   parallel computer using PCs running Linux as the processing elements.
  2131.   The first SHRIMP (Scalable, High-Performance, Really Inexpensive
  2132.   Multi-Processor) was a simple two-processor prototype using a dual-
  2133.   ported RAM on a custom EISA card interface.  There is now a prototype
  2134.   that will scale to larger configurations using a custom interface card
  2135.   to connect to a "hub" that is essentially the same mesh routing
  2136.   network used in the Intel Paragon (see
  2137.   <http://www.ssd.intel.com/paragon.html>).  Considerable effort has
  2138.   gone into developing low-overhead "virtual memory mapped
  2139.   communication" hardware and support software.
  2140.  
  2141.   3.2.18.  SLIP
  2142.  
  2143.   ╖  Linux support: kernel drivers
  2144.  
  2145.   ╖  Maximum bandwidth: 0.1 Mb/s
  2146.  
  2147.   ╖  Minimum latency: 1,000 microseconds?
  2148.  
  2149.   ╖  Available as: commodity hardware
  2150.  
  2151.   ╖  Interface port/bus used: RS232C
  2152.  
  2153.   ╖  Network structure: cable between 2 machines
  2154.  
  2155.   ╖  Cost per machine connected: $2
  2156.  
  2157.   Although SLIP (Serial Line Interface Protocol) is firmly planted at
  2158.   the low end of the performance spectrum, SLIP (or CSLIP or PPP) allows
  2159.   two machines to perform socket communication via ordinary RS232 serial
  2160.   ports.  The RS232 ports can be connected using a null-modem RS232
  2161.   serial cable, or they can even be connected via dial-up through a
  2162.   modem.  In any case, latency is high and bandwidth is low, so SLIP
  2163.   should be used only when no other alternatives are available.  It is
  2164.   worth noting, however, that most PCs have two RS232 ports, so it would
  2165.   be possible to network a group of machines simply by connecting the
  2166.   machines as a linear array or as a ring.  There is even load sharing
  2167.   software called EQL.
  2168.  
  2169.   3.2.19.  TTL_PAPERS
  2170.  
  2171.   ╖  Linux support: AFAPI library
  2172.  
  2173.   ╖  Maximum bandwidth: 1.6 Mb/s
  2174.  
  2175.   ╖  Minimum latency: 3 microseconds
  2176.  
  2177.   ╖  Available as: public-domain design, single-vendor hardware
  2178.  
  2179.   ╖  Interface port/bus used: SPP
  2180.  
  2181.   ╖  Network structure: tree of hubs
  2182.  
  2183.   ╖  Cost per machine connected: $100
  2184.  
  2185.   The PAPERS (Purdue's Adapter for Parallel Execution and Rapid
  2186.   Synchronization) project,  <http://garage.ecn.purdue.edu/~papers/>, at
  2187.   the Purdue University School of Electrical and Computer Engineering is
  2188.   building scalable, low-latency, aggregate function communication
  2189.   hardware and software that allows a parallel supercomputer to be built
  2190.   using unmodified PCs/workstations as nodes.
  2191.  
  2192.   There have been over a dozen different types of PAPERS hardware built
  2193.   that connect to PCs/workstations via the SPP (Standard Parallel Port),
  2194.   roughly following two development lines.  The versions called "PAPERS"
  2195.   target higher performance, using whatever technologies are
  2196.   appropriate; current work uses FPGAs, and high bandwidth PCI bus
  2197.   interface designs are also under development.  In contrast, the
  2198.   versions called "TTL_PAPERS" are designed to be easily reproduced
  2199.   outside Purdue, and are remarkably simple public domain designs that
  2200.   can be built using ordinary TTL logic.  One such design is produced
  2201.   commercially,  <http://chelsea.ios.com:80/~hgdietz/sbm4.html>.
  2202.  
  2203.   Unlike the custom hardware designs from other universities, TTL_PAPERS
  2204.   clusters have been assembled at many universities from the USA to
  2205.   South Korea.  Bandwidth is severely limited by the SPP connections,
  2206.   but PAPERS implements very low latency aggregate function
  2207.   communications; even the fastest message-oriented systems cannot
  2208.   provide comparable performance on those aggregate functions.  Thus,
  2209.   PAPERS is particularly good for synchronizing the displays of a video
  2210.   wall (to be discussed further in the upcoming Video Wall HOWTO),
  2211.   scheduling accesses to a high-bandwidth network, evaluating global
  2212.   fitness in genetic searches, etc.  Although PAPERS clusters have been
  2213.   built using IBM PowerPC AIX, DEC Alpha OSF/1, and HP PA-RISC HP-UX
  2214.   machines, Linux-based PCs are the platforms best supported.
  2215.  
  2216.   User programs using TTL_PAPERS AFAPI directly access the SPP hardware
  2217.   port registers under Linux, without an OS call for each access.  To do
  2218.   this, AFAPI first gets port permission using either iopl() or
  2219.   ioperm().  The problem with these calls is that both require the user
  2220.   program to be privileged, yielding a potential security hole.  The
  2221.   solution is an optional kernel patch,
  2222.   <http://garage.ecn.purdue.edu/~papers/giveioperm.html>, that allows a
  2223.   privileged process to control port permission for any process.
  2224.  
  2225.   3.2.20.  USB (Universal Serial Bus)
  2226.  
  2227.   ╖  Linux support: kernel driver
  2228.  
  2229.   ╖  Maximum bandwidth: 12 Mb/s
  2230.  
  2231.   ╖  Minimum latency: ?
  2232.  
  2233.   ╖  Available as: commodity hardware
  2234.  
  2235.   ╖  Interface port/bus used: USB
  2236.  
  2237.   ╖  Network structure: bus
  2238.  
  2239.   ╖  Cost per machine connected: $5?
  2240.  
  2241.   USB (Universal Serial Bus,  <http://www.usb.org/>) is a hot-pluggable
  2242.   conventional-Ethernet-speed, bus for up to 127 peripherals ranging
  2243.   from keyboards to video conferencing cameras.  It isn't really clear
  2244.   how multiple computers get connected to each other using USB.  In any
  2245.   case, USB ports are quickly becoming as standard on PC motherboards as
  2246.   RS232 and SPP, so don't be surprised if one or two USB ports are
  2247.   lurking on the back of the next PC you buy.  Development of a Linux
  2248.   driver is discussed at  <http://peloncho.fis.ucm.es/~inaky/USB.html>.
  2249.  
  2250.   In some ways, USB is almost the low-performance, zero-cost, version of
  2251.   FireWire that you can purchase today.
  2252.  
  2253.   3.2.21.  WAPERS
  2254.  
  2255.   ╖  Linux support: AFAPI library
  2256.  
  2257.   ╖  Maximum bandwidth: 0.4 Mb/s
  2258.  
  2259.   ╖  Minimum latency: 3 microseconds
  2260.  
  2261.   ╖  Available as: public-domain design
  2262.  
  2263.   ╖  Interface port/bus used: SPP
  2264.  
  2265.   ╖  Network structure: wiring pattern between 2-64 machines
  2266.  
  2267.   ╖  Cost per machine connected: $5
  2268.  
  2269.   WAPERS (Wired-AND Adapter for Parallel Execution and Rapid
  2270.   Synchronization) is a spin-off of the PAPERS project,
  2271.   <http://garage.ecn.purdue.edu/~papers/>, at the Purdue University
  2272.   School of Electrical and Computer Engineering.  If implemented
  2273.   properly, the SPP has four bits of open-collector output that can be
  2274.   wired together across machines to implement a 4-bit wide wired AND.
  2275.   This wired-AND is electrically touchy, and the maximum number of
  2276.   machines that can be connected in this way critically depends on the
  2277.   analog properties of the ports (maximum sink current and pull-up
  2278.   resistor value); typically, up to 7 or 8 machines can be networked by
  2279.   WAPERS.  Although cost and latency are very low, so is bandwidth;
  2280.   WAPERS is much better as a second network for aggregate operations
  2281.   than as the only network in a cluster.  As with TTL_PAPERS, to improve
  2282.   system security, there is a minor kernel patch recommended, but not
  2283.   required:  <http://garage.ecn.purdue.edu/~papers/giveioperm.html>.
  2284.  
  2285.   3.3.  Network Software Interface
  2286.  
  2287.   Before moving on to discuss the software support for parallel
  2288.   applications, it is useful to first briefly cover the basics of low-
  2289.   level software interface to the network hardware.  There are really
  2290.   only three basic choices:  sockets, device drivers, and user-level
  2291.   libraries.
  2292.  
  2293.   3.3.1.  Sockets
  2294.  
  2295.   By far the most common low-level network interface is a socket
  2296.   interface.  Sockets have been a part of unix for over a decade, and
  2297.   most standard network hardware is designed to support at least two
  2298.   types of socket protocols:  UDP and TCP.  Both types of socket allow
  2299.   you to send arbitrary size blocks of data from one machine to another,
  2300.   but there are several important differences.  Typically, both yield a
  2301.   minimum latency of around 1,000 microseconds, although performance can
  2302.   be far worse depending on network traffic.
  2303.  
  2304.   These socket types are the basic network software interface for most
  2305.   of the portable, higher-level, parallel processing software; for
  2306.   example, PVM uses a combination of UDP and TCP, so knowing the
  2307.   difference will help you tune performance.  For even better
  2308.   performance, you can also use these mechanisms directly in your
  2309.   program.  The following is just a simple overview of UDP and TCP; see
  2310.   the manual pages and a good network programming book for details.
  2311.  
  2312.   3.3.1.1.  UDP Protocol (SOCK_DGRAM)
  2313.  
  2314.   UDP is the User Datagram Protocol, but you more easily can remember
  2315.   the properties of UDP as Unreliable Datagram Processing.  In other
  2316.   words, UDP allows each block to be sent as an individual message, but
  2317.   a message might be lost in transmission.  In fact, depending on
  2318.   network traffic, UDP messages can be lost, can arrive multiple times,
  2319.   or can arrive in an order different from that in which they were sent.
  2320.   The sender of a UDP message does not automatically get an
  2321.   acknowledgment, so it is up to user-written code to detect and
  2322.   compensate for these problems.  Fortunately, UDP does ensure that if a
  2323.   message arrives, the message contents are intact (i.e., you never get
  2324.   just part of a UDP message).
  2325.  
  2326.   The nice thing about UDP is that it tends to be the fastest socket
  2327.   protocol.  Further, UDP is "connectionless," which means that each
  2328.   message is essentially independent of all others.  A good analogy is
  2329.   that each message is like a letter to be mailed; you might send
  2330.   multiple letters to the same address, but each one is independent of
  2331.   the others and there is no limit on how many people you can send
  2332.   letters to.
  2333.  
  2334.   3.3.1.2.  TCP Protocol (SOCK_STREAM)
  2335.  
  2336.   Unlike UDP, TCP is a reliable, connection-based, protocol.  Each block
  2337.   sent is not seen as a message, but as a block of data within an
  2338.   apparently continuous stream of bytes being transmitted through a
  2339.   connection between sender and receiver.  This is very different from
  2340.   UDP messaging because each block is simply part of the byte stream and
  2341.   it is up to the user code to figure-out how to extract each block from
  2342.   the byte stream; there are no markings separating messages.  Further,
  2343.   the connections are more fragile with respect to network problems, and
  2344.   only a limited number of connections can exist simultaneously for each
  2345.   process.  Because it is reliable, TCP generally implies significantly
  2346.   more overhead than UDP.
  2347.  
  2348.   There are, however, a few pleasant surprises about TCP.  One is that,
  2349.   if multiple messages are sent through a connection, TCP is able to
  2350.   pack them together in a buffer to better match network hardware packet
  2351.   sizes, potentially yielding better-than-UDP performance for groups of
  2352.   short or oddly-sized messages.  The other bonus is that networks
  2353.   constructed using reliable direct physical links between machines can
  2354.   easily and efficiently simulate TCP connections.  For example, this
  2355.   was done for the ParaStation's "Socket Library" interface software,
  2356.   which provides TCP semantics using user-level calls that differ from
  2357.   the standard TCP OS calls only by the addition of the prefix PSS to
  2358.   each function name.
  2359.  
  2360.   3.3.2.  Device Drivers
  2361.  
  2362.   When it comes to actually pushing data onto the network or pulling
  2363.   data off the network, the standard unix software interface is a part
  2364.   of the unix kernel called a device driver.  UDP and TCP don't just
  2365.   transport data, they also imply a fair amount of overhead for socket
  2366.   management.  For example, something has to manage the fact that
  2367.   multiple TCP connections can share a single physical network
  2368.   interface. In contrast, a device driver for a dedicated network
  2369.   interface only needs to implement a few simple data transport
  2370.   functions.  These device driver functions can then be invoked by user
  2371.   programs by using open() to identify the proper device and then using
  2372.   system calls like read() and write() on the open "file."  Thus, each
  2373.   such operation could transport a block of data with little more than
  2374.   the overhead of a system call, which might be as fast as tens of
  2375.   microseconds.
  2376.  
  2377.   Writing a device driver to be used with Linux is not hard...  if you
  2378.   know precisely how the device hardware works.  If you are not sure how
  2379.   it works, don't guess.  Debugging device drivers isn't fun and
  2380.   mistakes can fry hardware.  However, if that hasn't scared you off, it
  2381.   may be possible to write a device driver to, for example, use
  2382.   dedicated Ethernet cards as dumb but fast direct machine-to-machine
  2383.   connections without the usual Ethernet protocol overhead.  In fact,
  2384.   that's pretty much what some early Intel supercomputers did....  Look
  2385.   at the Device Driver HOWTO for more information.
  2386.  
  2387.   3.3.3.  User-Level Libraries
  2388.  
  2389.   If you've taken an OS course, user-level access to hardware device
  2390.   registers is exactly what you have been taught never to do, because
  2391.   one of the primary purposes of an OS is to control device access.
  2392.   However, an OS call is at least tens of microseconds of overhead.  For
  2393.   custom network hardware like TTL_PAPERS, which can perform a basic
  2394.   network operation in just 3 microseconds, such OS call overhead is
  2395.   intolerable.  The only way to avoid that overhead is to have user-
  2396.   level code - a user-level library - directly access hardware device
  2397.   registers.  Thus, the question becomes one of how a user-level library
  2398.   can access hardware directly, yet not compromise the OS control of
  2399.   device access rights.
  2400.   On a typical system, the only way for a user-level library to directly
  2401.   access hardware device registers is to:
  2402.  
  2403.   1. At user program start-up, use an OS call to map the page of memory
  2404.      address space containing the device registers into the user process
  2405.      virtual memory map.  For some systems, the mmap() call (first
  2406.      mentioned in section 2.6) can be used to map a special file which
  2407.      represents the physical memory page addresses of the I/O devices.
  2408.      Alternatively, it is relatively simple to write a device driver to
  2409.      perform this function.  Further, this device driver can control
  2410.      access by only mapping the page(s) containing the specific device
  2411.      registers needed, thereby maintaining OS access control.
  2412.  
  2413.   2. Access device registers without an OS call by simply loading or
  2414.      storing to the mapped addresses.  For example, *((char *) 0x1234) =
  2415.      5; would store the byte value 5 into memory location 1234
  2416.      (hexadecimal).
  2417.  
  2418.   Fortunately, it happens that Linux for the Intel 386 (and compatible
  2419.   processors) offers an even better solution:
  2420.  
  2421.   1. Using the ioperm() OS call from a privileged process, get
  2422.      permission to access the precise I/O port addresses that correspond
  2423.      to the device registers.  Alternatively, permission can be managed
  2424.      by an independent privileged user process (i.e., a "meta OS") using
  2425.      the giveioperm() OS call
  2426.      <http://garage.ecn.purdue.edu/~papers/giveioperm.html> patch for
  2427.      Linux.
  2428.  
  2429.   2. Access device registers without an OS call by using 386 port I/O
  2430.      instructions.
  2431.  
  2432.   This second solution is preferable because it is common that multiple
  2433.   I/O devices have their registers within a single page, in which case
  2434.   the first technique would not provide protection against accessing
  2435.   other device registers that happened to reside in the same page as the
  2436.   ones intended.  Of course, the down side is that 386 port I/O
  2437.   instructions cannot be coded in C - instead, you will need to use a
  2438.   bit of assembly code.  The GCC-wrapped (usable in C programs) inline
  2439.   assembly code function for a port input of a byte value is:
  2440.  
  2441.   ______________________________________________________________________
  2442.   extern inline unsigned char
  2443.   inb(unsigned short port)
  2444.   {
  2445.       unsigned char _v;
  2446.   __asm__ __volatile__ ("inb %w1,%b0"
  2447.                         :"=a" (_v)
  2448.                         :"d" (port), "0" (0));
  2449.       return _v;
  2450.   }
  2451.   ______________________________________________________________________
  2452.  
  2453.   Similarly, the GCC-wrapped code for a byte port output is:
  2454.  
  2455.   ______________________________________________________________________
  2456.   extern inline void
  2457.   outb(unsigned char value,
  2458.   unsigned short port)
  2459.   {
  2460.   __asm__ __volatile__ ("outb %b0,%w1"
  2461.                         :/* no outputs */
  2462.                         :"a" (value), "d" (port));
  2463.   }
  2464.   ______________________________________________________________________
  2465.  
  2466.   3.4.  PVM (Parallel Virtual Machine)
  2467.  
  2468.   PVM (Parallel Virtual Machine) is a freely-available, portable,
  2469.   message-passing library generally implemented on top of sockets.  It
  2470.   is clearly established as the de-facto standard for message-passing
  2471.   cluster parallel computing.
  2472.  
  2473.   PVM supports single-processor and SMP Linux machines, as well as
  2474.   clusters of Linux machines linked by socket-capable networks (e.g.,
  2475.   SLIP, PLIP, Ethernet, ATM).  In fact, PVM will even work across groups
  2476.   of machines in which a variety of different types of processors,
  2477.   configurations, and physical networks are used - Heterogeneous
  2478.   Clusters - even to the scale of treating machines linked by the
  2479.   Internet as a parallel cluster.  PVM also provides facilities for
  2480.   parallel job control across a cluster.  Best of all, PVM has long been
  2481.   freely available (currently from
  2482.   <http://www.epm.ornl.gov/pvm/pvm_home.html>), which has led to many
  2483.   programming language compilers, application libraries, programming and
  2484.   debugging tools, etc., using it as their "portable message-passing
  2485.   target library."  There is also a network newsgroup,
  2486.   comp.parallel.pvm.
  2487.  
  2488.   It is important to note, however, that PVM message-passing calls
  2489.   generally add significant overhead to standard socket operations,
  2490.   which already had high latency.  Further, the message handling calls
  2491.   themselves do not constitute a particularly "friendly" programming
  2492.   model.
  2493.  
  2494.   Using the same Pi computation example first described in section 1.3,
  2495.   the version using C with PVM library calls is:
  2496.  
  2497.   ______________________________________________________________________
  2498.   #include <stdlib.h>
  2499.   #include <stdio.h>
  2500.   #include <pvm3.h>
  2501.  
  2502.   #define NPROC   4
  2503.  
  2504.   main(int argc, char **argv)
  2505.   {
  2506.     register double lsum, width;
  2507.     double sum;
  2508.     register int intervals, i;
  2509.     int mytid, iproc, msgtag = 4;
  2510.     int tids[NPROC];  /* array of task ids */
  2511.  
  2512.     /* enroll in pvm */
  2513.     mytid = pvm_mytid();
  2514.  
  2515.     /* Join a group and, if I am the first instance,
  2516.        iproc=0, spawn more copies of myself
  2517.     */
  2518.     iproc = pvm_joingroup("pi");
  2519.  
  2520.     if (iproc == 0) {
  2521.       tids[0] = pvm_mytid();
  2522.       pvm_spawn("pvm_pi", &argv[1], 0, NULL, NPROC-1, &tids[1]);
  2523.     }
  2524.     /* make sure all processes are here */
  2525.     pvm_barrier("pi", NPROC);
  2526.  
  2527.     /* get the number of intervals */
  2528.     intervals = atoi(argv[1]);
  2529.     width = 1.0 / intervals;
  2530.  
  2531.     lsum = 0.0;
  2532.     for (i = iproc; i<intervals; i+=NPROC) {
  2533.       register double x = (i + 0.5) * width;
  2534.       lsum += 4.0 / (1.0 + x * x);
  2535.     }
  2536.  
  2537.     /* sum across the local results & scale by width */
  2538.     sum = lsum * width;
  2539.     pvm_reduce(PvmSum, &sum, 1, PVM_DOUBLE, msgtag, "pi", 0);
  2540.  
  2541.     /* have only the console PE print the result */
  2542.     if (iproc == 0) {
  2543.       printf("Estimation of pi is %f\n", sum);
  2544.     }
  2545.  
  2546.     /* Check program finished, leave group, exit pvm */
  2547.     pvm_barrier("pi", NPROC);
  2548.     pvm_lvgroup("pi");
  2549.     pvm_exit();
  2550.     return(0);
  2551.   }
  2552.   ______________________________________________________________________
  2553.  
  2554.   3.5.  MPI (Message Passing Interface)
  2555.  
  2556.   Although PVM is the de-facto standard message-passing library, MPI
  2557.   (Message Passing Interface) is the relatively new official standard.
  2558.   The home page for the MPI standard is
  2559.   <http://www.mcs.anl.gov:80/mpi/> and the newsgroup is
  2560.   comp.parallel.mpi.
  2561.  
  2562.   However, before discussing MPI, I feel compelled to say a little bit
  2563.   about the PVM vs. MPI religious war that has been going on for the
  2564.   past few years.  I'm not really on either side.  Here's my attempt at
  2565.   a relatively unbiased summary of the differences:
  2566.  
  2567.      Execution control environment.
  2568.         Put simply, PVM has one and MPI doesn't specify how/if one is
  2569.         implemented.  Thus, things like starting a PVM program executing
  2570.         are done identically everywhere, while for MPI it depends on
  2571.         which implementation is being used.
  2572.  
  2573.      Support for heterogeneous clusters.
  2574.         PVM grew-up in the workstation cycle-scavenging world, and thus
  2575.         directly manages heterogeneous mixes of machines and operating
  2576.         systems.  In contrast, MPI largely assumes that the target is an
  2577.         MPP (Massively Parallel Processor) or a dedicated cluster of
  2578.         nearly identical workstations.
  2579.  
  2580.      Kitchen sink syndrome.
  2581.         PVM evidences a unity of purpose that MPI 2.0 doesn't.  The new
  2582.         MPI 2.0 standard includes a lot of features that go way beyond
  2583.         the basic message passing model - things like RMA (Remote Memory
  2584.         Access) and parallel file I/O.  Are these things useful?  Of
  2585.         course they are...  but learning MPI 2.0 is a lot like learning
  2586.         a complete new programming language.
  2587.  
  2588.      User interface design.
  2589.         MPI was designed after PVM, and clearly learned from it.  MPI
  2590.         offers simpler, more efficient, buffer handling and higher-level
  2591.         abstractions allowing user-defined data structures to be
  2592.         transmitted in messages.
  2593.  
  2594.      The force of law.
  2595.         By my count, there are still significantly more things designed
  2596.         to use PVM than there are to use MPI; however, porting them to
  2597.         MPI is easy, and the fact that MPI is backed by a widely-
  2598.         supported formal standard means that using MPI is, for many
  2599.         institutions, a matter of policy.
  2600.  
  2601.   Conclusion?  Well, there are at least three independently developed,
  2602.   freely available, versions of MPI that can run on clusters of Linux
  2603.   systems (and I wrote one of them):
  2604.  
  2605.   ╖  LAM (Local Area Multicomputer) is a full implementation of the MPI
  2606.      1.1 standard.  It allows MPI programs to be executed within an
  2607.      individual Linux system or across a cluster of Linux systems using
  2608.      UDP/TCP socket communication.  The system includes simple execution
  2609.      control facilities, as well as a variety of program development and
  2610.      debugging aids.  It is freely available from
  2611.      <http://www.osc.edu/lam.html>.
  2612.  
  2613.   ╖  MPICH (MPI CHameleon) is designed as a highly portable full
  2614.      implementation of the MPI 1.1 standard.  Like LAM, it allows MPI
  2615.      programs to be executed within an individual Linux system or across
  2616.      a cluster of Linux systems using UDP/TCP socket communication.
  2617.      However, the emphasis is definitely on promoting MPI by providing
  2618.      an efficient, easily retargetable, implementation.  To port this
  2619.      MPI implementation, one implements either the five functions of the
  2620.      "channel interface" or, for better performance, the full MPICH ADI
  2621.      (Abstract Device Interface).  MPICH, and lots of information about
  2622.      it and porting, are available from
  2623.      <http://www.mcs.anl.gov/mpi/mpich/>.
  2624.  
  2625.   ╖  AFMPI (Aggregate Function MPI) is a subset implementation of the
  2626.      MPI 2.0 standard.  This is the one that I wrote.  Built on top of
  2627.      the AFAPI, it is designed to showcase low-latency collective
  2628.      communication functions and RMAs, and thus provides only minimal
  2629.      support for MPI data types, communicators, etc.  It allows C
  2630.      programs using MPI to run on an individual Linux system or across a
  2631.      cluster connected by AFAPI-capable network hardware.  It is freely
  2632.      available from  <http://garage.ecn.purdue.edu/~papers/>.
  2633.  
  2634.   No matter which of these (or other) MPI implementations one uses, it
  2635.   is fairly simple to perform the most common types of communications.
  2636.  
  2637.   However, MPI 2.0 incorporates several communication paradigms that are
  2638.   fundamentally different enough so that a programmer using one of them
  2639.   might not even recognize the other coding styles as MPI.  Thus, rather
  2640.   than giving a single example program, it is useful to have an example
  2641.   of each of the fundamentally different communication paradigms that
  2642.   MPI supports.  All three programs implement the same basic algorithm
  2643.   (from section 1.3) that is used throughout this HOWTO to compute the
  2644.   value of Pi.
  2645.  
  2646.   The first MPI program uses basic MPI message-passing calls for each
  2647.   processor to send its partial sum to processor 0, which sums and
  2648.   prints the result:
  2649.  
  2650.   ______________________________________________________________________
  2651.   #include <stdlib.h>
  2652.   #include <stdio.h>
  2653.   #include <mpi.h>
  2654.  
  2655.   main(int argc, char **argv)
  2656.   {
  2657.     register double width;
  2658.     double sum, lsum;
  2659.     register int intervals, i;
  2660.     int nproc, iproc;
  2661.     MPI_Status status;
  2662.  
  2663.     if (MPI_Init(&argc, &argv) != MPI_SUCCESS) exit(1);
  2664.     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
  2665.     MPI_Comm_rank(MPI_COMM_WORLD, &iproc);
  2666.     intervals = atoi(argv[1]);
  2667.     width = 1.0 / intervals;
  2668.     lsum = 0;
  2669.     for (i=iproc; i<intervals; i+=nproc) {
  2670.       register double x = (i + 0.5) * width;
  2671.       lsum += 4.0 / (1.0 + x * x);
  2672.     }
  2673.     lsum *= width;
  2674.     if (iproc != 0) {
  2675.       MPI_Send(&lbuf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
  2676.     } else {
  2677.       sum = lsum;
  2678.       for (i=1; i<nproc; ++i) {
  2679.         MPI_Recv(&lbuf, 1, MPI_DOUBLE, MPI_ANY_SOURCE,
  2680.                  MPI_ANY_TAG, MPI_COMM_WORLD, &status);
  2681.         sum += lsum;
  2682.       }
  2683.       printf("Estimation of pi is %f\n", sum);
  2684.     }
  2685.     MPI_Finalize();
  2686.     return(0);
  2687.   }
  2688.   ______________________________________________________________________
  2689.  
  2690.   The second MPI version uses collective communication (which, for this
  2691.   particular application, is clearly the most appropriate):
  2692.  
  2693.   ______________________________________________________________________
  2694.   #include <stdlib.h>
  2695.   #include <stdio.h>
  2696.   #include <mpi.h>
  2697.  
  2698.   main(int argc, char **argv)
  2699.   {
  2700.     register double width;
  2701.     double sum, lsum;
  2702.     register int intervals, i;
  2703.     int nproc, iproc;
  2704.  
  2705.     if (MPI_Init(&argc, &argv) != MPI_SUCCESS) exit(1);
  2706.     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
  2707.     MPI_Comm_rank(MPI_COMM_WORLD, &iproc);
  2708.     intervals = atoi(argv[1]);
  2709.     width = 1.0 / intervals;
  2710.     lsum = 0;
  2711.     for (i=iproc; i<intervals; i+=nproc) {
  2712.       register double x = (i + 0.5) * width;
  2713.       lsum += 4.0 / (1.0 + x * x);
  2714.     }
  2715.     lsum *= width;
  2716.     MPI_Reduce(&lsum, &sum, 1, MPI_DOUBLE,
  2717.                MPI_SUM, 0, MPI_COMM_WORLD);
  2718.     if (iproc == 0) {
  2719.       printf("Estimation of pi is %f\n", sum);
  2720.     }
  2721.     MPI_Finalize();
  2722.     return(0);
  2723.   }
  2724.   ______________________________________________________________________
  2725.  
  2726.   The third MPI version uses the MPI 2.0 RMA mechanism for each
  2727.   processor to add its local lsum into sum on processor 0:
  2728.  
  2729.   ______________________________________________________________________
  2730.   #include <stdlib.h>
  2731.   #include <stdio.h>
  2732.   #include <mpi.h>
  2733.  
  2734.   main(int argc, char **argv)
  2735.   {
  2736.     register double width;
  2737.     double sum = 0, lsum;
  2738.     register int intervals, i;
  2739.     int nproc, iproc;
  2740.     MPI_Win sum_win;
  2741.  
  2742.     if (MPI_Init(&argc, &argv) != MPI_SUCCESS) exit(1);
  2743.     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
  2744.     MPI_Comm_rank(MPI_COMM_WORLD, &iproc);
  2745.     MPI_Win_create(&sum, sizeof(sum), sizeof(sum),
  2746.                    0, MPI_COMM_WORLD, &sum_win);
  2747.     MPI_Win_fence(0, sum_win);
  2748.     intervals = atoi(argv[1]);
  2749.     width = 1.0 / intervals;
  2750.     lsum = 0;
  2751.     for (i=iproc; i<intervals; i+=nproc) {
  2752.       register double x = (i + 0.5) * width;
  2753.       lsum += 4.0 / (1.0 + x * x);
  2754.     }
  2755.     lsum *= width;
  2756.     MPI_Accumulate(&lsum, 1, MPI_DOUBLE, 0, 0,
  2757.                    1, MPI_DOUBLE, MPI_SUM, sum_win);
  2758.     MPI_Win_fence(0, sum_win);
  2759.     if (iproc == 0) {
  2760.       printf("Estimation of pi is %f\n", sum);
  2761.     }
  2762.     MPI_Finalize();
  2763.     return(0);
  2764.   }
  2765.   ______________________________________________________________________
  2766.  
  2767.   It is useful to note that the MPI 2.0 RMA mechanism very neatly
  2768.   overcomes any potential problems with the corresponding data structure
  2769.   on various processors residing at different memory locations.  This is
  2770.   done by referencing a "window" that implies the base address,
  2771.   protection against out-of-bound accesses, and even address scaling.
  2772.   Efficient implementation is aided by the fact that RMA processing may
  2773.   be delayed until the next MPI_Win_fence.  In summary, the RMA
  2774.   mechanism may be a strange cross between distributed shared memory and
  2775.   message passing, but it is a very clean interface that potentially
  2776.   generates very efficient communication.
  2777.  
  2778.   3.6.  AFAPI (Aggregate Function API)
  2779.  
  2780.   Unlike PVM, MPI, etc., the AFAPI (Aggregate Function Application
  2781.   Program Interface) did not start life as an attempt to build a
  2782.   portable abstract interface layered on top of existing network
  2783.   hardware and software.  Rather, AFAPI began as the very hardware-
  2784.   specific low-level support library for PAPERS (Purdue's Adapter for
  2785.   Parallel Execution and Rapid Synchronization; see
  2786.   <http://garage.ecn.purdue.edu/~papers/>).
  2787.  
  2788.   PAPERS was discussed briefly in section 3.2; it is a public domain
  2789.   design custom aggregate function network that delivers latencies as
  2790.   low as a few microseconds.  However, the important thing about PAPERS
  2791.   is that it was developed as an attempt to build a supercomputer that
  2792.   would be a better target for compiler technology than existing
  2793.   supercomputers.  This is qualitatively different from most Linux
  2794.   cluster efforts and PVM/MPI, which generally focus on trying to use
  2795.   standard networks for the relatively few sufficiently coarse-grain
  2796.   parallel applications.  The fact that Linux PCs are used as components
  2797.   of PAPERS systems is simply an artifact of implementing prototypes in
  2798.   the most cost-effective way possible.
  2799.  
  2800.   The need for a common low-level software interface across more than a
  2801.   dozen different prototype implementations was what made the PAPERS
  2802.   library become standardized as AFAPI.  However, the model used by
  2803.   AFAPI is inherently simpler and better suited for the finer-grain
  2804.   interactions typical of code compiled by parallelizing compilers or
  2805.   written for SIMD architectures.  The simplicity of the model not only
  2806.   makes PAPERS hardware easy to build, but also yields surprisingly
  2807.   efficient AFAPI ports for a variety of other hardware systems, such as
  2808.   SMPs.
  2809.  
  2810.   AFAPI currently runs on Linux clusters connected using TTL_PAPERS,
  2811.   CAPERS, or WAPERS.  It also runs (without OS calls or even bus-lock
  2812.   instructions, see section 2.2) on SMP systems using a System V Shared
  2813.   Memory library called SHMAPERS.  A version that runs across Linux
  2814.   clusters using UDP broadcasts on conventional networks (e.g.,
  2815.   Ethernet) is under development.  All released versions are available
  2816.   from  <http://garage.ecn.purdue.edu/~papers/>.  All versions of the
  2817.   AFAPI are designed to be called from C or C++.
  2818.  
  2819.   The following example program is the AFAPI version of the Pi
  2820.   computation described in section 1.3.
  2821.  
  2822.   ______________________________________________________________________
  2823.   #include <stdlib.h>
  2824.   #include <stdio.h>
  2825.   #include "afapi.h"
  2826.  
  2827.   main(int argc, char **argv)
  2828.   {
  2829.     register double width, sum;
  2830.     register int intervals, i;
  2831.  
  2832.     if (p_init()) exit(1);
  2833.  
  2834.     intervals = atoi(argv[1]);
  2835.     width = 1.0 / intervals;
  2836.  
  2837.     sum = 0;
  2838.     for (i=IPROC; i<intervals; i+=NPROC) {
  2839.       register double x = (i + 0.5) * width;
  2840.       sum += 4.0 / (1.0 + x * x);
  2841.     }
  2842.  
  2843.     sum = p_reduceAdd64f(sum) * width;
  2844.  
  2845.     if (IPROC == CPROC) {
  2846.       printf("Estimation of pi is %f\n", sum);
  2847.     }
  2848.  
  2849.     p_exit();
  2850.     return(0);
  2851.   }
  2852.   ______________________________________________________________________
  2853.  
  2854.   3.7.  Other Cluster Support Libraries
  2855.  
  2856.   In addition to PVM, MPI, and AFAPI, the following libraries offer
  2857.   features that may be useful in parallel computing using a cluster of
  2858.   Linux systems.  These systems are given a lighter treatment in this
  2859.   document simply because, unlike PVM, MPI, and AFAPI, I have little or
  2860.   no direct experience with the use of these systems on Linux clusters.
  2861.   If you find any of these or other libraries to be especially useful,
  2862.   please send email to me at pplinux@ecn.purdue.edu describing what
  2863.   you've found, and I will consider adding an expanded section on that
  2864.   library.
  2865.  
  2866.   3.7.1.  Condor (process migration support)
  2867.  
  2868.   Condor is a distributed resource management system that can manage
  2869.   large heterogeneous clusters of workstations.  Its design has been
  2870.   motivated by the needs of users who would like to use the unutilized
  2871.   capacity of such clusters for their long-running, computation-
  2872.   intensive jobs.  Condor preserves a large measure of the originating
  2873.   machine's environment on the execution machine, even if the
  2874.   originating and execution machines do not share a common file system
  2875.   and/or password mechanisms.  Condor jobs that consist of a single
  2876.   process are automatically checkpointed and migrated between
  2877.   workstations as needed to ensure eventual completion.
  2878.  
  2879.   Condor is available at  <http://www.cs.wisc.edu/condor/>.  A Linux
  2880.   port exists; more information is available at
  2881.   <http://www.cs.wisc.edu/condor/linux/linux.html>.  Contact condor-
  2882.   admin@cs.wisc.edu for details.
  2883.  
  2884.   3.7.2.  DFN-RPC (German Research Network - Remote Procedure Call)
  2885.  
  2886.   The DFN-RPC, a (German Research Network Remote Procedure Call) tool,
  2887.   was developed to distribute and parallelize scientific-technical
  2888.   application programs between a workstation and a compute server or a
  2889.   cluster. The interface is optimized for applications written in
  2890.   fortran, but the DFN-RPC can also be used in a C environment.  It has
  2891.   been ported to Linux.  More information is at  <ftp://ftp.uni-
  2892.   stuttgart.de/pub/rus/dfn_rpc/README_dfnrpc.html>.
  2893.  
  2894.   3.7.3.  DQS (Distributed Queueing System)
  2895.  
  2896.   Not exactly a library, DQS 3.0 (Distributed Queueing System) is a job
  2897.   queueing system that has been developed and tested under Linux.  It is
  2898.   designed to allow both use and administration of a heterogeneous
  2899.   cluster as a single entity.  It is available from
  2900.   <http://www.scri.fsu.edu/~pasko/dqs.html>.
  2901.  
  2902.   There is also a commercial version called CODINE 4.1.1 (COmputing in
  2903.   DIstributed Network Environments).  Information on it is available
  2904.   from  <http://www.genias.de/genias_welcome.html>.
  2905.  
  2906.   3.8.  General Cluster References
  2907.  
  2908.   Because clusters can be constructed and used in so many different
  2909.   ways, there are quite a few groups that have made interesting
  2910.   contributions.  The following are references to various cluster-
  2911.   related projects that may be of general interest.  This includes a mix
  2912.   of Linux-specific and generic cluster references.  The list is given
  2913.   in alphabetical order.
  2914.  
  2915.   3.8.1.  Beowulf
  2916.  
  2917.   The Beowulf project,  <http://cesdis1.gsfc.nasa.gov/beowulf/>, centers
  2918.   on production of software for using off-the-shelf clustered
  2919.   workstations based on commodity PC-class hardware, a high-bandwidth
  2920.   cluster-internal network, and the Linux operating system.
  2921.  
  2922.   Thomas Sterling has been the driving force behind Beowulf, and
  2923.   continues to be an eloquent and outspoken proponent of Linux
  2924.   clustering for scientific computing in general. In fact, many groups
  2925.   now refer to their clusters as "Beowulf class" systems - even if the
  2926.   cluster isn't really all that similar to the official Beowulf design.
  2927.  
  2928.   Don Becker, working in support of the Beowulf project, has produced
  2929.   many of the network drivers used by Linux in general.  Many of these
  2930.   drivers have even been adapted for use in BSD.  Don also is
  2931.   responsible for many of these Linux network drivers allowing load-
  2932.   sharing across multiple parallel connections to achieve higher
  2933.   bandwidth without expensive switched hubs.  This type of load sharing
  2934.   was the original distinguishing feature of the Beowulf cluster.
  2935.  
  2936.   3.8.2.  Linux/AP+
  2937.  
  2938.   The Linux/AP+ project,  <http://cap.anu.edu.au/cap/projects/linux/>,
  2939.   is not exactly about Linux clustering, but centers on porting Linux to
  2940.   the Fujitsu AP1000+ and adding appropriate parallel processing
  2941.   enhancements.  The AP1000+ is a commercially available SPARC-based
  2942.   parallel machine that uses a custom network with a torus topology, 25
  2943.   MB/s bandwidth, and 10 microsecond latency...  in short, it looks a
  2944.   lot like a SPARC Linux cluster.
  2945.  
  2946.   3.8.3.  Locust
  2947.  
  2948.   The Locust project,  <http://www.ecsl.cs.sunysb.edu/~manish/locust/>,
  2949.   is building a distributed virtual shared memory system that uses
  2950.   compile-time information to hide message-latency and to reduce network
  2951.   traffic at run time.  Pupa is the underlying communication subsystem
  2952.   of Locust, and is implemented using Ethernet to connect 486 PCs under
  2953.   FreeBSD.  Linux?
  2954.  
  2955.   3.8.4.  Midway DSM (Distributed Shared Memory)
  2956.  
  2957.   Midway,
  2958.   <http://www.cs.cmu.edu/afs/cs.cmu.edu/project/midway/WWW/HomePage.html>,
  2959.   is a software-based DSM (Distributed Shared Memory) system, not unlike
  2960.   TreadMarks.  The good news is that it uses compile-time aids rather
  2961.   than relatively slow page-fault mechanisms, and it is free.  The bad
  2962.   news is that it doesn't run on Linux clusters.
  2963.  
  2964.   3.8.5.  Mosix
  2965.  
  2966.   MOSIX modifies the BSDI BSD/OS to provide dynamic load balancing and
  2967.   preemptive process migration across a networked group of PCs.  This is
  2968.   nice stuff not just for parallel processing, but for generally using a
  2969.   cluster much like a scalable SMP.  Will there be a Linux version?
  2970.   Look at  <http://www.cs.huji.ac.il/mosix/> for more information.
  2971.  
  2972.   3.8.6.  NOW (Network Of Workstations)
  2973.  
  2974.   The Berkeley NOW (Network Of Workstations) project,
  2975.   <http://now.cs.berkeley.edu/>, has led much of the push toward
  2976.   parallel computing using networks of workstations.  There is a lot
  2977.   work going on here, all aimed toward "demonstrating a practical 100
  2978.   processor system in the next few years."  Alas, they don't use Linux.
  2979.  
  2980.   3.8.7.  Parallel Processing Using Linux
  2981.  
  2982.   The parallel processing using Linux WWW site,
  2983.   <http://yara.ecn.purdue.edu/~pplinux/>, is the home of this HOWTO and
  2984.   many related documents including online slides for a full-day
  2985.   tutorial.  Aside from the work on the PAPERS project, the Purdue
  2986.   University School of Electrical and Computer Engineering generally has
  2987.   been a leader in parallel processing; this site was established to
  2988.   help others apply Linux PCs for parallel processing.
  2989.  
  2990.   Since Purdue's first cluster of Linux PCs was assembled in February
  2991.   1994, there have been many Linux PC clusters assembled at Purdue,
  2992.   including several with video walls.  Although these clusters used 386,
  2993.   486, and Pentium systems (no Pentium Pro systems), Intel recently
  2994.   awarded Purdue a donation which will allow it to construct multiple
  2995.   large clusters of Pentium II systems (with as many as 165 machines
  2996.   planned for a single cluster).  Although these clusters all have/will
  2997.   have PAPERS networks, most also have conventional networks.
  2998.  
  2999.   3.8.8.  Pentium Pro Cluster Workshop
  3000.  
  3001.   In Des Moines, Iowa, April 10-11, 1997, AMES Laboratory held the
  3002.   Pentium Pro Cluster Workshop.  The WWW site from this workshop,
  3003.   <http://www.scl.ameslab.gov/workshops/PPCworkshop.html>, contains a
  3004.   wealth of PC cluster information gathered from all the attendees.
  3005.  
  3006.   3.8.9.  TreadMarks DSM (Distributed Shared Memory)
  3007.  
  3008.   DSM (Distributed Shared Memory) is a technique whereby a message-
  3009.   passing system can appear to behave as an SMP.  There are quite a few
  3010.   such systems, most of which use the OS page-fault mechanism to trigger
  3011.   message transmissions.  TreadMarks,
  3012.   <http://www.cs.rice.edu/~willy/TreadMarks/overview.html>, is one of
  3013.   the more efficient of such systems and does run on Linux clusters.
  3014.   The bad news is "TreadMarks is being distributed at a small cost to
  3015.   universities and nonprofit institutions." For more information about
  3016.   the software, contact treadmarks@ece.rice.edu.
  3017.  
  3018.   3.8.10.  U-Net (User-level NETwork interface architecture)
  3019.  
  3020.   The U-Net (User-level NETwork interface architecture) project at
  3021.   Cornell,  <http://www2.cs.cornell.edu/U-Net/Default.html>, attempts to
  3022.   provide low-latency and high-bandwidth using commodity network
  3023.   hardware by by virtualizing the network interface so that applications
  3024.   can send and receive messages without operating system intervention.
  3025.   U-Net runs on Linux PCs using a DECchip DC21140 based Fast Ethernet
  3026.   card or a Fore Systems PCA-200 (not PCA-200E) ATM card.
  3027.  
  3028.   3.8.11.  WWT (Wisconsin Wind Tunnel)
  3029.  
  3030.   There is really quite a lot of cluster-related work at Wisconsin.  The
  3031.   WWT (Wisconsin Wind Tunnel) project,  <http://www.cs.wisc.edu/~wwt/>,
  3032.   is doing all sorts of work toward developing a "standard" interface
  3033.   between compilers and the underlying parallel hardware.  There is the
  3034.   Wisconsin COW (Cluster Of Workstations), Cooperative Shared Memory and
  3035.   Tempest, the Paradyn Parallel Performance Tools, etc.  Unfortunately,
  3036.   there is not much about Linux.
  3037.  
  3038.   4.  SIMD Within A Register (e.g., using MMX)
  3039.  
  3040.   SIMD (Single Instruction stream, Multiple Data stream) Within A
  3041.   Register (SWAR) isn't a new idea.  Given a machine with k-bit
  3042.   registers, data paths, and function units, it has long been known that
  3043.   ordinary register operations can function as SIMD parallel operations
  3044.   on n, k/n-bit, integer field values.  However, it is only with the
  3045.   recent push for multimedia that the 2x to 8x speedup offered by SWAR
  3046.   techniques has become a concern for mainstream computing.  The 1997
  3047.   versions of most microprocessors incorporate hardware support for
  3048.   SWAR:
  3049.  
  3050.   ╖  AMD K6 MMX (MultiMedia eXtensions)
  3051.  
  3052.   ╖  Cyrix M2 MMX (MultiMedia eXtensions)
  3053.  
  3054.   ╖  Digital Alpha MAX (MultimediA eXtensions)
  3055.  
  3056.   ╖  Hewlett-Packard PA-RISC MAX (Multimedia Acceleration eXtensions)
  3057.  
  3058.   ╖  Intel Pentium II & Pentium with MMX (MultiMedia eXtensions)
  3059.  
  3060.   ╖  Microunity Mediaprocessor SIGD (Single Instruction on Groups of
  3061.      Data)
  3062.  
  3063.   ╖  MIPS Digital Media eXtension (MDMX, pronounced Mad Max)
  3064.  
  3065.   ╖  Sun SPARC V9 VIS (Visual Instruction Set)
  3066.  
  3067.   There are a few holes in the hardware support provided by the new
  3068.   microprocessors, quirks like only supporting some operations for some
  3069.   field sizes.  It is important to remember, however, that you don't
  3070.   need any hardware support for many SWAR operations to be efficient.
  3071.   For example, bitwise operations are not affected by the logical
  3072.   partitioning of a register.
  3073.  
  3074.   4.1.  SWAR: What Is It Good For?
  3075.  
  3076.   Although every modern processor is capable of executing with at least
  3077.   some SWAR parallelism, the sad fact is that even the best SWAR-
  3078.   enhanced instruction sets do not support very general-purpose
  3079.   parallelism.  In fact, many people have noticed that the performance
  3080.   difference between Pentium and "Pentium with MMX technology" is often
  3081.   due to things like the larger L1 cache that coincided with appearance
  3082.   of MMX.  So, realistically, what is SWAR (or MMX) good for?
  3083.  
  3084.   ╖  Integers only, the smaller the better.  Two 32-bit values fit in a
  3085.      64-bit MMX register, but so do eight one-byte characters or even an
  3086.      entire chess board worth of one-bit values.
  3087.  
  3088.      Note: there will be a floating-point version of MMX, although very
  3089.      little has been said about it at this writing.  Cyrix has posted a
  3090.      set of slides,  <ftp://ftp.cyrix.com/developr/mpf97rm.pdf>, that
  3091.      includes a few comments about MMFP.  Apparently, MMFP will support
  3092.      two 32-bit floating-point numbers to be packed into a 64-bit MMX
  3093.      register; combining this with two MMFP pipelines will yield four
  3094.      single-precision FLOPs per clock.
  3095.  
  3096.   ╖  SIMD or vector-style parallelism.  The same operation is applied to
  3097.      all fields simultaneously.  There are ways to nullify the effects
  3098.      on selected fields (i.e., equivalent to SIMD enable masking), but
  3099.      they complicate coding and hurt performance.
  3100.  
  3101.   ╖  Localized, regular (preferably packed), memory reference patterns.
  3102.      SWAR in general, and MMX in particular, are terrible at randomly-
  3103.      ordered accesses; gathering a vector x[y] (where y is an index
  3104.      array) is prohibitively expensive.
  3105.  
  3106.   These are serious restrictions, but this type of parallelism occurs in
  3107.   many parallel algorithms - not just multimedia applications.  For the
  3108.   right type of algorithm, SWAR is more effective than SMP or cluster
  3109.   parallelism...  and it doesn't cost anything to use it.
  3110.  
  3111.   4.2.  Introduction To SWAR Programming
  3112.  
  3113.   The basic concept of SWAR, SIMD Within A Register, is that operations
  3114.   on word-length registers can be used to speed-up computations by
  3115.   performing SIMD parallel operations on n k/n-bit field values.
  3116.   However, making use of SWAR technology can be awkward, and some SWAR
  3117.   operations are actually more expensive than the corresponding
  3118.   sequences of serial operations because they require additional
  3119.   instructions to enforce the field partitioning.
  3120.  
  3121.   To illustrate this point, let's consider a greatly simplified SWAR
  3122.   mechanism that manages four 8-bit fields within each 32-bit register.
  3123.   The values in two registers might be represented as:
  3124.  
  3125.   ______________________________________________________________________
  3126.            PE3     PE2     PE1     PE0
  3127.         +-------+-------+-------+-------+
  3128.   Reg0  | D 7:0 | C 7:0 | B 7:0 | A 7:0 |
  3129.         +-------+-------+-------+-------+
  3130.   Reg1  | H 7:0 | G 7:0 | F 7:0 | E 7:0 |
  3131.         +-------+-------+-------+-------+
  3132.   ______________________________________________________________________
  3133.  
  3134.   This simply indicates that each register is viewed as essentially a
  3135.   vector of four independent 8-bit integer values.  Alternatively, think
  3136.   of A and E as values in Reg0 and Reg1 of processing element 0 (PE0), B
  3137.   and F as values in PE1's registers, and so forth.
  3138.  
  3139.   The remainder of this document briefly reviews the basic classes of
  3140.   SIMD parallel operations on these integer vectors and how these
  3141.   functions can be implemented.
  3142.  
  3143.   4.2.1.  Polymorphic Operations
  3144.  
  3145.   Some SWAR operations can be performed trivially using ordinary 32-bit
  3146.   integer operations, without concern for the fact that the operation is
  3147.   really intended to operate independently in parallel on these 8-bit
  3148.   fields.  We call any such SWAR operation polymorphic, since the
  3149.   function is unaffected by the field types (sizes).
  3150.  
  3151.   Testing if any field is non-zero is polymorphic, as are all bitwise
  3152.   logic operations.  For example, an ordinary bitwise-and operation (C's
  3153.   & operator) performs a bitwise and no matter what the field sizes are.
  3154.   A simple bitwise and of the above registers yields:
  3155.  
  3156.   ______________________________________________________________________
  3157.             PE3       PE2       PE1       PE0
  3158.         +---------+---------+---------+---------+
  3159.   Reg2  | D&H 7:0 | C&G 7:0 | B&F 7:0 | A&E 7:0 |
  3160.         +---------+---------+---------+---------+
  3161.   ______________________________________________________________________
  3162.  
  3163.   Because the bitwise and operation always has the value of result bit k
  3164.   affected only by the values of the operand bit k values, all field
  3165.   sizes are supported using the same single instruction.
  3166.  
  3167.   4.2.2.  Partitioned Operations
  3168.  
  3169.   Unfortunately, lots of important SWAR operations are not polymorphic.
  3170.   Arithmetic operations such as add, subtract, multiply, and divide are
  3171.   all subject to carry/borrow interactions between fields.  We call such
  3172.   SWAR operations partitioned, because each such operation must
  3173.   effectively partition the operands and result to prevent interactions
  3174.   between fields.  However, there are actually three different methods
  3175.   that can be used to achieve this effect.
  3176.  
  3177.   4.2.2.1.  Partitioned Instructions
  3178.  
  3179.   Perhaps the most obvious approach to implementing partitioned
  3180.   operations is to provide hardware support for "partitioned parallel
  3181.   instructions" that cut the carry/borrow logic between fields.  This
  3182.   approach can yield the highest performance, but it requires a change
  3183.   to the processor's instruction set and generally places many
  3184.   restrictions on field size (e.g., 8-bit fields might be supported, but
  3185.   not 12-bit fields).
  3186.  
  3187.   The AMD/Cyrix/Intel MMX, Digital MAX, HP MAX, and Sun VIS all
  3188.   implement restricted versions of partitioned instructions.
  3189.   Unfortunately, these different instruction set extensions have
  3190.   significantly different restrictions, making algorithms somewhat non-
  3191.   portable between them.  For example, consider the following sampling
  3192.   of partitioned operations:
  3193.  
  3194.   ______________________________________________________________________
  3195.     Instruction           AMD/Cyrix/Intel MMX   DEC MAX   HP MAX   Sun VIS
  3196.   +---------------------+---------------------+---------+--------+---------+
  3197.   | Absolute Difference |                     |       8 |        |       8 |
  3198.   +---------------------+---------------------+---------+--------+---------+
  3199.   | Merge Maximum       |                     |   8, 16 |        |         |
  3200.   +---------------------+---------------------+---------+--------+---------+
  3201.   | Compare             |           8, 16, 32 |         |        |  16, 32 |
  3202.   +---------------------+---------------------+---------+--------+---------+
  3203.   | Multiply            |                  16 |         |        |    8x16 |
  3204.   +---------------------+---------------------+---------+--------+---------+
  3205.   | Add                 |           8, 16, 32 |         |     16 |  16, 32 |
  3206.   +---------------------+---------------------+---------+--------+---------+
  3207.   ______________________________________________________________________
  3208.  
  3209.   In the table, the numbers indicate the field sizes, in bits, for which
  3210.   each operation is supported.  Even though the table omits many
  3211.   instructions including all the more exotic ones, it is clear that
  3212.   there are many differences.  The direct result is that high-level
  3213.   languages (HLLs) really are not very effective as programming models,
  3214.   and portability is generally poor.
  3215.  
  3216.   4.2.2.2.  Unpartitioned Operations With Correction Code
  3217.  
  3218.   Implementing partitioned operations using partitioned instructions can
  3219.   certainly be efficient, but what do you do if the partitioned
  3220.   operation you need is not supported by the hardware?  The answer is
  3221.   that you use a series of ordinary instructions to perform the
  3222.   operation with carry/borrow across fields, and then correct for the
  3223.   undesired field interactions.
  3224.  
  3225.   This is a purely software approach, and the corrections do introduce
  3226.   overhead, but it works with fully general field partitioning.  This
  3227.   approach is also fully general in that it can be used either to fill
  3228.   gaps in the hardware support for partitioned instructions, or it can
  3229.   be used to provide full functionality for target machines that have no
  3230.   hardware support at all.  In fact, by expressing the code sequences in
  3231.   a language like C, this approach allows SWAR programs to be fully
  3232.   portable.
  3233.  
  3234.   The question immediately arises:  precisely how inefficient is it to
  3235.   simulate SWAR partitioned operations using unpartitioned operations
  3236.   with correction code?  Well, that is certainly the $64k question...
  3237.   but many operations are not as difficult as one might expect.
  3238.  
  3239.   Consider implementing a four-element 8-bit integer vector add of two
  3240.   source vectors, x+y, using ordinary 32-bit operations.
  3241.  
  3242.   An ordinary 32-bit add might actually yield the correct result, but
  3243.   not if any 8-bit field carries into the next field.  Thus, our goal is
  3244.   simply to ensure that such a carry does not occur.  Because adding two
  3245.   k-bit fields generates an at most k+1 bit result, we can ensure that
  3246.   no carry occurs by simply "masking out" the most significant bit of
  3247.   each field.  This is done by bitwise anding each operand with
  3248.   0x7f7f7f7f and then performing an ordinary 32-bit add.
  3249.  
  3250.   ______________________________________________________________________
  3251.   t = ((x & 0x7f7f7f7f) + (y & 0x7f7f7f7f));
  3252.   ______________________________________________________________________
  3253.  
  3254.   That result is correct...  except for the most significant bit within
  3255.   each field.  Computing the correct value for each field is simply a
  3256.   matter of doing two 1-bit partitioned adds of the most significant
  3257.   bits from x and y to the 7-bit carry result which was computed for t.
  3258.   Fortunately, a 1-bit partitioned add is implemented by an ordinary
  3259.   exclusive or operation.  Thus, the result is simply:
  3260.  
  3261.   ______________________________________________________________________
  3262.   (t ^ ((x ^ y) & 0x80808080))
  3263.   ______________________________________________________________________
  3264.  
  3265.   Ok, well, maybe that isn't so simple.  After all, it is six operations
  3266.   to do just four adds.  However, notice that the number of operations
  3267.   is not a function of how many fields there are...  so, with more
  3268.   fields, we get speedup.  In fact, we may get speedup anyway simply
  3269.   because the fields were loaded and stored in a single (integer vector)
  3270.   operation, register availability may be improved, and there are fewer
  3271.   dynamic code scheduling dependencies (because partial word references
  3272.   are avoided).
  3273.  
  3274.   4.2.2.3.  Controlling Field Values
  3275.  
  3276.   While the other two approaches to partitioned operation implementation
  3277.   both center on getting the maximum space utilization for the
  3278.   registers, it can be computationally more efficient to instead control
  3279.   the field values so that inter-field carry/borrow events should never
  3280.   occur.  For example, if we know that all the field values being added
  3281.   are such that no field overflow will occur, a partitioned add
  3282.   operation can be implemented using an ordinary add instruction; in
  3283.   fact, given this constraint, an ordinary add instruction appears
  3284.   polymorphic, and is usable for any field sizes without correction
  3285.   code.  The question thus becomes how to ensure that field values will
  3286.   not cause carry/borrow events.
  3287.  
  3288.   One way to ensure this property is to implement partitioned
  3289.   instructions that can restrict the range of field values.  The Digital
  3290.   MAX vector minimum and maximum instructions can be viewed as hardware
  3291.   support for clipping field values to avoid inter-field carry/borrow.
  3292.  
  3293.   However, suppose that we do not have partitioned instructions that can
  3294.   efficiently restrict the range of field values...  is there a
  3295.   sufficient condition that can be cheaply imposed to ensure
  3296.   carry/borrow events will not interfere with adjacent fields?  The
  3297.   answer lies in analysis of the arithmetic properties.  Adding two k-
  3298.   bit numbers generates a result with at most k+1 bits; thus, a field of
  3299.   k+1 bits can safely contain such an operation despite using ordinary
  3300.   instructions.
  3301.  
  3302.   Thus, suppose that the 8-bit fields in our earlier example are now
  3303.   7-bit fields with 1-bit "carry/borrow spacers":
  3304.  
  3305.   ______________________________________________________________________
  3306.                 PE3          PE2          PE1          PE0
  3307.         +----+-------+----+-------+----+-------+----+-------+
  3308.   Reg0  | D' | D 6:0 | C' | C 6:0 | B' | B 6:0 | A' | A 6:0 |
  3309.         +----+-------+----+-------+----+-------+----+-------+
  3310.   ______________________________________________________________________
  3311.  
  3312.   A vector of 7-bit adds is performed as follows.  Let us assume that,
  3313.   prior to the start of any partitioned operation, all the carry spacer
  3314.   bits (A', B', C', and D') have the value 0.  By simply executing an
  3315.   ordinary add operation, all the fields obtain the correct 7-bit
  3316.   values; however, some spacer bit values might now be 1.  We can
  3317.   correct this by just one more conventional operation, masking-out the
  3318.   spacer bits.  Our 7-bit integer vector add, x+y, is thus:
  3319.  
  3320.   ______________________________________________________________________
  3321.   ((x + y) & 0x7f7f7f7f)
  3322.   ______________________________________________________________________
  3323.  
  3324.   This is just two instructions for four adds, clearly yielding good
  3325.   speedup.
  3326.  
  3327.   The sharp reader may have noticed that setting the spacer bits to 0
  3328.   does not work for subtract operations.  The correction is, however,
  3329.   remarkably simple.  To compute x-y, we simply ensure the initial
  3330.   condition that the spacers in x are all 1, while the spacers in y are
  3331.   all 0.  In the worst case, we would thus get:
  3332.  
  3333.   ______________________________________________________________________
  3334.   (((x | 0x80808080) - y) & 0x7f7f7f7f)
  3335.   ______________________________________________________________________
  3336.  
  3337.   However, the additional bitwise or operation can often be optimized
  3338.   out by ensuring that the operation generating the value for x used |
  3339.   0x80808080 rather than & 0x7f7f7f7f as the last step.
  3340.  
  3341.   Which method should be used for SWAR partitioned operations?  The
  3342.   answer is simply "whichever yields the best speedup."  Interestingly,
  3343.   the ideal method to use may be different for different field sizes
  3344.   within the same program running on the same machine.
  3345.  
  3346.   4.2.3.  Communication & Type Conversion Operations
  3347.  
  3348.   Although some parallel computations, including many operations on
  3349.   image pixels, have the property that the ith value in a vector is a
  3350.   function only of values that appear in the ith position of the operand
  3351.   vectors, this is generally not the case.  For example, even pixel
  3352.   operations such as smoothing require values from adjacent pixels as
  3353.   operands, and transformations like FFTs require more complex (less
  3354.   localized) communication patterns.
  3355.  
  3356.   It is not difficult to efficiently implement 1-dimensional nearest
  3357.   neighbor communication for SWAR using unpartitioned shift operations.
  3358.   For example, to move a value from PEi to PE(i+1), a simple shift
  3359.   operation suffices.  If the fields are 8-bits in length, we would use:
  3360.  
  3361.   ______________________________________________________________________
  3362.   (x << 8)
  3363.   ______________________________________________________________________
  3364.  
  3365.   Still, it isn't always quite that simple.  For example, to move a
  3366.   value from PEi to PE(i-1), a simple shift operation might suffice...
  3367.   but the C language does not specify if shifts right preserve the sign
  3368.   bit, and some machines only provide signed shift right.  Thus, in the
  3369.   general case, we must explicitly zero the potentially replicated sign
  3370.   bits:
  3371.  
  3372.   ______________________________________________________________________
  3373.   ((x >> 8) & 0x00ffffff)
  3374.   ______________________________________________________________________
  3375.  
  3376.   Adding "wrap-around connections" is also reasonably efficient using
  3377.   unpartitioned shifts.  For example, to move a value from PEi to
  3378.   PE(i+1) with wraparound:
  3379.  
  3380.   ______________________________________________________________________
  3381.   ((x << 8) | ((x >> 24) & 0x000000ff))
  3382.   ______________________________________________________________________
  3383.  
  3384.   The real problem comes when more general communication patterns must
  3385.   be implemented.  Only the HP MAX instruction set supports arbitrary
  3386.   rearrangement of fields with a single instruction, which is called
  3387.   Permute.  This Permute instruction is really misnamed; not only can it
  3388.   perform an arbitrary permutation of the fields, but it also allows
  3389.   repetition.  In short, it implements an arbitrary x[y] operation.
  3390.  
  3391.   Unfortunately, x[y] is very difficult to implement without such an
  3392.   instruction.  The code sequence is generally both long and
  3393.   inefficient; in fact, it is sequential code.  This is very
  3394.   disappointing.  The relatively high speed of x[y] operations in the
  3395.   MasPar MP1/MP2 and Thinking Machines CM1/CM2/CM200 SIMD supercomputers
  3396.   was one of the key reasons these machines performed well.  However,
  3397.   x[y] has always been slower than nearest neighbor communication, even
  3398.   on those supercomputers, so many algorithms have been designed to
  3399.   minimize the need for x[y] operations.  In short, without hardware
  3400.   support, it is probably best to develop SWAR algorithms as though x[y]
  3401.   wasn't legal...  or at least isn't cheap.
  3402.  
  3403.   4.2.4.  Recurrence Operations (Reductions, Scans, etc.)
  3404.  
  3405.   A recurrence is a computation in which there is an apparently
  3406.   sequential relationship between values being computed.  However, if
  3407.   these recurrences involve associative operations, it may be possible
  3408.   to recode the computation using a tree-structured parallel algorithm.
  3409.  
  3410.   The most common type of parallelizable recurrence is probably the
  3411.   class known as associative reductions.  For example, to compute the
  3412.   sum of a vector's values, one commonly writes purely sequential C code
  3413.   like:
  3414.  
  3415.   ______________________________________________________________________
  3416.   t = 0;
  3417.   for (i=0; i<MAX; ++i) t += x[i];
  3418.   ______________________________________________________________________
  3419.  
  3420.   However, the order of the additions is rarely important.  Floating
  3421.   point and saturation math can yield different answers if the order of
  3422.   additions is changed, but ordinary wrap-around integer additions will
  3423.   yield the same results independent of addition order.  Thus, we can
  3424.   re-write this sequence into a tree-structured parallel summation in
  3425.   which we first add pairs of values, then pairs of those partial sums,
  3426.   and so forth, until a single final sum results.  For a vector of four
  3427.   8-bit values, just two addition steps are needed; the first step does
  3428.   two 8-bit adds, yielding two 16-bit result fields (each containing a
  3429.   9-bit result):
  3430.  
  3431.   ______________________________________________________________________
  3432.   t = ((x & 0x00ff00ff) + ((x >> 8) & 0x00ff00ff));
  3433.   ______________________________________________________________________
  3434.  
  3435.   The second step adds these two 9-bit values in 16-bit fields to
  3436.   produce a single 10-bit result:
  3437.  
  3438.   ______________________________________________________________________
  3439.   ((t + (t >> 16)) & 0x000003ff)
  3440.   ______________________________________________________________________
  3441.  
  3442.   Actually, the second step performs two 16-bit field adds...  but the
  3443.   top 16-bit add is meaningless, which is why the result is masked to a
  3444.   single 10-bit result value.
  3445.  
  3446.   Scans, also known as "parallel prefix" operations, are somewhat harder
  3447.   to implement efficiently.  This is because, unlike reductions, scans
  3448.   produce partitioned results.  For this reason, scans can be
  3449.   implemented using a fairly obvious sequence of partitioned operations.
  3450.  
  3451.   4.3.  MMX SWAR Under Linux
  3452.  
  3453.   For Linux, IA32 processors are our primary concern.  The good news is
  3454.   that AMD, Cyrix, and Intel all implement the same MMX instructions.
  3455.   However, MMX performance varies; for example, the K6 has only one MMX
  3456.   pipeline - the Pentium with MMX has two.  The only really bad news is
  3457.   that Intel is still running those stupid MMX commercials....  ;-)
  3458.  
  3459.   There are really three approaches to using MMX for SWAR:
  3460.  
  3461.   1. Use routines from an MMX library.  In particular, Intel has
  3462.      developed several "performance libraries,"
  3463.      <http://developer.intel.com/drg/tools/ad.htm>, that offer a variety
  3464.      of hand-optimized routines for common multimedia tasks.  With a
  3465.      little effort, many non-multimedia algorithms can be reworked to
  3466.      enable some of the most compute-intensive portions to be
  3467.      implemented using one or more of these library routines.  These
  3468.      libraries are not currently available for Linux, but could be
  3469.      ported.
  3470.  
  3471.   2. Use MMX instructions directly.  This is somewhat complicated by two
  3472.      facts.  The first problem is that MMX might not be available on the
  3473.      processor, so an alternative implementation must also be provided.
  3474.      The second problem is that the IA32 assembler generally used under
  3475.      Linux does not currently recognize MMX instructions.
  3476.  
  3477.   3. Use a high-level language or module compiler that can directly
  3478.      generate appropriate MMX instructions.  Such tools are currently
  3479.      under development, but none is yet fully functional under Linux.
  3480.      For example, at Purdue University (
  3481.      <http://dynamo.ecn.purdue.edu/~hankd/SWAR/>) we are currently
  3482.      developing a compiler that will take functions written in an
  3483.      explicitly parallel C dialect and will generate SWAR modules that
  3484.      are callable as C functions, yet make use of whatever SWAR support
  3485.      is available, including MMX.  The first prototype module compilers
  3486.      were built in Fall 1996, however, bringing this technology to a
  3487.      usable state is taking much longer than was originally expected.
  3488.  
  3489.   In summary, MMX SWAR is still awkward to use.  However, with a little
  3490.   extra effort, the second approach given above can be used now.  Here
  3491.   are the basics:
  3492.  
  3493.   1. You cannot use MMX if your processor does not support it.  The
  3494.      following GCC code can be used to test if MMX is supported on your
  3495.      processor.  It returns 0 if not, non-zero if it is supported.
  3496.  
  3497.      ___________________________________________________________________
  3498.      inline extern
  3499.      int mmx_init(void)
  3500.      {
  3501.              int mmx_available;
  3502.  
  3503.              __asm__ __volatile__ (
  3504.                      /* Get CPU version information */
  3505.                      "movl $1, %%eax\n\t"
  3506.                      "cpuid\n\t"
  3507.                      "andl $0x800000, %%edx\n\t"
  3508.                      "movl %%edx, %0"
  3509.                      : "=q" (mmx_available)
  3510.                      : /* no input */
  3511.              );
  3512.              return mmx_available;
  3513.      }
  3514.      ___________________________________________________________________
  3515.  
  3516.   2. An MMX register essentially holds one of what GCC would call an
  3517.      unsigned long long.  Thus, memory-based variables of this type
  3518.      become the communication mechanism between your MMX modules and the
  3519.      C programs that call them.  Alternatively, you can declare your MMX
  3520.      data as any 64-bit aligned data structure (it is convenient to
  3521.      ensure 64-bit alignment by declaring your data type as a union with
  3522.      an unsigned long long field).
  3523.  
  3524.   3. If MMX is available, you can write your MMX code using the .byte
  3525.      assembler directive to encode each instruction.  This is painful
  3526.      stuff to do by hand, but not difficult for a compiler to generate.
  3527.      For example, the MMX instruction PADDB MM0,MM1 could be encoded as
  3528.      the GCC in-line assembly code:
  3529.  
  3530.      ___________________________________________________________________
  3531.      __asm__ __volatile__ (".byte 0x0f, 0xfc, 0xc1\n\t");
  3532.      ___________________________________________________________________
  3533.  
  3534.   Remember that MMX uses some of the same hardware that is used for
  3535.   floating point operations, so code intermixed with MMX code must not
  3536.   invoke any floating point operations.  The floating point stack also
  3537.   should be empty before executing any MMX code; the floating point
  3538.   stack is normally empty at the beginning of a C function that does not
  3539.   use floating point.
  3540.  
  3541.   4. Exit your MMX code by executing the EMMS instruction, which can be
  3542.      encoded as:
  3543.  
  3544.      ___________________________________________________________________
  3545.      __asm__ __volatile__ (".byte 0x0f, 0x77\n\t");
  3546.      ___________________________________________________________________
  3547.  
  3548.   If the above looks very awkward and crude, it is.  However, MMX is
  3549.   still quite young....  future versions of this document will offer
  3550.   better ways to program MMX SWAR.
  3551.  
  3552.   5.  Linux-Hosted Attached Processors
  3553.  
  3554.   Although this approach has recently fallen out of favor, it is
  3555.   virtually impossible for other parallel processing methods to achieve
  3556.   the low cost and high performance possible by using a Linux system to
  3557.   host an attached parallel computing system.  The problem is that very
  3558.   little software support is available; you are pretty much on your own.
  3559.  
  3560.   5.1.  A Linux PC Is A Good Host
  3561.  
  3562.   In general, attached parallel processors tend to be specialized to
  3563.   perform specific types of functions.
  3564.  
  3565.   Before becoming discouraged by the fact that you are somewhat on your
  3566.   own, it is useful to understand that, although it may be difficult to
  3567.   get a Linux PC to appropriately host a particular system, a Linux PC
  3568.   is one of the few platforms well suited to this type of use.
  3569.  
  3570.   PCs make a good host for two primary reasons.  The first is the cheap
  3571.   and easy expansion capability; resources such as more memory, disks,
  3572.   networks, etc., are trivially added to a PC.  The second is the ease
  3573.   of interfacing.  Not only are ISA and PCI bus prototyping cards widely
  3574.   available, but the parallel port offers reasonable performance in a
  3575.   completely non-invasive interface.  The IA32 separate I/O space also
  3576.   facilitates interfacing by providing hardware I/O address protection
  3577.   at the level of individual I/O port addresses.
  3578.  
  3579.   Linux also makes a good host OS.  The free availability of full source
  3580.   code, and extensive "hacking" guides, obviously are a tremendous help.
  3581.   However, Linux also provides good near-real-time scheduling, and there
  3582.   is even a true real-time version of Linux at
  3583.   <http://luz.cs.nmt.edu/~rtlinux/>.  Perhaps even more important is the
  3584.   fact that while providing a full UNIX environment, Linux can support
  3585.   development tools that were written to run under Microsoft DOS and/or
  3586.   Windows.  MSDOS programs can execute within a Linux process using
  3587.   dosemu to provide a protected virtual machine that can literally run
  3588.   MSDOS.  Linux support for Windows 3.xx programs is even more direct:
  3589.   free software such as wine,  <http://www.linpro.no/wine/>, simulates
  3590.   Windows 3.11 well enough for most programs to execute correctly and
  3591.   efficiently within a UNIX/X environment.
  3592.  
  3593.   The following two sections give examples of attached parallel systems
  3594.   that I'd like to see supported under Linux....
  3595.  
  3596.   5.2.  Did You DSP That?
  3597.  
  3598.   There is a thriving market for high-performance DSP (Digital Signal
  3599.   Processing) processors.  Although these chips were generally designed
  3600.   to be embedded in application-specific systems, they also make great
  3601.   attached parallel computers.  Why?
  3602.  
  3603.   ╖  Many of them, such as the Texas Instruments ( <http://www.ti.com/>)
  3604.      TMS320 and the Analog Devices ( <http://www.analog.com/>) SHARC DSP
  3605.      families, are designed to construct parallel machines with little
  3606.      or no "glue" logic.
  3607.  
  3608.   ╖  They are cheap, especially per MIP or MFLOP.  Including the cost of
  3609.      basic support logic, it is not unheard of for a DSP processor to be
  3610.      one tenth the cost of a PC processor with comparable performance.
  3611.  
  3612.   ╖  They do not use much power nor generate much heat.  This means that
  3613.      it is possible to have a bunch of these chips powered by a
  3614.      conventional PC's power supply - and enclosing them in your PC's
  3615.      case will not turn it into an oven.
  3616.  
  3617.   ╖  There are strange-looking things in most DSP instruction sets that
  3618.      high-level (e.g., C) compilers are unlikely to use well - for
  3619.      example, "Bit Reverse Addressing."  Using an attached parallel
  3620.      system, it is possible to straightforwardly compile and run most
  3621.      code on the host, while running the most time-consuming few
  3622.      algorithms on the DSPs as carefully hand-tuned code.
  3623.  
  3624.   ╖  These DSP processors are not really designed to run a UNIX-like OS,
  3625.      and generally are not very good as stand-alone general-purpose
  3626.      computer processors.  For example, many do not have memory
  3627.      management hardware.  In other words, they work best when hosted by
  3628.      a more general-purpose machine...  such as a Linux PC.
  3629.  
  3630.   Although some audio cards and modems include DSP processors that Linux
  3631.   drivers can access, the big payoff comes from using an attached
  3632.   parallel system that has four or more DSP processors.
  3633.  
  3634.   Because the Texas Instruments TMS320 series,
  3635.   <http://www.ti.com/sc/docs/dsps/dsphome.htm>, has been very popular
  3636.   for a long time, and it is trivial to construct a TMS320-based
  3637.   parallel processor, there are quite a few such systems available.
  3638.   There are both integer-only and floating-point capable versions of the
  3639.   TMS320; older designs used a somewhat unusual single-precision
  3640.   floating-point format, but the new models support IEEE formats.  The
  3641.   older TMS320C4x (aka, 'C4x) achieves up to 80 MFLOPS using the TI-
  3642.   specific single-precision floating-point format; in contrast, a single
  3643.   'C67x will provide up to 1 GFLOPS single-precision or 420 MFLOPS
  3644.   double-precision for IEEE floating point calculations, using a VLIW-
  3645.   based chip architecture called VelociTI.  Not only is it easy to
  3646.   configure a group of these chips as a multiprocessor, but in a single
  3647.   chip, the 'C8x multiprocessor will provide a 100 MFLOPS IEEE floating-
  3648.   point RISC master processor along with either two or four integer
  3649.   slave DSPs.
  3650.  
  3651.   The other DSP processor family that has been used in more than a few
  3652.   attached parallel systems lately is the SHARC (aka, ADSP-2106x) from
  3653.   Analog Devices  <http://www.analog.com/>.  These chips can be
  3654.   configured as a 6-processor shared memory multiprocessor without
  3655.   external glue logic, and larger systems also can be configured using
  3656.   six 4-bit links/chip.  Most of the larger systems seem targeted to
  3657.   military applications, and are a bit pricey.  However, Integrated
  3658.   Computing Engines, Inc.,  <http://www.iced.com/>, makes an interesting
  3659.   little two-board PCI card set called GreenICE.  This unit contains an
  3660.   array of 16 SHARC processors, and is capable of delivering a peak
  3661.   speed of about 1.9 GFLOPS using a single-precision IEEE format.
  3662.   GreenICE costs less than $5,000.
  3663.  
  3664.   In my opinion, attached parallel DSPs really deserve a lot more
  3665.   attention from the Linux parallel processing community....
  3666.  
  3667.   5.3.  FPGAs And Reconfigurable Logic Computing
  3668.  
  3669.   If parallel processing is all about getting the highest speedup, then
  3670.   why not build custom hardware?  Well, we all know the answers; it
  3671.   costs too much, takes too long to develop, becomes useless when we
  3672.   change the algorithm even slightly, etc.  However, recent advances in
  3673.   electrically reprogrammable FPGAs (Field Programmable Gate Arrays)
  3674.   have nullified most of those objections.  Now, the gate density is
  3675.   high enough so that an entire simple processor can be built within a
  3676.   single FPGA, and the time to reconfigure (reprogram) an FPGA has also
  3677.   been dropping to a level where it is reasonable to reconfigure even
  3678.   when moving from one phase of an algorithm to the next.
  3679.  
  3680.   This stuff is not for the weak of heart:  you'll have to work with
  3681.   hardware description languages like VHDL for the FPGA configuration,
  3682.   as well as writing low-level code to interface to programs on the
  3683.   Linux host system.  However, the cost of FPGAs is low, and especially
  3684.   for algorithms operating on low-precision integer data (actually, a
  3685.   small superset of the stuff SWAR is good at), FPGAs can perform
  3686.   complex operations just about as fast as you can feed them data.  For
  3687.   example, simple FPGA-based systems have yielded better-than-
  3688.   supercomputer times for searching gene databases.
  3689.  
  3690.   There are other companies making appropriate FPGA-based hardware, but
  3691.   the following two companies represent a good sample.
  3692.  
  3693.   Virtual Computer Company offers a variety of products using
  3694.   dynamically reconfigurable SRAM-based Xilinx FPGAs.  Their 8/16 bit
  3695.   "Virtual ISA Proto Board"  <http://www.vcc.com/products/isa.html> is
  3696.   less than $2,000.
  3697.  
  3698.   The Altera ARC-PCI (Altera Reconfigurable Computer, PCI bus),
  3699.   <http://www.altera.com/html/new/pressrel/pr_arc-pci.html>, is a
  3700.   similar type of card, but uses Altera FPGAs and a PCI bus interface
  3701.   rather than ISA.
  3702.  
  3703.   Many of the design tools, hardware description languages, compilers,
  3704.   routers, mappers, etc., come as object code only that runs under
  3705.   Windows and/or DOS.  You could simply keep a disk partition with
  3706.   DOS/Windows on your host PC and reboot whenever you need to use them,
  3707.   however, many of these software packages may work under Linux using
  3708.   dosemu or Windows emulators like wine.
  3709.  
  3710.   6.  Of General Interest
  3711.  
  3712.   The material covered in this section applies to all four parallel
  3713.   processing models for Linux.
  3714.  
  3715.   6.1.  Programming Languages And Compilers
  3716.  
  3717.   I am primarily known as a compiler researcher, so I'd like to be able
  3718.   to say that there are lots of really great compilers automatically
  3719.   generating efficient parallel code for Linux systems.  Unfortunately,
  3720.   the truth is that it is hard to beat the performance obtained by
  3721.   expressing your parallel program using various explicit communication
  3722.   and other parallel operations within C code that is compiled by GCC.
  3723.  
  3724.   The following language/compiler projects represent some of the best
  3725.   efforts toward producing reasonably efficient code from high-level
  3726.   languages.  Generally, each is reasonably effective for the kinds of
  3727.   programming tasks it targets, but none is the powerful general-purpose
  3728.   language and compiler system that will make you forever stop writing C
  3729.   programs to compile with GCC...  which is fine.  Use these languages
  3730.   and compilers as they were intended, and you'll be rewarded with
  3731.   shorter development times, easier debugging and maintenance, etc.
  3732.  
  3733.   There are plenty of languages and compilers beyond those listed here
  3734.   (in alphabetical order).  A list of freely available compilers (most
  3735.   of which have nothing to do with Linux parallel processing) is at
  3736.   <http://www.idiom.com/free-compilers/>.
  3737.  
  3738.   6.1.1.  Fortran 66/77/PCF/90/HPF/95
  3739.  
  3740.   At least in the scientific computing community, there will always be
  3741.   Fortran.  Of course, now Fortran doesn't mean the same thing it did in
  3742.   the 1966 ANSI standard.  Basically, Fortran 66 was pretty simple
  3743.   stuff.  Fortran 77 added tons of features, the most noticeable of
  3744.   which were the improved support for character data and the change of
  3745.   DO loop semantics.  PCF (Parallel Computing Forum) Fortran attempted
  3746.   to add a variety of parallel processing support features to 77.
  3747.   Fortran 90 is a fully-featured modern language, essentially adding
  3748.   C++-like object-oriented programming features and parallel array
  3749.   syntax to the 77 language.  HPF (High-Performance Fortran,
  3750.   <http://www.crpc.rice.edu/HPFF/home.html>), which has itself gone
  3751.   through two versions (HPF-1 and HPF-2), is essentially the enhanced,
  3752.   standardized, version of what many of us used to know as CM Fortran,
  3753.   MasPar Fortran, or Fortran D; it extends Fortran 90 with a variety of
  3754.   parallel processing enhancements, largely focussed on specifying data
  3755.   layouts.  Finally, Fortran 95 represents a relatively minor
  3756.   enhancement and refinement of 90.
  3757.  
  3758.   What works with C generally can also work with f2c, g77 (a nice Linux-
  3759.   specific overview is at  <http://linux.uni-
  3760.   regensburg.de/psi_linux/gcc/html_g77/g77_91.html>), or the commercial
  3761.   Fortran 90/95 products from
  3762.   <http://extweb.nag.co.uk/nagware/NCNJNKNM.html>.  This is because all
  3763.   of these compilers eventually come down to the same code-generation
  3764.   used in the back-end of GCC.
  3765.  
  3766.   Commercial Fortran parallelizers that can generate code for SMPs are
  3767.   available from  <http://www.kai.com/> and
  3768.   <http://www.psrv.com/vast/vast_parallel.html>.  It is not clear if
  3769.   these compilers will work for SMP Linux, but it should be possible
  3770.   given that the standard POSIX threads (i.e., LinuxThreads) work under
  3771.   SMP Linux.
  3772.  
  3773.   The Portland Group,  <http://www.pgroup.com/>, has commercial
  3774.   parallelizing HPF Fortran (and C, C++) compilers that generate code
  3775.   for SMP Linux; they also have a version targeting clusters using MPI
  3776.   or PVM.  FORGE/spf/xHPF products at  < http://www.apri.com/> might
  3777.   also be useful for SMPs or clusters.
  3778.  
  3779.   Freely available parallelizing Fortrans that might be made to work
  3780.   with parallel Linux systems include:
  3781.  
  3782.   ╖  ADAPTOR (Automatic DAta Parallelism TranslaTOR,
  3783.      <http://www.gmd.de/SCAI/lab/adaptor/adaptor_home.html>), which can
  3784.      translate HPF into Fortran 77/90 code with MPI or PVM calls, but
  3785.      does not mention Linux.
  3786.  
  3787.   ╖  Fx  <http://www.cs.cmu.edu/~fx/Fx> at Carnegie Mellon targets some
  3788.      workstation clusters, but Linux?
  3789.  
  3790.   ╖  HPFC (prototype HPF Compiler,
  3791.      <http://www.cri.ensmp.fr/~coelho/hpfc.html>) generates Fortran 77
  3792.      code with PVM calls.  Is it usable on a Linux cluster?
  3793.  
  3794.   ╖  Can PARADIGM (PARAllelizing compiler for DIstributed-memory
  3795.      General-purpose Multicomputers,
  3796.      <http://www.crhc.uiuc.edu/Paradigm/>) be used with Linux?
  3797.  
  3798.   ╖  The Polaris compiler,
  3799.      <http://ece.www.ecn.purdue.edu/~eigenman/polaris/>, generates
  3800.      Fortran code for shared memory multiprocessors, and may soon be
  3801.      retargeted to PAPERS Linux clusters.
  3802.  
  3803.   ╖  PREPARE,
  3804.      <http://www.irisa.fr/EXTERNE/projet/pampa/PREPARE/prepare.html>,
  3805.      targets MPI clusters...  it is not clear if it can generate code to
  3806.      run on IA32 processors.
  3807.  
  3808.   ╖  Combining ADAPT and ADLIB, shpf (Subset High Performance Fortran
  3809.      compilation system,
  3810.      <http://www.ccg.ecs.soton.ac.uk/Projects/shpf/shpf.html>) is public
  3811.      domain and generates Fortran 90 with MPI calls...  so, if you have
  3812.      a Fortran 90 compiler under Linux....
  3813.  
  3814.   ╖  SUIF (Stanford University Intermediate Form, see
  3815.      <http://suif.stanford.edu/>) has parallelizing compilers for both C
  3816.      and Fortran.  This is also the focus of the National Compiler
  3817.      Infrastructure Project...  so, is anybody targeting parallel Linux
  3818.      systems?
  3819.  
  3820.   I'm sure that I have omitted many potentially useful compilers for
  3821.   various dialects of Fortran, but there are so many that it is
  3822.   difficult to keep track.  In the future, I would prefer to list only
  3823.   those compilers known to work with Linux.  Please email comments
  3824.   and/or corrections to pplinux@ecn.purdue.edu.
  3825.  
  3826.   6.1.2.  GLU (Granular Lucid)
  3827.  
  3828.   GLU (Granular Lucid) is a very high-level programming system based on
  3829.   a hybrid programming model that combines intensional (Lucid) and
  3830.   imperative models.  It supports both PVM and TCP sockets.  Does it run
  3831.   under Linux?  More information is available at
  3832.   <http://www.csl.sri.com/GLU.html>.
  3833.  
  3834.   6.1.3.  Jade And SAM
  3835.  
  3836.   Jade is a parallel programming language that extends C to exploit
  3837.   coarse-grain concurrency in sequential, imperative programs.  It
  3838.   assumes a distributed shared memory model, which is implemented by SAM
  3839.   for workstation clusters using PVM.  More information is available at
  3840.   <http://suif.stanford.edu/~scales/sam.html>.
  3841.  
  3842.   6.1.4.  Mentat And Legion
  3843.  
  3844.   Mentat is an object-oriented parallel processing system that works
  3845.   with workstation clusters and has been ported to Linux.  Mentat
  3846.   Programming Language (MPL) is an object-oriented programming language
  3847.   based on C++.  The Mentat run-time system uses something vaguely
  3848.   resembling non-blocking remote procedure calls.  More information is
  3849.   available at  <http://www.cs.virginia.edu/~mentat/>.
  3850.  
  3851.   Legion  <http://www.cs.virginia.edu/~legion/> is built on top on
  3852.   Mentat, providing the appearance of a single virtual machine across
  3853.   wide-area networked machines.
  3854.  
  3855.   6.1.5.  MPL (MasPar Programming Language)
  3856.  
  3857.   Not to be confussed with Mentat's MPL, this language was originally
  3858.   developed as the native parallel C dialect for the MasPar SIMD
  3859.   supercomputers.  Well, MasPar isn't really in that business any more
  3860.   (they are now NeoVista Solutions,  <http://www.neovista.com>, a data
  3861.   mining company), but their MPL compiler was built using GCC, so it is
  3862.   still freely available.  In a joint effort between the University of
  3863.   Alabama at Huntsville and Purdue University, MasPar's MPL has been
  3864.   retargeted to generate C code with AFAPI calls (see section 3.6), and
  3865.   thus runs on both Linux SMPs and clusters.  The compiler is, however,
  3866.   somewhat buggy...  see
  3867.   <http://www.math.luc.edu/~laufer/mspls/papers/cohen.ps>.
  3868.  
  3869.   6.1.6.  PAMS (Parallel Application Management System)
  3870.  
  3871.   Myrias is a company selling a software product called PAMS (Parallel
  3872.   Application Management System).  PAMS provides very simple directives
  3873.   for virtual shared memory parallel processing.  Networks of Linux
  3874.   machines are not yet supported.  See  <http://www.myrias.com/> for
  3875.   more information.
  3876.  
  3877.   6.1.7.  Parallaxis-III
  3878.  
  3879.   Parallaxis-III is a structured programming language that extends
  3880.   Modula-2 with "virtual processors and connections" for data
  3881.   parallelism (a SIMD model).  The Parallaxis software comprises
  3882.   compilers for sequential and parallel computer systems, a debugger
  3883.   (extensions to the gdb and xgbd debugger), and a large variety of
  3884.   sample algorithms from different areas, especially image processing.
  3885.   This runs on sequential Linux systems...  an old version supported
  3886.   various parallel targets, and the new version also will (e.g.,
  3887.   targeting a PVM cluster).  More information is available at
  3888.   <http://www.informatik.uni-stuttgart.de/ipvr/bv/p3/p3.html>.
  3889.  
  3890.   6.1.8.  pC++/Sage++
  3891.  
  3892.   pC++/Sage++ is a language extension to C++ that permits data-parallel
  3893.   style operations using "collections of objects" from some base
  3894.   "element" class.  It is a preprocessor generating C++ code that can
  3895.   run under PVM.  Does it run under Linux?  More information is
  3896.   available at  <http://www.extreme.indiana.edu/sage/>.
  3897.  
  3898.   6.1.9.  SR (Synchronizing Resources)
  3899.  
  3900.   SR (Synchronizing Resources) is a concurrent programming language in
  3901.   which resources encapsulate processes and the variables they share;
  3902.   operations provide the primary mechanism for process interaction. SR
  3903.   provides a novel integration of the mechanisms for invoking and
  3904.   servicing operations. Consequently, all of local and remote procedure
  3905.   call, rendezvous, message passing, dynamic process creation,
  3906.   multicast, and semaphores are supported. SR also supports shared
  3907.   global variables and operations.
  3908.  
  3909.   It has been ported to Linux, but it isn't clear what parallelism it
  3910.   can execute with.  More information is available at
  3911.   <http://www.cs.arizona.edu/sr/www/index.html>.
  3912.  
  3913.   6.1.10.  ZPL And IronMan
  3914.  
  3915.   ZPL is an array-based programming language intended to support
  3916.   engineering and scientific applications.  It generates calls to a
  3917.   simple message-passing interface called IronMan, and the few functions
  3918.   which constitute this interface can be easily implemented using nearly
  3919.   any message-passing system.  However, it is primarily targeted to PVM
  3920.   and MPI on workstation clusters, and Linux is supported.  More
  3921.   information is available at
  3922.   <http://www.cs.washington.edu/research/projects/orca3/zpl/www/>.
  3923.  
  3924.   6.2.  Performance Issues
  3925.  
  3926.   There are a lot of people who spend a lot of time benchmarking
  3927.   particular motherboards, network cards, etc., trying to determine
  3928.   which is the best.  The problem with that approach is that by the time
  3929.   you've been able to benchmark something, it is no longer the best
  3930.   available; it even may have been taken off the market and replaced by
  3931.   a revised model with entirely different properties.
  3932.  
  3933.   Buying PC hardware is like buying orange juice.  Usually, it is made
  3934.   with pretty good stuff no matter what company name is on the label.
  3935.   Few people know, or care, where the components (or orange juice
  3936.   concentrate) came from.  That said, there are some hardware
  3937.   differences that you should pay attention to.  My advice is simply
  3938.   that you be aware of what you can expect from the hardware under
  3939.   Linux, and then focus your attention on getting rapid delivery, a good
  3940.   price, and a reasonable policy for returns.
  3941.  
  3942.   An excellent overview of the different PC processors is given in
  3943.   <http://www.pcguide.com/ref/cpu/fam/>; in fact, the whole WWW site
  3944.   <http://www.pcguide.com/> is full of good technical overviews of PC
  3945.   hardware.  It is also useful to know a bit about performance of
  3946.   specific hardware configurations, and the Linux Benchmarking HOWTO
  3947.   <http://sunsite.unc.edu/LDP/HOWTO/Benchmarking-HOWTO.html> is a good
  3948.   place to start.
  3949.  
  3950.   The Intel IA32 processors have many special registers that can be used
  3951.   to measure the performance of a running system in exquisite detail.
  3952.   Intel VTune,  <http://developer.intel.com/design/perftool/vtune/>,
  3953.   uses the performance registers extensively in a very complete code-
  3954.   tuning system...  that unfortunately doesn't run under Linux.  A
  3955.   loadable module device driver, and library routines, for accessing the
  3956.   Pentium performance registers is available from
  3957.   <http://www.cs.umd.edu/users/akinlar/driver.html>.  Keep in mind that
  3958.   these performance registers are different on different IA32
  3959.   processors; this code works only with Pentium, not with 486, Pentium
  3960.   Pro, Pentium II, K6, etc.
  3961.  
  3962.   Another comment on performance is appropriate, especially for those of
  3963.   you who want to build big clusters and put them in small spaces.  At
  3964.   least some modern processors incorporate thermal sensors and circuits
  3965.   that are used to slow the internal clock rate if operating temperature
  3966.   gets too high (an attempt to reduce heat output and improve
  3967.   reliability).  I'm not suggesting that everyone should go buy a
  3968.   peltier device (heat pump) to cool each CPU, but you should be aware
  3969.   that high operating temperature does not just shorten component life -
  3970.   it also can directly reduce system performance.  Do not arrange your
  3971.   computers in physical configurations that block airflow, trap heat
  3972.   within confined areas, etc.
  3973.  
  3974.   Finally, performance isn't just speed, but also reliability and
  3975.   availability.  High reliability means that your system almost never
  3976.   crashes, even when components fail...  which generally requires
  3977.   special features like redundant power supplies and hot-swap
  3978.   motherboards.  That usually isn't cheap.  High availability refers to
  3979.   the concept that your system is available for use nearly all the
  3980.   time...  the system may crash when components fail, but the system is
  3981.   quickly repaired and rebooted.  There is a High-Availability HOWTO
  3982.   that discusses many of the basic issues.  However, especially for
  3983.   clusters, high availablity can be achieved simply by having a few
  3984.   spares.  I recommend at least one spare, and prefer to have at least
  3985.   one spare for every 16 machines in a large cluster.  Discarding faulty
  3986.   hardware and replacing it with a spare can yield both higher
  3987.   availability and lower cost than a maintenance contract.
  3988.  
  3989.   6.3.  Conclusion - It's Out There
  3990.  
  3991.   So, is anybody doing parallel processing using Linux?  Yes!
  3992.  
  3993.   It wasn't very long ago that a lot of people were wondering if the
  3994.   death of many parallel-processing supercomputer companies meant that
  3995.   parallel processing was on its way out.  I didn't think it was dead
  3996.   then (see  <http://dynamo.ecn.purdue.edu/~hankd/Opinions/pardead.html>
  3997.   for a fun overview of what I think really happened), and it seems
  3998.   quite clear now that parallel processing is again on the rise.  Even
  3999.   Intel, which just recently stopped making parallel supercomputers, is
  4000.   proud of the parallel processing support in things like MMX and the
  4001.   upcoming IA64 EPIC (Explicitly Parallel Instruction Computer).
  4002.  
  4003.   If you search for "Linux" and "parallel" with your favorite search
  4004.   engine, you'll find quite a few places are involved in parallel
  4005.   processing using Linux.  In particular, Linux PC clusters seem to be
  4006.   popping-up everywhere.  The appropriateness of Linux, combined with
  4007.   the low cost and high performance of PC hardware, have made parallel
  4008.   processing using Linux a popular approach to supercomputing for both
  4009.   small, budget-constrained, groups and large, well-funded, national
  4010.   research laboratories.
  4011.  
  4012.   Various projects listed elsewhere in this document maintain lists of
  4013.   "kindred" research sites that have similar parallel Linux
  4014.   configurations.  However, at
  4015.   <http://yara.ecn.purdue.edu/~pplinux/Sites/>, there is a hypertext
  4016.   document intended to provide photographs, descriptions, and contact
  4017.   information for all the various sites using Linux systems for parallel
  4018.   processing.  To have information about your site posted there:
  4019.  
  4020.   ╖  You must have a "permanent" parallel Linux site:  an SMP, cluster
  4021.      of machines, SWAR system, or PC with attached processor, which is
  4022.      configured to allow users to execute parallel programs under Linux.
  4023.      A Linux-based software environment (e.g., PVM, MPI, AFAPI) that
  4024.      directly supports parallel processing must be installed on the
  4025.      system.  However, the hardware need not be dedicated to parallel
  4026.      processing under Linux, and may be used for completely different
  4027.      purposes when parallel programs are not being run.
  4028.  
  4029.   ╖  Request that your site be listed.  Send your site information to
  4030.      pplinux@ecn.purdue.edu.  Please follow the format used in other
  4031.      entries for your site information.  No site will be listed without
  4032.      an explicit request from the contact person for that site.
  4033.  
  4034.   There are 14 clusters in the current listing, but we are aware of at
  4035.   least several dozen Linux clusters world-wide.  Of course, listing
  4036.   does not imply any endorsement, etc.; our hope is simply to increase
  4037.   awareness, research, and collaboration involving parallel processing
  4038.   using Linux.
  4039.  
  4040.