home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / papers / Muuss.parallel.Z / Muuss.parallel
Text File  |  1991-02-06  |  44KB  |  1,046 lines

  1. .\" indxbib bib
  2. .\" refer -e -p bib a | pic | tbl out1 | /usr/5bin/eqn -Ti300 | \
  3. .\" /usr/5lib/troff -Ti300 -ms - | dimp -t | qpr -q im217-raw
  4. .\"
  5. .so /usr/lib/tmac/tmac.srefs
  6. .EQ
  7. delim $$
  8. .EN
  9. .\"gsize 24
  10. .RP
  11. .TL
  12. Excerpts from
  13. .br
  14. ``Workstations, Networking,
  15. .br
  16. Distributed Graphics,
  17. .br
  18. and
  19. .br
  20. Parallel Processing''
  21. .AU
  22. Michael John Muuss
  23. .AI
  24. Leader, Advanced Computer Systems Team
  25. Ballistic Research Laboratory
  26. Aberdeen Proving Ground
  27. Maryland 21005-5066 USA
  28. .AB
  29. .LP
  30. The process of design is iterative in nature;
  31. designs are formulated, analyzed, and improved, until the goals are met.
  32. Modern graphics workstations provide a powerful platform for
  33. performing detailed design and limited analysis of solid model designs,
  34. with faster computers accessed via network links for full resolution analysis.
  35. A broad spectrum of analysis tools exist, and most express their
  36. output in graphical form.
  37. Their three main styles of graphics display will be examined, along
  38. with a look at the underlying software mechanisms to support them.
  39. .LP
  40. Several enabling technologies
  41. are required for analysis tools to run on one computer,
  42. with graphical display on another computer, including the
  43. network transparent framebuffer capability.
  44. The importance of portable external data representations will be
  45. reviewed, and several specific
  46. external data representations will be examined in significant detail.
  47. By carefully dividing application software into appropriate tools
  48. and connecting them with UNIX pipes, a measure of parallel processing
  49. can be achieved within one system.
  50. In a tool oriented environment
  51. with machine independent data formats,
  52. network distributed computation can be accomplished.
  53. .LP
  54. The next step is to 
  55. make a single tool execute faster using parallel processing.
  56. Many analysis codes are implemented using the ray-tracing paradigm
  57. which is ideal for execution in parallel on
  58. tightly coupled shared-memory multiprocessors and loosely
  59. coupled ensembles of computers.
  60. Both are exploited, using different
  61. mechanisms.
  62. The strategies used for operating
  63. on shared-memory multiprocessors such as the Denelcor HEP, Alliant FX/8, and
  64. Cray X-MP will be presented, along with measured performance data.
  65. .LP
  66. The strategies used for dividing the work among network connected
  67. loosely coupled processors (each of which may themselves be a parallel
  68. processor)
  69. are presented, including details
  70. of the dispatching algorithm, and the design of the distribution protocol.
  71. The performance issues of this type of parallel processing will be presented,
  72. including a
  73. set of measured speeds on a variety of hardware.
  74. .AE
  75. .RT
  76. .\" Make troff use nroff style bracketed references
  77. .ds [. " [
  78. .ds .] ]
  79. .NH 1
  80. (Early Chapers Omitted)
  81. .NH 1
  82. SHARED-MEMORY PARALLEL PROCESSING
  83. .PP
  84. In the preceding section, we have seen how
  85. different processors
  86. can be harnessed to achieve a single goal.
  87. The discussion so far has focused on using multiple processors
  88. (a) within a single, multi-CPU system, through the use of UNIX pipes,
  89. and (b) by distributing different tools in a pipeline to different
  90. machines on the network.
  91. This section extends the investigation into parallel processing
  92. one level further, to harness the power of multiple processor
  93. machines to make a single application run faster.
  94. For the purposes of this discussion, the application to be
  95. parallelized will be a ray-tracing program, but the techniques
  96. developed here are quite general.
  97. .NH 2
  98. The Need for Speed
  99. .PP
  100. Images created using ray-tracing have a reputation for consuming large
  101. quantities of computer time.  For complex models,
  102. 10 to 20 hours of processor time to render a single frame
  103. on a DEC VAX-11/780 class machine is not uncommon.
  104. Using the ray-tracing paradigm for engineering analysis
  105. .[
  106. Muuss Understanding Solid Models
  107. .]
  108. often requires many times more processing than rendering
  109. a view of the model.  Examples of such engineering analyses
  110. include the predictive calculation of radar cross-sections,
  111. heat flow, and bi-static laser reflectivity.  For models of
  112. real-world geometry, running these analyses approaches
  113. the limits of practical execution times, even with modern SuperComputers.
  114. There are three main strategies that are being employed to
  115. attempt to decrease the amount of elapsed time it takes to
  116. ray-trace a particular scene:
  117. .IP 1)
  118. Advances in algorithms for ray-tracing.
  119. Newer techniques in partitioning space
  120. .[
  121. Kaplan Space-Tracing
  122. .]
  123. and in taking advantage of ray-to-ray coherence
  124. .[
  125. Arvo Ray Classification
  126. .]
  127. promise to continue to yield algorithms that do fewer and fewer
  128. ray/object intersections which do not contribute to the final results.
  129. Significant work remains to be done in this area, and an order of
  130. magnitude performance gain remains to be realized.  However, there
  131. is a limit to the gains that can be made in this area.
  132. .IP 2)
  133. Acquiring faster processors. A trivial method for decreasing the elapsed
  134. time to run a program is to purchase a faster computer.  However, even
  135. the fastest general-purpose computers such as the Cray X-MP and Cray-2
  136. do not execute fast enough to permit practical analysis of all
  137. real-world models in appropriate detail. Furthermore, the speed of light
  138. provides an upper bound on the fastest computer that can be built out of
  139. modern integrated circuits; this is already a significant
  140. factor in the Cray X-MP and Cray-2 processors, which operate with 8.5 ns
  141. and 4.3 ns clock periods respectively.
  142. .IP 3)
  143. Using multiple processors to solve a single problem. By engaging the
  144. resources of multiple processors to work on a single problem, the
  145. speed-of-light limit can be circumvented.  However, the price is that
  146. explicit attention must be paid to the distribution of data to the
  147. various processors, synchronization of the computations, and collection
  148. of the results.
  149. .PP
  150. Parallel processing is still a relatively young art, and presently there
  151. is only limited support available for
  152. the automatic parallelization of existing
  153. code, with newer vendors like Alliant leading the crowd.
  154. For now, there are few general techniques
  155. for taking programs intended
  156. for serial operation on a single processor, and automatically adapting
  157. them for operation on multiple processors.
  158. .[
  159. Ohr Minisupercomputers Speed
  160. .]
  161. The \fBWorm\fR program developed at Xerox PARC
  162. .[
  163. Shoch Worm Distributed Computation
  164. .]
  165. is one of the earliest known network image-rendering applications.
  166. More recently at Xerox PARC, Frank Crow has attempted to distribute
  167. the rendering of a single image across multiple processors,
  168. .[
  169. Crow Distributed Execution Work in Progress
  170. .]
  171. but discovered that communication overhead and synchronization problems
  172. limited parallelism to about 30% of the available processing power.
  173. A good summary of work to date has been collected by Peterson.
  174. .[
  175. Peterson Distributed Computation
  176. .]
  177. .PP
  178. Ray-tracing analysis of a model has the very nice property that
  179. the computations for each ray/model intersection are entirely
  180. independent of other ray/model intersection calculations.
  181. Therefore, it is easy to see how the calculations for each ray
  182. can be performed by separate, independent processors.  The
  183. underlying assumption is that each processor has read-only access
  184. to the entire model database.
  185. While it would be possible to partition the ray-tracing algorithm
  186. in such a way as to require only a portion of the model database
  187. being resident in each processor, this would significantly increase
  188. the complexity of the implementation as well as the
  189. amount of synchronization and control traffic needed.
  190. Such a partitioning has therefore
  191. not yet been seriously attempted.
  192. .PP
  193. It is the purpose of the research reported in the rest of this paper to
  194. explore the performance limits of parallel operation of ray-tracing
  195. algorithms where available processor memory is not a limitation.
  196. While it is not expected that this research will result
  197. in a general purpose technique for distributing arbitrary programs
  198. across multiple processors, the issues of the control and distribution of work
  199. and providing reliable results in a potentially unreliable system
  200. are quite general.  The techniques used here are likely to be
  201. applicable to a large set of other applications.
  202. .NH 2
  203. Raytracing Background
  204. .PP
  205. The origins of modern ray-tracing come from work at MAGI
  206. under contract to BRL, initiated in the early 1960s.
  207. The initial results were reported by MAGI
  208. .[
  209. geometric description technique MAGI
  210. .]
  211. in 1967.
  212. Extensions to the early developments were undertaken by a
  213. DoD Joint Technical Coordinating Group effort, resulting in
  214. publications in 1970
  215. .[
  216. MAGIC User Manual
  217. .]
  218. and 1971.
  219. .[
  220. MAGIC Analyst Manual
  221. .]
  222. A detailed presentation of the
  223. fundamental analysis and implementation of the ray-tracing algorithm
  224. can be found in these two documents.
  225. Also see
  226. .[
  227. Appel shading machine renderings solids
  228. .]
  229. .PP
  230. More recently, interest in ray-tracing developed in the academic
  231. community, with Kay's
  232. .[
  233. Kay Ray Tracing 1979
  234. .]
  235. thesis in 1979
  236. being a notable early work.
  237. One of the central papers in the ray-tracing literature is
  238. the work of Whitted.
  239. .[
  240. Whitted Improved Illumination Model
  241. .]
  242. Model sampling techniques can be improved to provide substantially
  243. more realistic images by using the ``Distributed Ray Tracing'' strategy.
  244. .[
  245. Cook Carpenter Distributed Ray Tracing
  246. .]
  247. For an excellent, concise discussion of ray-tracing,
  248. consult pages 363-381 of Rogers.
  249. .[
  250. Rogers Procedural Elements
  251. .]
  252. .PP
  253. There are several implementation strategies for interrogating
  254. the model by computing ray/geometry intersections.
  255. The traditional approach has been batch-oriented,
  256. with the user defining a set of ``viewing angles'',
  257. turning loose a big batch job to compute all the ray intersections,
  258. and then post-processing all the ray data into some meaningful form.
  259. However, the major drawback of this approach is that the application
  260. has no dynamic control over ray paths, making another batch run
  261. necessary for each level of reflection, etc.
  262. .PP
  263. In order to be successful, applications need: (1) dynamic control of ray
  264. paths, to naturally implement reflection, refraction, and fragmentation into
  265. multiple subsidiary rays, and (2) the ability to fire rays in arbitrary
  266. directions from arbitrary points.
  267. Nearly all non-batch ray-tracing implementations have a specific closely
  268. coupled application (typically a model of illumination), which
  269. allows efficient and effective control of the ray paths.
  270. However, the most flexible approach is to implement the ray-tracing
  271. capability as a general-purpose library, to make the functionality
  272. available to any application as needed, and
  273. this is the approach taken in the BRL CAD Package.
  274. .[
  275. Muuss CAD Package Release 1.21
  276. .]
  277. The ray-tracing library is called \fBlibrt\fR, while the ray-tracing
  278. application of interest here (an optical spectrum lighting model)
  279. is called \fBrt\fR.
  280. .NH 2
  281. The Structure of librt
  282. .PP
  283. In order to give all applications dynamic control over
  284. the ray paths, and to allow the rays to be fired in arbitrary directions
  285. from arbitrary points, BRL has implemented its third generation
  286. ray-tracing capability as a set of library routines.
  287. \fBlibrt\fR exists to allow application programs to
  288. intersect rays with model geometry.  There are four parts to the
  289. interface: three preparation routines and the actual ray-tracing routine.
  290. The first routine which must be called is
  291. rt_dirbuild(), which opens the database file, and builds the
  292. in-core database table of contents.
  293. The second routine to be called is rt_gettree(), which
  294. adds a database sub-tree to the active model space.
  295. rt_gettree() can be called multiple times
  296. to load different parts of the database
  297. into the active model space.
  298. The third routine is rt_prep(), which
  299. computes the space partitioning data structures and does other
  300. initialization chores.
  301. Calling this routine is optional,
  302. as it will be called by rt_shootray() if needed.
  303. rt_prep() is provided as a separate routine to
  304. allow independent timing of the preparation and ray-tracing phases of
  305. applications.
  306. .PP
  307. To compute the intersection of a ray with the geometry in the active
  308. model space, the application must call rt_shootray() once for each
  309. ray. Ray-path selection for perspective, reflection, refraction, etc,
  310. is entirely determined by the application program. The only parameter
  311. to the rt_shootray() is a \fBlibrt\fR ``application'' structure, which
  312. contains five major elements: the vector a_ray.r_pt which
  313. is the starting point of the ray to be fired, the vector a_ray.r_dir
  314. which is the unit-length direction vector of the ray,
  315. the pointer *a_hit() which is the address of an application-provided
  316. routine to call when the ray intersects the model geometry, the pointer
  317. *a_miss() which is the address of an application-provided routine to
  318. call when the ray does not hit any geometry, the flag a_onehit which is
  319. set non-zero to stop ray-tracing as soon as the ray has intersected at
  320. least one piece of geometry (useful for lighting models), plus various
  321. locations for each application to store state (recursion level, colors,
  322. etc). Note that the integer returned from the application-provided
  323. a_hit()/a_miss() routine is the formal return of the function
  324. rt_shootray(). The rt_shootray() function is prepared for full recursion
  325. so that the a_hit()/a_miss() routines can themselves fire additional
  326. rays by calling rt_shootray() recursively before deciding their own
  327. return value.
  328. .PP
  329. In addition, the function rt_shootray() is serially and concurrently
  330. reentrant, using only registers, local variables allocated on the stack, and
  331. dynamic memory allocated with rt_malloc().
  332. The rt_malloc() function serializes calls to \fBmalloc\fR(3).
  333. By having the ray-tracing library fully prepared to run
  334. in parallel with other instances of itself in the same address space,
  335. applications may take full advantage of parallel hardware capabilities,
  336. where such capabilities exist.
  337. .NH 2
  338. A Sample Ray-Tracing Program
  339. .PP
  340. A simple application program that fires one ray at a model and prints
  341. the result is included below, to demonstrate the simplicity of the
  342. interface to \fBlibrt\fR.
  343. .LP
  344. .sp .5
  345. .nf
  346. .ne 2i
  347. #include <brlcad/raytrace.h>
  348. struct application ap;
  349. main() {
  350.       rt_dirbuild("model.g");
  351.       rt_gettree("car");
  352.       rt_prep();
  353.       ap.a_point = [ 100, 0, 0 ];
  354.       ap.a_dir = [ -1, 0, 0 ];
  355.       ap.a_hit = &hit_geom;
  356.       ap.a_miss = &miss_geom;
  357.       ap.a_onehit = 1;
  358.       rt_shootray( &ap );
  359. }
  360. hit_geom(app, part)
  361. struct application *app;
  362. struct partition *part;
  363. {
  364.       printf("Hit %s", part->pt_forw->pt_regionp->reg_name);
  365. }
  366. miss_geom(){
  367.       printf("Missed");
  368. }
  369. .fi
  370. .NH 2
  371. Normal Operation:  Serial Execution
  372. .PP
  373. When running the \fBrt\fR program on a serial processor, 
  374. the code of interest is the top of the subroutine hierarchy.
  375. The function
  376. main()
  377. first calls
  378. get_args()
  379. to parse any command line options, then calls
  380. rt_dirbuild()
  381. to acquaint \fBlibrt\fR with the model database, and
  382. view_init()
  383. to initialize the application
  384. (in this case a lighting model, which may call
  385. mlib_init()
  386. to initialize the material-property library).  Finally,
  387. rt_gettree()
  388. is called repeatedly to load the model treetops.
  389. For each frame to be produced,
  390. the viewing parameters are processed, and
  391. do_frame()
  392. is called.
  393. .PP
  394. Within
  395. do_frame(),
  396. per-frame initialization is handled by calling
  397. rt_prep(),
  398. mlib_setup(),
  399. grid_setup(),
  400. and
  401. view_2init().
  402. Then,
  403. do_run()
  404. is called with the linear pixel indices of the start and end locations in
  405. the image;  typically these values are zero and width*length-1,
  406. except for the ensemble computer case.
  407. In the non-parallel cases,
  408. the do_run()
  409. routine initializes the global variables
  410. cur_pixel and last_pixel, and calls
  411. worker().
  412. At the end of the frame,
  413. view_end()
  414. is called to handle any final output, and print some statistics.
  415. .PP
  416. The worker() routine
  417. obtains the index of the next pixel that needs to be computed by
  418. incrementing cur_pixel, and calls
  419. rt_shootray()
  420. to interrogate the model geometry.
  421. view_pixel()
  422. is called to output the results for that pixel.
  423. worker()
  424. loops, computing one pixel at a time, until
  425. \fIcur_pixel > last_pixel\fR,
  426. after which it returns.
  427. .PP
  428. When
  429. rt_shootray()
  430. hits some geometry, it calls the a_hit() routine listed in the application
  431. structure to determine the final color of the pixel.
  432. In this case, colorview() is called.  colorview() uses view_shade()
  433. to do the actual computation.
  434. Depending on the properties of the material hit and the stack of shaders
  435. that are being used, various material-specific renderers may be called,
  436. followed by a call to
  437. rr_render()
  438. if reflection or refraction is needed.  Any of these routines may spawn
  439. multiple rays, and/or recurse on
  440. colorview().
  441. .NH 2
  442. Parallel Operation on Shared-Memory Machines
  443. .PP
  444. By capitalizing on the serial and concurrent
  445. reentrancy of the \fBlibrt\fR routines, it is very easy to take advantage
  446. of shared memory machines where it is possible to initiate multiple
  447. ``streams of execution'' or ``threads''
  448. within the address space of a single process.
  449. In order to be able to ensure that global variables are only
  450. manipulated by one instruction stream at a time,
  451. all such shared modifications are enclosed in critical sections.
  452. For each type of processor, it is necessary to implement the routines
  453. RES_ACQUIRE()
  454. and
  455. RES_RELEASE()
  456. to provide system-wide semaphore operations.
  457. When a processor acquires a resource, and any other processors need that
  458. same resource, they will wait until it is released, at which time exactly
  459. one of the waiting processors will then acquire the resource.
  460. .PP
  461. In order to minimize contention between processors
  462. over the critical sections of code, all critical sections are kept
  463. as short as possible: typically only a few lines of code.
  464. Furthermore, there are different semaphores for each type of resource
  465. accessed in critical sections.
  466. .I res_syscall
  467. is used to interlock all UNIX
  468. system calls and some library routines,
  469. such as
  470. \fBwrite\fR(2),
  471. \fBmalloc\fR(3),
  472. \fBprintf\fR(3),
  473. etc.
  474. .I res_worker
  475. is used by the function
  476. worker()
  477. to serialize access to the variable
  478. cur_pixel,
  479. which contains the index of the next pixel to be computed.
  480. .I res_results
  481. is used by the function
  482. view_pixel
  483. to serialize access to the result buffer.  This is necessary because
  484. few processors have hardware multi-processor interlocking on
  485. byte operations within the same word.
  486. .I res_model
  487. is used by the \fBlibspl\fR spline library routines to serialize operations
  488. which cause the model to be further refined during the raytracing process,
  489. so that data structures remain consistent.
  490. .PP
  491. Application of the usual client-server model of computing would
  492. suggest that one stream of execution would be dedicated to dispatching the
  493. next task, while the rest of the streams of execution would be used for
  494. ray-tracing computations.  However, in this case, the dispatching operation
  495. is trivial and a ``self-dispatching'' algorithm is used,
  496. with a critical section
  497. used to protect the shared variable
  498. cur_pixel.
  499. The real purpose of the function
  500. do_run()
  501. is to perform whatever machine-specific operation is required to
  502. initiate
  503. .I npsw
  504. streams of execution within the address space of the \fBrt\fR program, and
  505. then to have each stream call the function
  506. worker(),
  507. each with appropriate local stack space.
  508. .PP
  509. Each worker() function will loop until no more pixels remain,
  510. taking the next available pixel index.
  511. For each pass through the loop, RES_ACQUIRE(res_worker) will be
  512. used to acquire the semaphore, after which the index of the next
  513. pixel to be computed, \fIcur_pixel\fR,
  514. will be acquired and incremented, and before the semaphore is released,
  515. ie,
  516. .nf
  517. .sp .5
  518. worker() {
  519.     while(1)  {
  520.         RES_ACQUIRE( &rt_g.res_worker );
  521.         my_index = cur_pixel++;
  522.         RES_RELEASE( &rt_g.res_worker );
  523.         if( my_index > last_pixel )
  524.             break;
  525.         a.a_x = my_index%width;
  526.         a.a_y = my_index/width;
  527.         ...compute ray parameters...
  528.         rt_shootray( &a );
  529.     }
  530. }
  531. .fi
  532. .PP
  533. On the Denelcor HEP H-1000 each word of memory has a full/empty tag bit
  534. in addition to 64 data bits.
  535. RES_ACQUIRE is implemented using the
  536. Daread()
  537. primitive, which uses the hardware capability to wait until the
  538. semaphore word is full, then read it, and mark it as empty.
  539. RES_RELEASE is implemented using the
  540. Daset()
  541. primitive, which marks the word as full.
  542. do_run()
  543. starts additional streams of execution using the
  544. Dcreate(worker)
  545. primitive, which creates another stream which immediately calls the
  546. worker()
  547. function.
  548. .PP
  549. On the Alliant FX/8, RES_ACQUIRE is implemented using the hardware
  550. instruction test-and-set (TAS) which tests a location for being
  551. zero.
  552. As an atomic operation,
  553. if the location is zero, it sets it non-zero and
  554. sets the condition codes appropriately.  RES_ACQUIRE embeds this
  555. test-and-set instruction in a polling loop to wait for acquisition of
  556. the resource.
  557. RES_RELEASE just zeros the
  558. semaphore word.  Parallel execution is achieved by using the
  559. hardware capability to spread a loop across multiple processors,
  560. so a simple loop from 0 to 7 which calls
  561. worker()
  562. is executed in hardware concurrent mode.  Each concurrent instance
  563. of worker() is given a separate stack area in the ``cactus stack''.
  564. .PP
  565. On the Cray X-MP and Cray-2, the Cray multi-tasking library is used.
  566. RES_ACQUIRE maps into LOCKON, and RES_RELEASE maps into LOCKOFF,
  567. while
  568. do_run()
  569. just calls
  570. TSKSTART(worker)
  571. to obtain extra workers.
  572. .NH 2
  573. Performance Measurements
  574. .PP
  575. An important part of the BRL CAD Package is a set of five benchmark model
  576. databases and associated viewing parameters, which permit the relative
  577. performance of different computers and configurations to be made using
  578. a significant production program as the basis of comparison. For the
  579. purposes of this paper, just the "Moss" database will be used for
  580. comparison.  Since this benchmark generates pixels the fastest, it will
  581. place the greatest demands on any parallel processing scheme. The
  582. benchmark image is computed at 512x512 resolution.
  583. .PP
  584. The relative performance figures for running \fBrt\fR in the parallel mode
  585. with Release 1.20 of the BRL CAD Package are presented below. The
  586. Alliant FX/8 machine was brl-vector.arpa, configured with 8
  587. Computational Elements (CEs), 6 68012 Interactive Processors (IPs), 32
  588. Mbytes of main memory, and was running Concentrix 2.0, a port of 4.2 BSD
  589. UNIX.
  590. The Cray X-MP/48 machine was brl-patton.arpa, serial number 213, with
  591. 4 processors, 8 Mwords of main memory, with a clock period
  592. of 8.5 ns, and UNICOS 2.0, a port of System V UNIX.
  593. Unfortunately, no comprehensive results are available for the
  594. Denelcor HEP, the only other parallel computer known to have run this code.
  595. .TS
  596. center box;
  597. c s s s s
  598. n n n n n.
  599. Parallel \fBrt\fR Speedup -vs- # of Processors
  600. _
  601. # Processors    FX/8    (eff)    X-MP/48    (eff)
  602. _
  603. 1    1.00    100%    1.00    100%
  604. 2    1.84    92.0%    1.99    99.5%
  605. 3    2.79    93.0%    2.96    98.7%
  606. 4    3.68    92.0%    3.86    96.5%
  607. 5    4.80    96.0%    
  608. 6    5.70    95.0%    
  609. 7    6.50    92.9%    
  610. 8    7.46    93.3%    
  611. .TE
  612. .PP
  613. The multiple-processor performance of \fBrt\fR increases nearly
  614. linearly for shared memory machines
  615. with small collections of processors.
  616. The slight speedup of the Alliant when the fifth processor is added
  617. comes from the fact that the first four processors share one cache
  618. memory, while the second four share a second cache memory.
  619. To date, \fBrt\fR holds the record for the best achieved speedup for parallel
  620. processing on both the Cray X-MP/48 and the Alliant.
  621. Measurements on the HEP, before
  622. it was dismantled, indicated that near-linear improvements continued through
  623. 128 streams of execution.  This performance is due to the fact that
  624. the critical sections are very small, typically just a few lines of code,
  625. and that they account for an insignificant portion of the computation time.
  626. When \fBrt\fR is run in parallel and the number of processors is increased,
  627. the limit to overall performance will be determined
  628. by the total bandwidth of the shared memory, and by memory conflicts over
  629. popular regions of code and data.
  630. .NH 1
  631. DISTRIBUTED COMPUTATION ON LOOSELY-COUPLED ENSEMBLES OF PROCESSORS
  632. .PP
  633. The basic assumption of this design is that network bandwidth is
  634. modest, so that the number of bytes and packets of overhead should not exceed
  635. the number of bytes and packets of results.
  636. The natural implementation would be to provide
  637. a remote procedure call (RPC) interface to
  638. rt_shootray(), so that when additional subsidiary rays are needed,
  639. more processors could potentially be utilized.  However, measurements
  640. of this approach on VAX, Gould, and Alliant computers indicates that
  641. the system-call and communications overhead is comparable to the
  642. processing time for one ray/model intersection calculation.
  643. This much overhead rules out the RPC-per-ray interface for practical
  644. implementations.
  645. On some tightly coupled
  646. ensemble computers, there might be little penalty for such an approach,
  647. but in general, some larger unit of work must be exchanged.
  648. .PP
  649. It was not the intention of the author to develop another protocol
  650. for remote file access, so the issue of distributing the model database
  651. to the \fBrtsrv\fR server machines is handled outside of the context of
  652. the \fBremrt\fR and \fBrtsrv\fR software.
  653. In decreasing order of preference, the
  654. methods for model database distribution that are currently used
  655. are Sun NFS, Berkeley \fBrdist\fR, Berkeley \fBrcp\fR,
  656. and ordinary DARPA \fBftp\fR.
  657. Note that the binary databases need to be converted to a portable
  658. format before they are transmitted across the network, because \fBrtsrv\fR
  659. runs on a wide variety of processor types.
  660. Except for the model databases
  661. and the executable code of the \fBrtsrv\fR server process itself,
  662. no file storage is used on any of the server machines.
  663. .NH 2
  664. Distribution of Work
  665. .PP
  666. The approach used in \fBremrt\fR involves a single dispatcher
  667. process, which communicates with an arbitrary number of server
  668. processes.
  669. Work is assigned in groups of scanlines.
  670. As each server finishes a scanline, 
  671. the results are sent back to the dispatcher,
  672. where they are stored.
  673. Completed scanlines are removed from the list of scanlines to be done
  674. and from the list of scanlines currently assigned to that server.
  675. Different servers may be working on entirely different frames.
  676. Before a server is assigned scanlines from a new frame, it is sent
  677. a new set of options and viewpoint information.
  678. .PP
  679. The underlying communications layer used
  680. is the package (PKG) protocol, provided by the \fBlibpkg\fR library,
  681. so that all communications are known to be
  682. reliable, and communication disruptions are noticed.
  683. Whenever the
  684. dispatcher is notified by the \fBlibpkg\fR routines that contact with a server
  685. has been lost, all unfinished scanlines assigned to that server will be
  686. requeued at the head of the ``work to do'' queue, so that it will be
  687. assigned to the very next available server, allowing tardy scanlines to
  688. be finished quickly.
  689. .NH 2
  690. Distribution Protocol
  691. .PP
  692. When a server process \fBrtsrv\fR is started, the host name of the machine
  693. running the dispatcher process is given as a command line argument.
  694. The server process can be started from a command in the dispatcher
  695. \fBremrt\fR, which uses \fBsystem\fR(3)
  696. to run the \fBrsh\fR program, or directly via some other mechanism.
  697. This avoids the need to register the \fBrtsrv\fR program as a system network
  698. daemon and transfers issues of access control, permissions, and
  699. accounting onto other, more appropriate tools. Initially, the \fBrtsrv\fR
  700. server initiates a PKG connection to the dispatcher process and then
  701. enters a loop reading commands from the dispatcher. Some commands
  702. generate no response at all, some generate one response message, and
  703. some generate multiple response messages.  However, note that the server
  704. does not expect to receive any additional messages from the dispatcher
  705. until after it has finished processing a request, so that requests do
  706. not have to be buffered in the server.  While this simplifies the code,
  707. it has some performance implications, which are discussed later.
  708. .PP
  709. In the first stage, the message received must be of type MSG_START, with
  710. string parameters specifying the pathname of the model database and the
  711. names of the desired treetops.  If all goes well, the server responds
  712. with a MSG_START message, otherwise diagnostics are returned as string
  713. parameters to a MSG_PRINT message and the server exits.
  714. .PP
  715. In the second
  716. stage, the message received must be of type MSG_OPTIONS or MSG_MATRIX.
  717. MSG_OPTIONS specifies the image size and shape, hypersampling, stereo
  718. viewing, perspective -vs- ortho view, and control of randomization
  719. effects (the ``benchmark'' flag), using the familiar UNIX command line
  720. option format. MSG_MATRIX contains the 16 ASCII floating point numbers 
  721. for the 4x4 homogeneous transformation matrix which represents the
  722. desired view.
  723. .PP
  724. In the third stage, the server waits for messages of type MSG_LINES,
  725. which specify the starting and ending scanline to be processed.
  726. As each scanline is completed, it is immediately sent back to the
  727. dispatcher process to minimize the amount of computation that could
  728. be lost in case of server failure or communications outage.
  729. Each scanline is returned in a message of type MSG_PIXELS.  The first
  730. two bytes of that message contain the scanline number in 
  731. network order 16-bit binary.
  732. Following that is the 3*width bytes of RGB
  733. data that represents the scanline.
  734. When all the scanlines specified in the MSG_LINES command are processed,
  735. the server again waits for another message, either another MSG_LINES
  736. command or a MSG_OPTIONS/MSG_MATRIX command to specify a new view.
  737. .PP
  738. At any time, a MSG_RESTART message can be received by the server, which
  739. indicates that it should close all it's files and
  740. immediately re-\fBexec\fR(2) itself, either to prepare for processing
  741. an entirely new model, or as an error recovery aid.
  742. A MSG_LOGLVL message can be received at any time, to enable and disable
  743. the issuing of MSG_PRINT output.
  744. A MSG_END message suggests that the server should commit suicide,
  745. courteously.
  746. .NH 2
  747. Dispatching Algorithm
  748. .PP
  749. The dispatching (scheduling) algorithm revolves around two main lists,
  750. the first being a list of currently connected servers and
  751. the second being a list of frames still to be done.  For each unfinished
  752. frame, a list of scanlines remaining to be done is maintained.
  753. For each server, a list of the currently assigned scanlines is kept.
  754. Whenever a server returns a scanline, it is removed from the list of
  755. scanlines assigned to that server, stored in the output image,
  756. and also in the optional attached framebuffer.
  757. (It can be quite entertaining to watch the scanlines racing up the screen,
  758. especially when using processors of significantly different speeds).
  759. If the arrival of this scanline completes a frame, then the
  760. frame is written to disk on the dispatcher machine, timing data is computed,
  761. and that frame
  762. is removed from the list of work to be done.
  763. .PP
  764. When a server finishes the last scanline of its assignment and more
  765. work remains to be done, the list of unfinished frames is searched and
  766. the next available increment of work is assigned.  Work is assigned in
  767. blocks of consecutive scanlines, up to a per-server maximum assignment size.
  768. The block of scanlines is recorded as the server's new assignment and
  769. is removed from the list of work to be done.
  770. .NH 2
  771. Reliability Issues
  772. .PP
  773. If the \fBlibpkg\fR communications layer looses contact with a server machine,
  774. or if \fBremrt\fR is commanded to drop a server, then the scanlines remaining
  775. in the assignment are requeued at the head of the list of scanlines remaining
  776. for that frame.  They are placed at the head of the list so that the first
  777. available server will finish the tardy work, even if it had gone ahead to
  778. work on a subsequent frame.
  779. .PP
  780. Presently, adding and dropping server machines is a manual (or script
  781. driven) operation.  It would be desirable to develop a separate
  782. machine-independent network mechanism
  783. that \fBremrt\fR could use to inquire about the current loading and availability
  784. of server machines, but this has not been done.
  785. This would permit periodic status requests to be made
  786. and automatic reacquisition of eligible server machines
  787. could be attempted.
  788. Peterson's Distrib
  789. .[
  790. Peterson Distributed Computation
  791. .]
  792. System incorporates this as a built-in part of the distributed computing
  793. framework, but it seems that using an independent transaction-based
  794. facility such as Pistritto's Host Monitoring Protocol (HMP) facility
  795. .[
  796. Natalie Muuss BRL VAX UNIX Manual
  797. .]
  798. would be a more general solution.
  799. .PP
  800. If the dispatcher fails, all frames that have not been completed
  801. are lost;  on restart,
  802. execution resumes at the beginning of the first uncompleted frame.
  803. By carefully choosing a machine that has excellent reliability to
  804. run the dispatcher on, the issue of dispatcher failure can be largely
  805. avoided.  However, typically no more than two frames will be lost,
  806. minimizing the impact.  For frames that take extremely long times to
  807. compute, it would be reasonable extend the dispatcher to snapshot the work
  808. queues and partially assembled frames in a disk file, to permit operation
  809. to resume from the last ``checkpoint''.
  810. .NH 2
  811. Distributed remrt Performance
  812. .PP
  813. Ten identical Sun-3/50 systems were used
  814. to test the performance of \fBremrt\fR.
  815. All had 68881 floating point units and 4 Mbytes of memory,
  816. and all were in normal timesharing mode, unused except for
  817. running the tests and the slight overhead
  818. imposed by /etc/update, \fBrwhod\fR, etc.
  819. To provide a baseline performance figure for comparison, the
  820. benchmark image was computed in the normal way using \fBrt\fR, to
  821. avoid any overhead which might be introduced by \fBremrt\fR.
  822. The elapsed time to execute the ray-tracing portion of the benchmark
  823. was 2639 seconds;  the preparation phase was not included, but amounted
  824. to only a few seconds.
  825. .TS
  826. center box;
  827. c s s   s s   s s
  828. l c s | c s | c c
  829. l c c | c c | c c
  830. l n n | n n | n n.
  831. \fBremrt\fR Speedup -vs- # of Processors
  832. _
  833.     Ratios    Elapsed Seconds
  834. # CPUs    Theory    Sun-3/50    Theory    Sun-3/50    Total Speedup    Efficiency
  835. _
  836. 1    1.0000    1.0072    2639.0    2658    0.993    99.3%
  837. 2    0.5000    0.5119    1319.5    1351    1.953    97.7%
  838. 3    0.3333    0.3357    879.6    886    2.979    99.3%
  839. 4    0.2500    0.2524    659.7    666    3.949    98.7%
  840. 5    0.2000    0.2027    527.8    535    4.916    98.3%
  841. _
  842. 6    0.1666    0.1686    429.8    445    5.910    98.5%
  843. 7    0.1429    0.1470    377.0    388    6.778    96.8%
  844. 8    0.1250    0.1266    329.9    334    7.874    98.4%
  845. 9    0.1111    0.1133    293.2    299    8.796    97.7%
  846. 10    0.1000    0.1019    263.9    269    9.777    97.8%
  847. .TE
  848. .PP
  849. The ``speedup'' figure of 0.993 for 1 CPU shows the loss of performance
  850. of 0.7% introduced by the overhead of
  851. the \fBremrt\fR to \fBrtsrv\fR communications,
  852. versus the non-distributed \fBrt\fR performance figure. The primary result of note
  853. is that the speedup of the \fBremrt\fR network distributed application is
  854. very close to the theoretical maximum speedup, with a total efficiency
  855. of 97.8% for the ten Sun case!
  856. The very slight loss of performance noticed (2.23%)
  857. is due mostly to ``new assignment latency'',
  858. discussed further below.  Even so, it is worth noting that the speedup
  859. achieved by adding processors with \fBremrt\fR was even better than the
  860. performance achieved by adding processors in parallel mode with \fBrt\fR.
  861. This effect is due mostly to the lack of memory and semaphore contention
  862. between the \fBremrt\fR machines.
  863. .PP
  864. Unfortunately, time did not permit configuring and testing
  865. multiple Alliants running \fBrtsrv\fR in full parallel mode,
  866. although such operation is supported by \fBrtsrv\fR.
  867. .PP
  868. When \fBremrt\fR is actually being used for producing images, many different
  869. types of processors can be used together.  The aggregate performance of
  870. all the available machines on a campus network is truly awesome,
  871. especially when a Cray or two is included! Even in this
  872. case, the network bandwidth required does not exceed the capacity of an
  873. Ethernet (yet). The bandwidth requirements are sufficiently small that
  874. it is practical to run many \fBrtsrv\fR processes distributed over the
  875. ARPANET/MILNET. On one such occasion in early 1986, 13 Gould PN9080
  876. machines were used all over the east coast to finish some images for a
  877. publication deadline.
  878. .NH 2
  879. Performance Issues
  880. .PP
  881. The policy of making work assignments in terms of multiple adjacent
  882. scanlines
  883. reduces 
  884. the processing requirements of the dispatcher and also improves the
  885. efficiency of the servers.
  886. As a server finishes a scanline, it can give the scanline to
  887. the local operating system to send to the dispatcher machine,
  888. while the server
  889. continues with the computation, allowing the transmission to be
  890. overlapped with more computation.  When gateways and wide-area networks
  891. are involved (with their accompanying increase in latency and packet loss),
  892. this is an important consideration.  In the current
  893. implementation, assignments are always blocks of three scanlines
  894. because there is no general way for the \fBrtsrv\fR process to know what kind
  895. of machine it is running on and how fast it is likely to go.  Clearly,
  896. it would be worthwhile to assign larger blocks of scanlines to the
  897. faster processors so as to minimize idle time and control traffic overhead.
  898. Seemingly the best way to determine this would be to measure the rate of
  899. scanline completion and dynamically adjust the allocation size.
  900. This is not currently implemented.
  901. .PP
  902. By increasing the scanline block assignment size for the faster
  903. processors, the amount of time the server spends waiting for a new
  904. assignment (termed ``new assignment latency'') will be diminished, but
  905. not eliminated. Because the current design assumes that the server will
  906. not receive another request until the previous request has been fully
  907. processed, no easy solution exists.  Extending the server implementation
  908. to buffer at least one additional request would permit this limitation
  909. to be overcome, and the dispatcher would then have the option of sending
  910. a second assignment before the first one had completed, to always keep
  911. the server ``pipeline'' full.  For the case of very large numbers of
  912. servers, this pipelining will be important to keep delays in the
  913. dispatcher from affecting performance. In the case of very fast servers,
  914. pipelining will be important in achieving maximum server utilization, by
  915. overcoming network and dispatcher delays.
  916. .PP
  917. To obtain an advantage from the pipeline effect of the multiple scanline
  918. work assignments, it is important that the network implementations
  919. in both the servers and the dispatcher have adequate buffering to
  920. hold an entire scanline (typically 3K bytes).  For the dispatcher,
  921. it is a good idea to increase the default TCP receive space (and thus
  922. the receive window size) from 4K bytes to 16K bytes.  For the server
  923. machines, it is a good idea to increase the default TCP transmit space
  924. from 4K bytes to 16K bytes.  This can be accomplished by modifying
  925. the file /sys/netinet/tcp_usrreq.c to read:
  926. .sp .5
  927. .nf
  928. int   tcp_sendspace = 1024*16;
  929. int   tcp_recvspace = 1024*16;
  930. .fi
  931. .sp .5
  932. or to make suitable modifications to the binary image of the kernel
  933. using \fIadb\fR(1):
  934. .sp .5
  935. .nf
  936. adb -w -k /vmunix
  937. tcp_sendspace?W 0x4000
  938. tcp_recvspace?W 0x4000
  939. .fi
  940. .sp .5
  941. .PP
  942. The dispatcher process must maintain an active network connection to
  943. each of the server machines.  In all systems there is some limit to the
  944. number of open files that a single process may use (symbol NOFILE);  in
  945. 4.3 BSD UNIX, the limit is 64 open files.  For the current implementation,
  946. this places an upper bound on the number of servers that can be used.
  947. As many campus networks have more than 64 machines available at night,
  948. it would be nice if this limit could be eased.  One approach is
  949. to increase the limit on the dispatcher machine.  Another approach is to
  950. implement a special ``relay server'' to act as a fan-in/fan-out
  951. mechanism, although the additional latency could get to be an issue.
  952. A third approach is to partition the problem at a higher level.
  953. For example, having the east campus do the beginning of a movie,
  954. and the west campus do the end would reduce the open file problem.
  955. Additionally, if gateways are involved, partitioning the problem may be kinder
  956. to the campus network.
  957. .NH 2
  958. Conclusions
  959. .PP
  960. Parallel computing is good.
  961. .PP
  962. This paper has shown how it is possible to implement good graphics
  963. interfaces within the confines of a single uniprocessor machine.
  964. With the adoption of
  965. a ``software tools'' approach when providing data handling capabilities,
  966. it was shown how to transparently take advantage of multi-processor
  967. machines, and thus realize a speed advantage.
  968. Furthermore, the careful selection of file formats permitted
  969. realizing a further speed advantage in the accomplishment of a single task
  970. by utilizing multiple systems located across a network.
  971. .PP
  972. Carying the theme of increased speed further,
  973. multi-processor sytems were examined as a vehicle for making single
  974. image generation tools operate faster.
  975. An important result was to note that
  976. when operation in a shared memory parallel environment was an initial design
  977. goal, the implementation of concurrently reentrant code did not significantly
  978. increase the complexity of the software.  Having code with such properties allows
  979. direct utilization of nearly any shared memory multiprocessor with
  980. a minimum of system-specific support, namely the RES_ACQUIRE and RES_RELEASE
  981. semaphore operations, and some mechanism for starting multiple streams
  982. of execution within the same address space.
  983. .PP
  984. Finally, collections of processors connected only by conventional
  985. speed network links are considered as the final 
  986. environment for making a single tool operate faster using multiprocessing.
  987. It was shown that
  988. network distributed computing need not be inefficient or difficult.
  989. The protocol and dispatching mechanism described in the preceding
  990. sections has been shown to be very effective at taking the
  991. computationally intensive task of generating ray-traced images and
  992. distributing it across multiple processors connected only by a
  993. communications network. There are a significant number of other
  994. application programs that could directly utilize the techniques and
  995. control software implemented in \fBremrt\fR to achieve network distributed
  996. operation.  However, the development and operation of this type of
  997. program is still a research effort; the technology
  998. is not properly packaged for widespread, everyday use.
  999. Furthermore, it is clear that the techniques used in \fBremrt\fR are not
  1000. sufficiently general to be applied to all scientific problems.  In
  1001. particular, problems where each ``cell'' has dependencies on some or
  1002. all of the neighboring cells will require different techniques.
  1003. .PP
  1004. Massive proliferation of computers is a trend that is likely to continue
  1005. through the 1980s into the 1990s and beyond.  Developing software to
  1006. utilize significant numbers of network connected processors is the
  1007. coming challenge. This paper has presented a strategy that meets this
  1008. challenge, and provides a simple, powerful, and efficient method for
  1009. distributing a significant family of scientific analysis codes across
  1010. multiple computers.
  1011. .SH
  1012. Acknowledgements
  1013. .PP
  1014. The author would like to thank
  1015. Dr. Paul Deitz for providing his unflagging support and encouragement,
  1016. Phil Dykstra, Paul Stay, Gary Moss, Chuck Kennedy, and Bob Reschly
  1017. for the long hours as we designed and built this software,
  1018. and Dr. Dave Rogers for once again
  1019. persuading me to write it all down.
  1020. .PP
  1021. The following strings which have been included in this paper
  1022. are known to enjoy protection as trademarks;
  1023. the trademark ownership is acknowledged in the table below.
  1024. .TS
  1025. center;
  1026. l l.
  1027. Trademark    Trademark Owner
  1028. _
  1029. Cray    Cray Research, Inc
  1030. Ethernet    Xerox Corporation
  1031. FX/8    Alliant Computer Systems Corporation
  1032. IBM 370    International Business Machines Corporation
  1033. Macintosh    Apple Computer, Inc
  1034. MacPaint    Apple Computer, Inc
  1035. NFS    Sun Microsystems, Inc
  1036. PowerNode    Gould, Inc
  1037. ProNet    Proteon, Inc
  1038. Sun Workstation    Sun Microsystems, Inc
  1039. SunView    Sun Microsystems, Inc
  1040. UNIX    AT&T Bell Laboratories
  1041. UNICOS    Cray Research, Inc
  1042. VAX    Digital Equipment Corporation
  1043. VaxStation    Digital Equipment Corporation
  1044. X Window System    Massachusetts Institute of Technology
  1045. .TE
  1046.