| 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
| 3 | "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| 4 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 5 | <head> |
| 6 | <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> |
| 7 | <meta name="generator" content="AsciiDoc 10.1.2" /> |
| 8 | <title>Parallel GNU APL</title> |
| 9 | <style type="text/css"> |
| 10 | /* Shared CSS for AsciiDoc xhtml11 and html5 backends */ |
| 11 | |
| 12 | /* Default font. */ |
| 13 | body { |
| 14 | font-family: Georgia,serif; |
| 15 | } |
| 16 | |
| 17 | /* Title font. */ |
| 18 | h1, h2, h3, h4, h5, h6, |
| 19 | div.title, caption.title, |
| 20 | thead, p.table.header, |
| 21 | #toctitle, |
| 22 | #author, #revnumber, #revdate, #revremark, |
| 23 | #footer { |
| 24 | font-family: Arial,Helvetica,sans-serif; |
| 25 | } |
| 26 | |
| 27 | body { |
| 28 | margin: 1em 5% 1em 5%; |
| 29 | } |
| 30 | |
| 31 | a { |
| 32 | color: blue; |
| 33 | text-decoration: underline; |
| 34 | } |
| 35 | a:visited { |
| 36 | color: fuchsia; |
| 37 | } |
| 38 | |
| 39 | em { |
| 40 | font-style: italic; |
| 41 | color: navy; |
| 42 | } |
| 43 | |
| 44 | strong { |
| 45 | font-weight: bold; |
| 46 | color: #083194; |
| 47 | } |
| 48 | |
| 49 | h1, h2, h3, h4, h5, h6 { |
| 50 | color: #527bbd; |
| 51 | margin-top: 1.2em; |
| 52 | margin-bottom: 0.5em; |
| 53 | line-height: 1.3; |
| 54 | } |
| 55 | |
| 56 | h1, h2, h3 { |
| 57 | border-bottom: 2px solid silver; |
| 58 | } |
| 59 | h2 { |
| 60 | padding-top: 0.5em; |
| 61 | } |
| 62 | h3 { |
| 63 | float: left; |
| 64 | } |
| 65 | h3 + * { |
| 66 | clear: left; |
| 67 | } |
| 68 | h5 { |
| 69 | font-size: 1.0em; |
| 70 | } |
| 71 | |
| 72 | div.sectionbody { |
| 73 | margin-left: 0; |
| 74 | } |
| 75 | |
| 76 | hr { |
| 77 | border: 1px solid silver; |
| 78 | } |
| 79 | |
| 80 | p { |
| 81 | margin-top: 0.5em; |
| 82 | margin-bottom: 0.5em; |
| 83 | } |
| 84 | |
| 85 | ul, ol, li > p { |
| 86 | margin-top: 0; |
| 87 | } |
| 88 | ul > li { color: #aaa; } |
| 89 | ul > li > * { color: black; } |
| 90 | |
| 91 | .monospaced, code, pre { |
| 92 | font-family: "Courier New", Courier, monospace; |
| 93 | font-size: inherit; |
| 94 | color: navy; |
| 95 | padding: 0; |
| 96 | margin: 0; |
| 97 | } |
| 98 | pre { |
| 99 | white-space: pre-wrap; |
| 100 | } |
| 101 | |
| 102 | #author { |
| 103 | color: #527bbd; |
| 104 | font-weight: bold; |
| 105 | font-size: 1.1em; |
| 106 | } |
| 107 | #email { |
| 108 | } |
| 109 | #revnumber, #revdate, #revremark { |
| 110 | } |
| 111 | |
| 112 | #footer { |
| 113 | font-size: small; |
| 114 | border-top: 2px solid silver; |
| 115 | padding-top: 0.5em; |
| 116 | margin-top: 4.0em; |
| 117 | } |
| 118 | #footer-text { |
| 119 | float: left; |
| 120 | padding-bottom: 0.5em; |
| 121 | } |
| 122 | #footer-badges { |
| 123 | float: right; |
| 124 | padding-bottom: 0.5em; |
| 125 | } |
| 126 | |
| 127 | #preamble { |
| 128 | margin-top: 1.5em; |
| 129 | margin-bottom: 1.5em; |
| 130 | } |
| 131 | div.imageblock, div.exampleblock, div.verseblock, |
| 132 | div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, |
| 133 | div.admonitionblock { |
| 134 | margin-top: 1.0em; |
| 135 | margin-bottom: 1.5em; |
| 136 | } |
| 137 | div.admonitionblock { |
| 138 | margin-top: 2.0em; |
| 139 | margin-bottom: 2.0em; |
| 140 | margin-right: 10%; |
| 141 | color: #606060; |
| 142 | } |
| 143 | |
| 144 | div.content { /* Block element content. */ |
| 145 | padding: 0; |
| 146 | } |
| 147 | |
| 148 | /* Block element titles. */ |
| 149 | div.title, caption.title { |
| 150 | color: #527bbd; |
| 151 | font-weight: bold; |
| 152 | text-align: left; |
| 153 | margin-top: 1.0em; |
| 154 | margin-bottom: 0.5em; |
| 155 | } |
| 156 | div.title + * { |
| 157 | margin-top: 0; |
| 158 | } |
| 159 | |
| 160 | td div.title:first-child { |
| 161 | margin-top: 0.0em; |
| 162 | } |
| 163 | div.content div.title:first-child { |
| 164 | margin-top: 0.0em; |
| 165 | } |
| 166 | div.content + div.title { |
| 167 | margin-top: 0.0em; |
| 168 | } |
| 169 | |
| 170 | div.sidebarblock > div.content { |
| 171 | background: #ffffee; |
| 172 | border: 1px solid #dddddd; |
| 173 | border-left: 4px solid #f0f0f0; |
| 174 | padding: 0.5em; |
| 175 | } |
| 176 | |
| 177 | div.listingblock > div.content { |
| 178 | border: 1px solid #dddddd; |
| 179 | border-left: 5px solid #f0f0f0; |
| 180 | background: #f8f8f8; |
| 181 | padding: 0.5em; |
| 182 | } |
| 183 | |
| 184 | div.quoteblock, div.verseblock { |
| 185 | padding-left: 1.0em; |
| 186 | margin-left: 1.0em; |
| 187 | margin-right: 10%; |
| 188 | border-left: 5px solid #f0f0f0; |
| 189 | color: #888; |
| 190 | } |
| 191 | |
| 192 | div.quoteblock > div.attribution { |
| 193 | padding-top: 0.5em; |
| 194 | text-align: right; |
| 195 | } |
| 196 | |
| 197 | div.verseblock > pre.content { |
| 198 | font-family: inherit; |
| 199 | font-size: inherit; |
| 200 | } |
| 201 | div.verseblock > div.attribution { |
| 202 | padding-top: 0.75em; |
| 203 | text-align: left; |
| 204 | } |
| 205 | /* DEPRECATED: Pre version 8.2.7 verse style literal block. */ |
| 206 | div.verseblock + div.attribution { |
| 207 | text-align: left; |
| 208 | } |
| 209 | |
| 210 | div.admonitionblock .icon { |
| 211 | vertical-align: top; |
| 212 | font-size: 1.1em; |
| 213 | font-weight: bold; |
| 214 | text-decoration: underline; |
| 215 | color: #527bbd; |
| 216 | padding-right: 0.5em; |
| 217 | } |
| 218 | div.admonitionblock td.content { |
| 219 | padding-left: 0.5em; |
| 220 | border-left: 3px solid #dddddd; |
| 221 | } |
| 222 | |
| 223 | div.exampleblock > div.content { |
| 224 | border-left: 3px solid #dddddd; |
| 225 | padding-left: 0.5em; |
| 226 | } |
| 227 | |
| 228 | div.imageblock div.content { padding-left: 0; } |
| 229 | span.image img { border-style: none; vertical-align: text-bottom; } |
| 230 | a.image:visited { color: white; } |
| 231 | |
| 232 | dl { |
| 233 | margin-top: 0.8em; |
| 234 | margin-bottom: 0.8em; |
| 235 | } |
| 236 | dt { |
| 237 | margin-top: 0.5em; |
| 238 | margin-bottom: 0; |
| 239 | font-style: normal; |
| 240 | color: navy; |
| 241 | } |
| 242 | dd > *:first-child { |
| 243 | margin-top: 0.1em; |
| 244 | } |
| 245 | |
| 246 | ul, ol { |
| 247 | list-style-position: outside; |
| 248 | } |
| 249 | ol.arabic { |
| 250 | list-style-type: decimal; |
| 251 | } |
| 252 | ol.loweralpha { |
| 253 | list-style-type: lower-alpha; |
| 254 | } |
| 255 | ol.upperalpha { |
| 256 | list-style-type: upper-alpha; |
| 257 | } |
| 258 | ol.lowerroman { |
| 259 | list-style-type: lower-roman; |
| 260 | } |
| 261 | ol.upperroman { |
| 262 | list-style-type: upper-roman; |
| 263 | } |
| 264 | |
| 265 | div.compact ul, div.compact ol, |
| 266 | div.compact p, div.compact p, |
| 267 | div.compact div, div.compact div { |
| 268 | margin-top: 0.1em; |
| 269 | margin-bottom: 0.1em; |
| 270 | } |
| 271 | |
| 272 | tfoot { |
| 273 | font-weight: bold; |
| 274 | } |
| 275 | td > div.verse { |
| 276 | white-space: pre; |
| 277 | } |
| 278 | |
| 279 | div.hdlist { |
| 280 | margin-top: 0.8em; |
| 281 | margin-bottom: 0.8em; |
| 282 | } |
| 283 | div.hdlist tr { |
| 284 | padding-bottom: 15px; |
| 285 | } |
| 286 | dt.hdlist1.strong, td.hdlist1.strong { |
| 287 | font-weight: bold; |
| 288 | } |
| 289 | td.hdlist1 { |
| 290 | vertical-align: top; |
| 291 | font-style: normal; |
| 292 | padding-right: 0.8em; |
| 293 | color: navy; |
| 294 | } |
| 295 | td.hdlist2 { |
| 296 | vertical-align: top; |
| 297 | } |
| 298 | div.hdlist.compact tr { |
| 299 | margin: 0; |
| 300 | padding-bottom: 0; |
| 301 | } |
| 302 | |
| 303 | .comment { |
| 304 | background: yellow; |
| 305 | } |
| 306 | |
| 307 | .footnote, .footnoteref { |
| 308 | font-size: 0.8em; |
| 309 | } |
| 310 | |
| 311 | span.footnote, span.footnoteref { |
| 312 | vertical-align: super; |
| 313 | } |
| 314 | |
| 315 | #footnotes { |
| 316 | margin: 20px 0 20px 0; |
| 317 | padding: 7px 0 0 0; |
| 318 | } |
| 319 | |
| 320 | #footnotes div.footnote { |
| 321 | margin: 0 0 5px 0; |
| 322 | } |
| 323 | |
| 324 | #footnotes hr { |
| 325 | border: none; |
| 326 | border-top: 1px solid silver; |
| 327 | height: 1px; |
| 328 | text-align: left; |
| 329 | margin-left: 0; |
| 330 | width: 20%; |
| 331 | min-width: 100px; |
| 332 | } |
| 333 | |
| 334 | div.colist td { |
| 335 | padding-right: 0.5em; |
| 336 | padding-bottom: 0.3em; |
| 337 | vertical-align: top; |
| 338 | } |
| 339 | div.colist td img { |
| 340 | margin-top: 0.3em; |
| 341 | } |
| 342 | |
| 343 | @media print { |
| 344 | #footer-badges { display: none; } |
| 345 | } |
| 346 | |
| 347 | #toc { |
| 348 | margin-bottom: 2.5em; |
| 349 | } |
| 350 | |
| 351 | #toctitle { |
| 352 | color: #527bbd; |
| 353 | font-size: 1.1em; |
| 354 | font-weight: bold; |
| 355 | margin-top: 1.0em; |
| 356 | margin-bottom: 0.1em; |
| 357 | } |
| 358 | |
| 359 | div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { |
| 360 | margin-top: 0; |
| 361 | margin-bottom: 0; |
| 362 | } |
| 363 | div.toclevel2 { |
| 364 | margin-left: 2em; |
| 365 | font-size: 0.9em; |
| 366 | } |
| 367 | div.toclevel3 { |
| 368 | margin-left: 4em; |
| 369 | font-size: 0.9em; |
| 370 | } |
| 371 | div.toclevel4 { |
| 372 | margin-left: 6em; |
| 373 | font-size: 0.9em; |
| 374 | } |
| 375 | |
| 376 | span.aqua { color: aqua; } |
| 377 | span.black { color: black; } |
| 378 | span.blue { color: blue; } |
| 379 | span.fuchsia { color: fuchsia; } |
| 380 | span.gray { color: gray; } |
| 381 | span.green { color: green; } |
| 382 | span.lime { color: lime; } |
| 383 | span.maroon { color: maroon; } |
| 384 | span.navy { color: navy; } |
| 385 | span.olive { color: olive; } |
| 386 | span.purple { color: purple; } |
| 387 | span.red { color: red; } |
| 388 | span.silver { color: silver; } |
| 389 | span.teal { color: teal; } |
| 390 | span.white { color: white; } |
| 391 | span.yellow { color: yellow; } |
| 392 | |
| 393 | span.aqua-background { background: aqua; } |
| 394 | span.black-background { background: black; } |
| 395 | span.blue-background { background: blue; } |
| 396 | span.fuchsia-background { background: fuchsia; } |
| 397 | span.gray-background { background: gray; } |
| 398 | span.green-background { background: green; } |
| 399 | span.lime-background { background: lime; } |
| 400 | span.maroon-background { background: maroon; } |
| 401 | span.navy-background { background: navy; } |
| 402 | span.olive-background { background: olive; } |
| 403 | span.purple-background { background: purple; } |
| 404 | span.red-background { background: red; } |
| 405 | span.silver-background { background: silver; } |
| 406 | span.teal-background { background: teal; } |
| 407 | span.white-background { background: white; } |
| 408 | span.yellow-background { background: yellow; } |
| 409 | |
| 410 | span.big { font-size: 2em; } |
| 411 | span.small { font-size: 0.6em; } |
| 412 | |
| 413 | span.underline { text-decoration: underline; } |
| 414 | span.overline { text-decoration: overline; } |
| 415 | span.line-through { text-decoration: line-through; } |
| 416 | |
| 417 | div.unbreakable { page-break-inside: avoid; } |
| 418 | |
| 419 | |
| 420 | /* |
| 421 | * xhtml11 specific |
| 422 | * |
| 423 | * */ |
| 424 | |
| 425 | div.tableblock { |
| 426 | margin-top: 1.0em; |
| 427 | margin-bottom: 1.5em; |
| 428 | } |
| 429 | div.tableblock > table { |
| 430 | border: 3px solid #527bbd; |
| 431 | } |
| 432 | thead, p.table.header { |
| 433 | font-weight: bold; |
| 434 | color: #527bbd; |
| 435 | } |
| 436 | p.table { |
| 437 | margin-top: 0; |
| 438 | } |
| 439 | /* Because the table frame attribute is overridden by CSS in most browsers. */ |
| 440 | div.tableblock > table[frame="void"] { |
| 441 | border-style: none; |
| 442 | } |
| 443 | div.tableblock > table[frame="hsides"] { |
| 444 | border-left-style: none; |
| 445 | border-right-style: none; |
| 446 | } |
| 447 | div.tableblock > table[frame="vsides"] { |
| 448 | border-top-style: none; |
| 449 | border-bottom-style: none; |
| 450 | } |
| 451 | |
| 452 | |
| 453 | /* |
| 454 | * html5 specific |
| 455 | * |
| 456 | * */ |
| 457 | |
| 458 | table.tableblock { |
| 459 | margin-top: 1.0em; |
| 460 | margin-bottom: 1.5em; |
| 461 | } |
| 462 | thead, p.tableblock.header { |
| 463 | font-weight: bold; |
| 464 | color: #527bbd; |
| 465 | } |
| 466 | p.tableblock { |
| 467 | margin-top: 0; |
| 468 | } |
| 469 | table.tableblock { |
| 470 | border-width: 3px; |
| 471 | border-spacing: 0px; |
| 472 | border-style: solid; |
| 473 | border-color: #527bbd; |
| 474 | border-collapse: collapse; |
| 475 | } |
| 476 | th.tableblock, td.tableblock { |
| 477 | border-width: 1px; |
| 478 | padding: 4px; |
| 479 | border-style: solid; |
| 480 | border-color: #527bbd; |
| 481 | } |
| 482 | |
| 483 | table.tableblock.frame-topbot { |
| 484 | border-left-style: hidden; |
| 485 | border-right-style: hidden; |
| 486 | } |
| 487 | table.tableblock.frame-sides { |
| 488 | border-top-style: hidden; |
| 489 | border-bottom-style: hidden; |
| 490 | } |
| 491 | table.tableblock.frame-none { |
| 492 | border-style: hidden; |
| 493 | } |
| 494 | |
| 495 | th.tableblock.halign-left, td.tableblock.halign-left { |
| 496 | text-align: left; |
| 497 | } |
| 498 | th.tableblock.halign-center, td.tableblock.halign-center { |
| 499 | text-align: center; |
| 500 | } |
| 501 | th.tableblock.halign-right, td.tableblock.halign-right { |
| 502 | text-align: right; |
| 503 | } |
| 504 | |
| 505 | th.tableblock.valign-top, td.tableblock.valign-top { |
| 506 | vertical-align: top; |
| 507 | } |
| 508 | th.tableblock.valign-middle, td.tableblock.valign-middle { |
| 509 | vertical-align: middle; |
| 510 | } |
| 511 | th.tableblock.valign-bottom, td.tableblock.valign-bottom { |
| 512 | vertical-align: bottom; |
| 513 | } |
| 514 | |
| 515 | |
| 516 | /* |
| 517 | * manpage specific |
| 518 | * |
| 519 | * */ |
| 520 | |
| 521 | body.manpage h1 { |
| 522 | padding-top: 0.5em; |
| 523 | padding-bottom: 0.5em; |
| 524 | border-top: 2px solid silver; |
| 525 | border-bottom: 2px solid silver; |
| 526 | } |
| 527 | body.manpage h2 { |
| 528 | border-style: none; |
| 529 | } |
| 530 | body.manpage div.sectionbody { |
| 531 | margin-left: 3em; |
| 532 | } |
| 533 | |
| 534 | @media print { |
| 535 | body.manpage div#toc { display: none; } |
| 536 | } |
| 537 | |
| 538 | |
| 539 | </style> |
| 540 | <script type="text/javascript"> |
| 541 | /*<+'])'); |
| 584 | // Function that scans the DOM tree for header elements (the DOM2 |
| 585 | // nodeIterator API would be a better technique but not supported by all |
| 586 | // browsers). |
| 587 | var iterate = function (el) { |
| 588 | for (var i = el.firstChild; i != null; i = i.nextSibling) { |
| 589 | if (i.nodeType == 1 /* Node.ELEMENT_NODE */) { |
| 590 | var mo = re.exec(i.tagName); |
| 591 | if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") { |
| 592 | result[result.length] = new TocEntry(i, getText(i), mo[1]-1); |
| 593 | } |
| 594 | iterate(i); |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | iterate(el); |
| 599 | return result; |
| 600 | } |
| 601 | |
| 602 | var toc = document.getElementById("toc"); |
| 603 | if (!toc) { |
| 604 | return; |
| 605 | } |
| 606 | |
| 607 | // Delete existing TOC entries in case we're reloading the TOC. |
| 608 | var tocEntriesToRemove = []; |
| 609 | var i; |
| 610 | for (i = 0; i < toc.childNodes.length; i++) { |
| 611 | var entry = toc.childNodes[i]; |
| 612 | if (entry.nodeName.toLowerCase() == 'div' |
| 613 | && entry.getAttribute("class") |
| 614 | && entry.getAttribute("class").match(/^toclevel/)) |
| 615 | tocEntriesToRemove.push(entry); |
| 616 | } |
| 617 | for (i = 0; i < tocEntriesToRemove.length; i++) { |
| 618 | toc.removeChild(tocEntriesToRemove[i]); |
| 619 | } |
| 620 | |
| 621 | // Rebuild TOC entries. |
| 622 | var entries = tocEntries(document.getElementById("content"), toclevels); |
| 623 | for (var i = 0; i < entries.length; ++i) { |
| 624 | var entry = entries[i]; |
| 625 | if (entry.element.id == "") |
| 626 | entry.element.id = "_toc_" + i; |
| 627 | var a = document.createElement("a"); |
| 628 | a.href = "#" + entry.element.id; |
| 629 | a.appendChild(document.createTextNode(entry.text)); |
| 630 | var div = document.createElement("div"); |
| 631 | div.appendChild(a); |
| 632 | div.className = "toclevel" + entry.toclevel; |
| 633 | toc.appendChild(div); |
| 634 | } |
| 635 | if (entries.length == 0) |
| 636 | toc.parentNode.removeChild(toc); |
| 637 | }, |
| 638 | |
| 639 | |
| 640 | ///////////////////////////////////////////////////////////////////// |
| 641 | // Footnotes generator |
| 642 | ///////////////////////////////////////////////////////////////////// |
| 643 | |
| 644 | /* Based on footnote generation code from: |
| 645 | * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html |
| 646 | */ |
| 647 | |
| 648 | footnotes: function () { |
| 649 | // Delete existing footnote entries in case we're reloading the footnodes. |
| 650 | var i; |
| 651 | var noteholder = document.getElementById("footnotes"); |
| 652 | if (!noteholder) { |
| 653 | return; |
| 654 | } |
| 655 | var entriesToRemove = []; |
| 656 | for (i = 0; i < noteholder.childNodes.length; i++) { |
| 657 | var entry = noteholder.childNodes[i]; |
| 658 | if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote") |
| 659 | entriesToRemove.push(entry); |
| 660 | } |
| 661 | for (i = 0; i < entriesToRemove.length; i++) { |
| 662 | noteholder.removeChild(entriesToRemove[i]); |
| 663 | } |
| 664 | |
| 665 | // Rebuild footnote entries. |
| 666 | var cont = document.getElementById("content"); |
| 667 | var spans = cont.getElementsByTagName("span"); |
| 668 | var refs = {}; |
| 669 | var n = 0; |
| 670 | for (i=0; i<spans.length; i++) { |
| 671 | if (spans[i].className == "footnote") { |
| 672 | n++; |
| 673 | var note = spans[i].getAttribute("data-note"); |
| 674 | if (!note) { |
| 675 | // Use [\s\S] in place of . so multi-line matches work. |
| 676 | // Because JavaScript has no s (dotall) regex flag. |
| 677 | note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1]; |
| 678 | spans[i].innerHTML = |
| 679 | "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n + |
| 680 | "' title='View footnote' class='footnote'>" + n + "</a>]"; |
| 681 | spans[i].setAttribute("data-note", note); |
| 682 | } |
| 683 | noteholder.innerHTML += |
| 684 | "<div class='footnote' id='_footnote_" + n + "'>" + |
| 685 | "<a href='#_footnoteref_" + n + "' title='Return to text'>" + |
| 686 | n + "</a>. " + note + "</div>"; |
| 687 | var id =spans[i].getAttribute("id"); |
| 688 | if (id != null) refs["#"+id] = n; |
| 689 | } |
| 690 | } |
| 691 | if (n == 0) |
| 692 | noteholder.parentNode.removeChild(noteholder); |
| 693 | else { |
| 694 | // Process footnoterefs. |
| 695 | for (i=0; i<spans.length; i++) { |
| 696 | if (spans[i].className == "footnoteref") { |
| 697 | var href = spans[i].getElementsByTagName("a")[0].getAttribute("href"); |
| 698 | href = href.match(/#.*/)[0]; // Because IE return full URL. |
| 699 | n = refs[href]; |
| 700 | spans[i].innerHTML = |
| 701 | "[<a href='#_footnote_" + n + |
| 702 | "' title='View footnote' class='footnote'>" + n + "</a>]"; |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | }, |
| 707 | |
| 708 | install: function(toclevels) { |
| 709 | var timerId; |
| 710 | |
| 711 | function reinstall() { |
| 712 | asciidoc.footnotes(); |
| 713 | if (toclevels) { |
| 714 | asciidoc.toc(toclevels); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | function reinstallAndRemoveTimer() { |
| 719 | clearInterval(timerId); |
| 720 | reinstall(); |
| 721 | } |
| 722 | |
| 723 | timerId = setInterval(reinstall, 500); |
| 724 | if (document.addEventListener) |
| 725 | document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false); |
| 726 | else |
| 727 | window.onload = reinstallAndRemoveTimer; |
| 728 | } |
| 729 | |
| 730 | } |
| 731 | asciidoc.install(4); |
| 732 | /*]]>*/ |
| 733 | </script> |
| 734 | </head> |
| 735 | <body class="article"> |
| 736 | <div id="header"> |
| 737 | <h1>Parallel GNU APL</h1> |
| 738 | <span id="author">Jürgen Sauermann, GNU APL</span><br /> |
| 739 | <div id="toc"> |
| 740 | <div id="toctitle">Table of Contents</div> |
| 741 | </div> |
| 742 | </div> |
| 743 | <div id="content"> |
| 744 | <div class="sect1"> |
| 745 | <h2 id="_abstract">Abstract</h2> |
| 746 | <div class="sectionbody"> |
| 747 | <div class="paragraph"><p>This document briefly describes parallel execution in GNU APL</p></div> |
| 748 | </div> |
| 749 | </div> |
| 750 | <div class="sect1"> |
| 751 | <h2 id="_configuration">Configuration</h2> |
| 752 | <div class="sectionbody"> |
| 753 | <div class="paragraph"><p>Parallel execution of APL primitives needs to be <strong>./configure</strong>'d explicitly. |
| 754 | Without such configuration GNU APL executes sequentially. In freshly installed |
| 755 | GNU APL sources (i.e. after an SVN checkout or after unpacking the GNU APL tar |
| 756 | file), the configuration is:</p></div> |
| 757 | <div class="listingblock"> |
| 758 | <div class="content"> |
| 759 | <pre> |
| 760 | |
| 761 | <code>./configure --enable-maintainer-mode \ |
| 762 | VALUE_CHECK_WANTED=no \ |
| 763 | VALUE_HISTORY_WANTED=no \ |
| 764 | PERFORMANCE_COUNTERS_WANTED=yes \ |
| 765 | DYNAMIC_LOG_WANTED=yes \ |
| 766 | ASSERT_LEVEL_WANTED=0 \ |
| 767 | CORE_COUNT_WANTED=-3</code> |
| 768 | |
| 769 | </pre> |
| 770 | </div></div> |
| 771 | <div class="paragraph"><p>If the sources were already <strong>./configure</strong>'d then two make targets achieve |
| 772 | the same:</p></div> |
| 773 | <div class="listingblock"> |
| 774 | <div class="content"> |
| 775 | <pre> |
| 776 | |
| 777 | <code>make parallel |
| 778 | make parallel1</code> |
| 779 | |
| 780 | </pre> |
| 781 | </div></div> |
| 782 | <div class="paragraph"><p>The first make target <strong>parallel</strong> is the setting for maximum performance, while |
| 783 | the second make target <strong>parallel1</strong> is like <strong>parallel</strong> but with internal |
| 784 | performance counters enabled. The performance counters are needed for |
| 785 | benchmarking of the GNU APL performance via <strong>FIO∆get_statistics</strong> in workspace |
| 786 | <strong>5 FILE_IO</strong> and <strong>⎕FIO[201]</strong> respectively.</p></div> |
| 787 | <div class="admonitionblock"> |
| 788 | <table><tr> |
| 789 | <td class="icon"> |
| 790 | <img src="/usr/share/asciidoc/icons/caution.png" alt="Caution" /> |
| 791 | </td> |
| 792 | <td class="content">Parallel execution is an entirely experimental feature that should |
| 793 | not be used in mission-critical applications. Support for bugs caused by |
| 794 | this feature is rather limited.</td> |
| 795 | </tr></table> |
| 796 | </div> |
| 797 | </div> |
| 798 | </div> |
| 799 | <div class="sect1"> |
| 800 | <h2 id="_controlling_the_core_count">Controlling the Core Count</h2> |
| 801 | <div class="sectionbody"> |
| 802 | <div class="paragraph"><p>The number of cores that are used in parallel APL execution can be |
| 803 | controlled in several ways.</p></div> |
| 804 | <div class="sect2"> |
| 805 | <h3 id="_the_configure_option_core_count_wanted">The ./configure Option CORE_COUNT_WANTED</h3> |
| 806 | <div class="paragraph"><p>The first way to control the (maximum) core count is at the point in time when |
| 807 | the interpreter source code is being ./configure’d. The configure option |
| 808 | CORE_COUNT_WANTED defines how the interpreter chooses the number of cores |
| 809 | (see <strong>README-2-configure</strong>):</p></div> |
| 810 | <div class="ulist"><ul> |
| 811 | <li> |
| 812 | <p> |
| 813 | CORE_COUNT_WANTED=0: sequential |
| 814 | </p> |
| 815 | </li> |
| 816 | <li> |
| 817 | <p> |
| 818 | CORE_COUNT_WANTED=1: parallel (but using only 1 core) |
| 819 | </p> |
| 820 | </li> |
| 821 | <li> |
| 822 | <p> |
| 823 | CORE_COUNT_WANTED=2: parallel on 2 cores |
| 824 | </p> |
| 825 | </li> |
| 826 | <li> |
| 827 | <p> |
| 828 | … |
| 829 | </p> |
| 830 | </li> |
| 831 | <li> |
| 832 | <p> |
| 833 | CORE_COUNT_WANTED=N: parallel on N cores |
| 834 | </p> |
| 835 | </li> |
| 836 | <li> |
| 837 | <p> |
| 838 | CORE_COUNT_WANTED=-1: parallel on all existing cores |
| 839 | </p> |
| 840 | </li> |
| 841 | <li> |
| 842 | <p> |
| 843 | CORE_COUNT_WANTED=-2: parallel; the core count is determined by the command |
| 844 | line argument -cc of the interpreter |
| 845 | </p> |
| 846 | </li> |
| 847 | <li> |
| 848 | <p> |
| 849 | CORE_COUNT_WANTED=-3: parallel; the core count is determined at interpreter |
| 850 | run-time via ⎕SYL; |
| 851 | </p> |
| 852 | </li> |
| 853 | </ul></div> |
| 854 | <div class="admonitionblock"> |
| 855 | <table><tr> |
| 856 | <td class="icon"> |
| 857 | <img src="/usr/share/asciidoc/icons/note.png" alt="Note" /> |
| 858 | </td> |
| 859 | <td class="content">The command line option -cc works only if CORE_COUNT_WANTED=-2. For |
| 860 | CORE_COUNT_WANTED > 1 or -2, it is the responsibility of the user to ensure |
| 861 | that the desired number of cores actually exist (i.e. this is not checked |
| 862 | because some platforms cannot do that).</td> |
| 863 | </tr></table> |
| 864 | </div> |
| 865 | <div class="paragraph"><p><strong>CORE_COUNT_WANTED=-3</strong> is the most useful setting, because it allows changing |
| 866 | the core count at run-time of an APL program (e.g. in a benchmarking workspace |
| 867 | like <strong>Scalar2.apl</strong>).</p></div> |
| 868 | </div> |
| 869 | <div class="sect2"> |
| 870 | <h3 id="_changing_the_core_count_at_run_time">Changing the Core Count at Run-time</h3> |
| 871 | <div class="paragraph"><p>If <strong>CORE_COUNT_WANTED=-3</strong> (the default) then the system variable <strong>⎕SYL</strong>, in |
| 872 | particular <strong>⎕SYL[24 25 26;]</strong> control the number of cores being used:</p></div> |
| 873 | <div class="listingblock"> |
| 874 | <div class="content"> |
| 875 | <pre> |
| 876 | |
| 877 | <code> ⎕SYL[24 25 26;] |
| 878 | CORE_COUNT_WANTED (per ./configure) ¯3 |
| 879 | cores available 12 |
| 880 | cores used 1</code> |
| 881 | |
| 882 | </pre> |
| 883 | </div></div> |
| 884 | <div class="sect3"> |
| 885 | <h4 id="_syl_24_2">⎕SYL[24;2]</h4> |
| 886 | <div class="paragraph"><p><strong>⎕SYL[24;2])</strong> is a read-only value pertaining to the value used for |
| 887 | <strong>CORE_COUNT_WANTED</strong> in <strong>./configure</strong>.</p></div> |
| 888 | </div> |
| 889 | <div class="sect3"> |
| 890 | <h4 id="_syl_25_2">⎕SYL[25;2]</h4> |
| 891 | <div class="paragraph"><p><strong>⎕SYL[25;2])</strong> is the number of cores either chosen by ⎕SYL[24;2] or else as |
| 892 | indicated by the platform. The value 12 above as reported on a i7-8700 |
| 893 | Intel CPU with 6 physical cores and 2 core threads per physical core.</p></div> |
| 894 | </div> |
| 895 | <div class="sect3"> |
| 896 | <h4 id="_syl_26_2">⎕SYL[26;2]</h4> |
| 897 | <div class="paragraph"><p><strong>⎕SYL[26;2])</strong> is the number of cores used by the interpreter. Setting:</p></div> |
| 898 | <div class="paragraph"><p><strong>⎕SYL[26;2])←0</strong> chooses sequential operation of the interpreter. |
| 899 | <strong>⎕SYL[26;2])←N</strong> with <strong>N≥1 chooses parallel operation on *N</strong> cores. |
| 900 | * Other values trigger a <strong>DOMAIN ERROR</strong>.</p></div> |
| 901 | <div class="admonitionblock"> |
| 902 | <table><tr> |
| 903 | <td class="icon"> |
| 904 | <img src="/usr/share/asciidoc/icons/note.png" alt="Note" /> |
| 905 | </td> |
| 906 | <td class="content"><strong>⎕SYL[26;2])←1</strong> could be useful for benchmarking to see the difference |
| 907 | between parallel and sequential code, but without distributing the |
| 908 | computational load over several cores.</td> |
| 909 | </tr></table> |
| 910 | </div> |
| 911 | <div class="paragraph"><p>Setting <strong>⎕SYL[26;2]</strong> with a proper value in APL calls |
| 912 | <strong>Parallel::set_core_count()</strong> in <strong>Parallel.cc</strong>.</p></div> |
| 913 | </div> |
| 914 | </div> |
| 915 | </div> |
| 916 | </div> |
| 917 | <div class="sect1"> |
| 918 | <h2 id="_the_initialization_of_the_parallel_subsystem">The Initialization of the Parallel Subsystem</h2> |
| 919 | <div class="sectionbody"> |
| 920 | <div class="paragraph"><p>Parallel execution is initialized as follows:</p></div> |
| 921 | <div class="ulist"><ul> |
| 922 | <li> |
| 923 | <p> |
| 924 | the initialization is performed automatically when the interpreter is |
| 925 | started (function <strong>Parallel::init()</strong>). If the interpreter is ./configured |
| 926 | with <strong>DYNAMIC_LOG_WANTED=yes</strong> then logging of the initialization can be |
| 927 | enabled with command line option <strong>-l 41</strong>. |
| 928 | </p> |
| 929 | </li> |
| 930 | <li> |
| 931 | <p> |
| 932 | <strong>Parallel::init()</strong> initializes semaphores related to parallel execution |
| 933 | and then calls <strong>CPU_pool::init()</strong>. <strong>CPU_pool::init()</strong> determines, which CPUs |
| 934 | can be used by the interpreter and stores them in its vector <strong>the_CPUs</strong>. |
| 935 | If <strong>CORE_COUNT_WANTED</strong> is <strong>≥ 0</strong> or <strong>-2</strong> then the CPUs in the vector are |
| 936 | determined by <strong>CORE_COUNT_WANTED</strong> or by the <strong>-cc</strong> command line option |
| 937 | (no checks are performed to verify that the CPUs chosen are correct). |
| 938 | Otherwise, i.e. (<strong>CORE_COUNT_WANTED</strong> is -1 or -3) the cores available to |
| 939 | the interpreter are determined by <strong>pthread_getaffinity_np()</strong> and all CPUs |
| 940 | that are available to the interpreter are stored in the vector. |
| 941 | </p> |
| 942 | </li> |
| 943 | <li> |
| 944 | <p> |
| 945 | Then <strong>Parallel::init()</strong> creates a thread pool with |
| 946 | <strong>Thread_context::init_parallel</strong>, with one thread for each CPU |
| 947 | in <strong>CPU_pool::the_CPUs</strong>. If <strong>CORE_COUNT_WANTED = -3</strong> then only the first |
| 948 | thread is activated (and the user needs to use ⎕SYL in order to activate |
| 949 | more cores. Otherwise all threads are activated (and ⎕SYL cannot be used). |
| 950 | Finally <strong>Parallel::init()</strong> brings all threads into their initial state. |
| 951 | </p> |
| 952 | </li> |
| 953 | </ul></div> |
| 954 | <div class="paragraph"><p>At any point in time, a thread can be in one of 2 states:</p></div> |
| 955 | <div class="ulist"><ul> |
| 956 | <li> |
| 957 | <p> |
| 958 | BLKD: Blocked on its private semaphore <strong>Thread_context::pool_sema</strong>, or |
| 959 | </p> |
| 960 | </li> |
| 961 | <li> |
| 962 | <p> |
| 963 | RUN: Running. |
| 964 | </p> |
| 965 | </li> |
| 966 | </ul></div> |
| 967 | <div class="paragraph"><p>A thread in state RUN can further be in 2 sub-states:</p></div> |
| 968 | <div class="ulist"><ul> |
| 969 | <li> |
| 970 | <p> |
| 971 | busy-waiting for more work to become available, or |
| 972 | </p> |
| 973 | </li> |
| 974 | <li> |
| 975 | <p> |
| 976 | computing the current job. |
| 977 | </p> |
| 978 | </li> |
| 979 | </ul></div> |
| 980 | <div class="paragraph"><p>The first thread in the pool, aka. the <strong>master</strong>, is always in state <strong>RUN</strong> and |
| 981 | is never busy-waiting (instead it executes the APL interpreter).</p></div> |
| 982 | <div class="paragraph"><p>The remaining threads, aka. the <strong>workers</strong>, are in state <strong>BLKD</strong> as long as |
| 983 | they are inactive (this can only happen if ⎕SYL is being used and the worker |
| 984 | is above the value set with ⎕SYL). Otherwise the worker is in state <strong>RUN</strong>. A |
| 985 | worker in state <strong>RUN</strong> is not necessarily computing, e.g. if the joblists are |
| 986 | empty and the worker is busy-waiting for more work.</p></div> |
| 987 | <div class="paragraph"><p>When the interpreter (i.e. the master) needs to compute a primitive scalar |
| 988 | function (or an inner or outer product of a primitive scalar function) with |
| 989 | a sufficiently large argument, then it unleashes the workers |
| 990 | (<strong>Thread_context::M_fork()</strong>), performs its own share of the work, and waits |
| 991 | for all workers to complete their share of the work |
| 992 | (<strong>Thread_context::M_join()</strong>).</p></div> |
| 993 | <div class="paragraph"><p>At the same time, the workers wait for the master’s <strong>M_fork()</strong> in |
| 994 | <strong>Thread_context::PF_fork()</strong>, perform their share of the work, indicate that |
| 995 | their work is complete, and wait for all others to complete as well |
| 996 | (<strong>Thread_context::M_join()</strong>).</p></div> |
| 997 | </div> |
| 998 | </div> |
| 999 | <div class="sect1"> |
| 1000 | <h2 id="_the_operation_of_the_parallel_subsystem">The Operation of the Parallel Subsystem</h2> |
| 1001 | <div class="sectionbody"> |
| 1002 | <div class="paragraph"><p>After initialization, the parallel subsystem works (see <strong>Thread_context.cc/hh</strong>) |
| 1003 | as follows.</p></div> |
| 1004 | <div class="ulist"><ul> |
| 1005 | <li> |
| 1006 | <p> |
| 1007 | worker thread in state BLKD do nothing. This case can only occur with |
| 1008 | <strong>CORE_COUNT_WANTED=-3</strong>, and the transition between states BLKD and RUN can |
| 1009 | (after the initialization) only occur by setting ⎕SYL[26;2]. |
| 1010 | </p> |
| 1011 | </li> |
| 1012 | <li> |
| 1013 | <p> |
| 1014 | every thread maintains a variable <strong>job_number</strong> which is initially 0 for both |
| 1015 | the master and every worker: |
| 1016 | </p> |
| 1017 | </li> |
| 1018 | </ul></div> |
| 1019 | <div class="listingblock"> |
| 1020 | <div class="content"> |
| 1021 | <pre> |
| 1022 | |
| 1023 | <code>Thread_context::Thread_context() |
| 1024 | : N(CNUM_INVALID), |
| 1025 | thread(0), |
| 1026 | *job_number(0)*, |
| 1027 | job_name("no-job-name"), |
| 1028 | blocked(false) |
| 1029 | { |
| 1030 | }</code> |
| 1031 | |
| 1032 | </pre> |
| 1033 | </div></div> |
| 1034 | <div class="ulist"><ul> |
| 1035 | <li> |
| 1036 | <p> |
| 1037 | As long as the <strong>Thread_context::job_number</strong> of the master is equal to the |
| 1038 | <strong>Thread_context::job_number</strong> number of a worker, that worker busy-waits |
| 1039 | until both numbers differ. The master also increments the static variable |
| 1040 | <strong>busy_worker_count</strong>: |
| 1041 | </p> |
| 1042 | </li> |
| 1043 | </ul></div> |
| 1044 | <div class="listingblock"> |
| 1045 | <div class="content"> |
| 1046 | <pre> |
| 1047 | |
| 1048 | <code> /// start parallel execution of work in a worker |
| 1049 | void PF_fork() |
| 1050 | { |
| 1051 | while (get_master().job_number == job_number) |
| 1052 | /* busy wait until the master has increased job_number */ ; |
| 1053 | }</code> |
| 1054 | |
| 1055 | </pre> |
| 1056 | </div></div> |
| 1057 | <div class="ulist"><ul> |
| 1058 | <li> |
| 1059 | <p> |
| 1060 | When the master finds new work (e.g. after interpreting a scalar APL |
| 1061 | function) then it inserts that work into the proper <strong>Parallel_job_list<></strong> of |
| 1062 | each worker and increments its own <strong>Thread_context::job_number</strong> (in |
| 1063 | <strong>Thread_context::M_fork()</strong>). This causes all workers to begin their share of |
| 1064 | the work: |
| 1065 | </p> |
| 1066 | </li> |
| 1067 | </ul></div> |
| 1068 | <div class="listingblock"> |
| 1069 | <div class="content"> |
| 1070 | <pre> |
| 1071 | |
| 1072 | <code> /// start parallel execution of work at the master |
| 1073 | static void M_fork(const char * jname) |
| 1074 | { |
| 1075 | get_master().job_name = jname; |
| 1076 | atomic_add(busy_worker_count, active_core_count - 1); |
| 1077 | ++get_master().job_number; |
| 1078 | }</code> |
| 1079 | |
| 1080 | </pre> |
| 1081 | </div></div> |
| 1082 | <div class="ulist"><ul> |
| 1083 | <li> |
| 1084 | <p> |
| 1085 | The workers perform their work and, after finishing it, increment their |
| 1086 | <strong>Thread_context::job_number</strong> and decrement <strong>busy_worker_count</strong>.again: |
| 1087 | </p> |
| 1088 | </li> |
| 1089 | </ul></div> |
| 1090 | <div class="listingblock"> |
| 1091 | <div class="content"> |
| 1092 | <pre> |
| 1093 | |
| 1094 | <code> /// end parallel execution of work in a worker |
| 1095 | void PF_join() |
| 1096 | { |
| 1097 | atomic_add(busy_worker_count, -1); // we are ready |
| 1098 | ++job_number; // we reached master job_number |
| 1099 | |
| 1100 | // wait until all workers finished or new job from master |
| 1101 | while (atomic_read(busy_worker_count) != 0 && |
| 1102 | get_master().job_number == job_number) |
| 1103 | /* busy wait */ ; |
| 1104 | }</code> |
| 1105 | |
| 1106 | </pre> |
| 1107 | </div></div> |
| 1108 | <div class="imageblock"> |
| 1109 | <div class="content"> |
| 1110 | <img src="./APL1.png" alt="APL1" /> |
| 1111 | </div> |
| 1112 | </div> |
| 1113 | <div class="paragraph"><p>The synchronization scheme above was designed such that as little interaction |
| 1114 | between threads is needed and heavier constructs like semaphores could be |
| 1115 | avoided.</p></div> |
| 1116 | </div> |
| 1117 | </div> |
| 1118 | <div class="sect1"> |
| 1119 | <h2 id="_notation">Notation</h2> |
| 1120 | <div class="sectionbody"> |
| 1121 | <div class="paragraph"><p>In the context of parallel execution, the prefix <strong>M_</strong> designates functions |
| 1122 | that are only called from the master thread, while the prefix <strong>PF_</strong> (for pool |
| 1123 | function) designates functions that are called from a worker thread.</p></div> |
| 1124 | <div class="paragraph"><p>Master functions only exist in class <strong>Thread_context</strong>, while pool functions |
| 1125 | exist in classes <strong>Thread_context</strong>, <strong>ScalarFunction</strong>, <strong>Bif_OPER2_INNER</strong>, and |
| 1126 | <strong>Bif_OPER2_OUTER</strong>. Note that the master thread itself acts like a worker |
| 1127 | thread after returning from <strong>M_fork()</strong> and before calling <strong>M_join()</strong>.</p></div> |
| 1128 | </div> |
| 1129 | </div> |
| 1130 | <div class="sect1"> |
| 1131 | <h2 id="_benchmarking_of_the_parallel_execution">Benchmarking of the Parallel Execution</h2> |
| 1132 | <div class="sectionbody"> |
| 1133 | <div class="sect2"> |
| 1134 | <h3 id="_the_theory_8230">The Theory …</h3> |
| 1135 | <div class="paragraph"><p>If a scalar APL function, is computed on a single core, then the time (most |
| 1136 | conveniently expressed in terms of CPU cycles) to compute it for an APL array |
| 1137 | with a ravel of length N is:</p></div> |
| 1138 | <div class="paragraph"><p>T<sub>seq</sub>(N) = ⍺<sub>seq</sub> + β<sub>seq</sub> × N.</p></div> |
| 1139 | <div class="paragraph"><p>In theory, the parallel computation of the same function on a number of cores |
| 1140 | requires time:</p></div> |
| 1141 | <div class="paragraph"><p>T<sub>par</sub>(N) = ⍺<sub>par</sub> + β<sub>par</sub> × N.</p></div> |
| 1142 | <div class="paragraph"><p>The terms ⍺<sub>seq</sub> and ⍺<sub>par</sub> are the start-up times for the computation, while |
| 1143 | the terms β<sub>seq</sub> and β<sub>par</sub> are the per-item times for the computation.</p></div> |
| 1144 | <div class="paragraph"><p>Under normal circumstance one has:</p></div> |
| 1145 | <div class="ulist"><ul> |
| 1146 | <li> |
| 1147 | <p> |
| 1148 | ⍺<sub>seq</sub> ≤ ⍺<sub>par</sub> |
| 1149 | </p> |
| 1150 | </li> |
| 1151 | <li> |
| 1152 | <p> |
| 1153 | β<sub>seq</sub> ≥ β<sub>par</sub> |
| 1154 | </p> |
| 1155 | </li> |
| 1156 | </ul></div> |
| 1157 | <div class="paragraph"><p>Under ideal circumstances one even has</p></div> |
| 1158 | <div class="paragraph"><p>β<sub>par</sub> = β<sub>seq</sub> ÷ C, or: β<sub>seq</sub> ÷ β<sub>par</sub> = C.</p></div> |
| 1159 | <div class="paragraph"><p>where C is the number of cores involved. The quotient <strong>β<sub>seq</sub> ÷ β<sub>par</sub></strong> is |
| 1160 | commonly known as the <strong>speed-up</strong> of the parallel execution. The difference |
| 1161 | ⍺<sub>par</sub> - ⍺<sub>seq</sub> is primarily caused by functions like M_fork(), PF_fork(), |
| 1162 | M_join() and PF_join() above, but also by the overhead caused by the |
| 1163 | joblist mechanism that is required to efficiently parallelize scalar |
| 1164 | operation on nested APL values.</p></div> |
| 1165 | <div class="paragraph"><p>The equations above can be used to compute a break-even length N<sub>BE</sub> so |
| 1166 | that:</p></div> |
| 1167 | <div class="ulist"><ul> |
| 1168 | <li> |
| 1169 | <p> |
| 1170 | T<sub>seq</sub>(N) < T<sub>par</sub>(N) for N < N<sub>BE</sub> |
| 1171 | </p> |
| 1172 | </li> |
| 1173 | <li> |
| 1174 | <p> |
| 1175 | T<sub>seq</sub>(N) > T<sub>par</sub>(N) for N > N<sub>BE</sub>. |
| 1176 | </p> |
| 1177 | </li> |
| 1178 | </ul></div> |
| 1179 | <div class="paragraph"><p>That simply means that the computation for arrays with a short ravel (i.e. of |
| 1180 | less than N<sub>BE</sub> items) it is faster to compute sequentially, while for longer |
| 1181 | ravels it is faster to compute in parallel.</p></div> |
| 1182 | <div class="paragraph"><p>The above formulae are easier to interpret if one plots the execution times |
| 1183 | (on the Y axis) vs. the vector length (on the X axis). For example, if</p></div> |
| 1184 | <div class="ulist"><ul> |
| 1185 | <li> |
| 1186 | <p> |
| 1187 | ⍺<sub>seq</sub> = 10, ⍺<sub>par</sub> = 10, i.e. T<sub>seq</sub>(N) = 10 + 10×N (green plot line) |
| 1188 | </p> |
| 1189 | </li> |
| 1190 | <li> |
| 1191 | <p> |
| 1192 | β<sub>seq</sub> = 30, β<sub>par</sub> = 5, i.e. T<sub>par</sub>(N) = 30 + 5 (red plot line) |
| 1193 | </p> |
| 1194 | </li> |
| 1195 | </ul></div> |
| 1196 | <div class="paragraph"><p>then the theory predicts the following execution times:</p></div> |
| 1197 | <div class="imageblock"> |
| 1198 | <div class="content"> |
| 1199 | <img src="./APL2.png" alt="APL2" /> |
| 1200 | </div> |
| 1201 | </div> |
| 1202 | <div class="paragraph"><p>As one can see, the intersection of the Y-axis (i.e. N=0) and the plot line |
| 1203 | T<sub>seq</sub>(N) and T<sub>par</sub>(N) is the start-up time ⍺<sub>seq</sub> and ⍺<sub>par</sub> respectively. |
| 1204 | The break-even length in this example is the intersection of the two plot |
| 1205 | lines at N=4.</p></div> |
| 1206 | </div> |
| 1207 | <div class="sect2"> |
| 1208 | <h3 id="_8230_and_the_practice">… and the Practice</h3> |
| 1209 | <div class="paragraph"><p>As <strong>Benjamin Brewster</strong> stated in 1882: <em>In theory there is no difference |
| 1210 | between theory and practice, while in practice there is</em>.</p></div> |
| 1211 | <div class="paragraph"><p>This statement is particularly true for benchmarking. Until about 1990, given |
| 1212 | some piece of assembler code, it was feasible (and was actually done) to |
| 1213 | compute the number of CPU cycles that the execution of that code would take.</p></div> |
| 1214 | <div class="paragraph"><p>Since then a number of optimizations, both in hardware and in software, have |
| 1215 | made it practically impossible to predict the execution time of any given code. |
| 1216 | Even worse, these days the same code, executed again and again, typically |
| 1217 | results in rather different cycle counts for each execution pass. Even if |
| 1218 | "no" other processes execute on the same CPU on which a benchmark measurement |
| 1219 | is performed (where "no other process" means not counting the typically 250 or |
| 1220 | so operating system processes that are sitting idle on the CPU) the results |
| 1221 | can differ substantially between different measurements of the same code.</p></div> |
| 1222 | <div class="paragraph"><p>So in practice, lets discuss the results of a benchmark:</p></div> |
| 1223 | <div class="imageblock"> |
| 1224 | <div class="content"> |
| 1225 | <img src="./APL3.png" alt="APL3" /> |
| 1226 | </div> |
| 1227 | </div> |
| 1228 | <div class="paragraph"><p>This benchmark measured the time to compute Z←¯6 ○ MixIRC for different vector |
| 1229 | lengths, ranging from N=200 to N=4000. MixIRC is a random mix of integer, |
| 1230 | real and complex arguments of ¯6○ aka. <strong>arccosh</strong>. The benchmark worked well in |
| 1231 | the sense that the measured numbers of CPU cycles were very much in line with |
| 1232 | the theory. The thick lines are those that have the smallest squared |
| 1233 | differences from the measurement points (the line that best matches the |
| 1234 | measurement points).</p></div> |
| 1235 | <div class="paragraph"><p>To be on the safe side, lets repeat <strong>the same</strong> benchmark:</p></div> |
| 1236 | <div class="imageblock"> |
| 1237 | <div class="content"> |
| 1238 | <img src="./APL4.png" alt="APL4" /> |
| 1239 | </div> |
| 1240 | </div> |
| 1241 | <div class="paragraph"><p>This one went less well. One difference from the previous one is that the |
| 1242 | deviations of the measurement points are considerably larger than in the |
| 1243 | previous run. If one runs the benchmark many times, then it looks like the |
| 1244 | deviations in the sequential execution are larger than in the parallel |
| 1245 | execution. More importantly, the sequential start-up time ⍺<sub>seq</sub> is now |
| 1246 | larger than the parallel start-up time ⍺<sub>par</sub>.</p></div> |
| 1247 | <div class="paragraph"><p>These two examples are only meant to highlight some the problems that may occur |
| 1248 | if one tries to determine the parameters ⍺ and β. The following is a summary |
| 1249 | of findings after having performed many such measurements with GNU APL and |
| 1250 | different core counts, vector lengths, and primitive functions:</p></div> |
| 1251 | <div class="ulist"><ul> |
| 1252 | <li> |
| 1253 | <p> |
| 1254 | every measurement needs to be visualized (plotted) to rule out too many |
| 1255 | or too large outliers. |
| 1256 | </p> |
| 1257 | </li> |
| 1258 | <li> |
| 1259 | <p> |
| 1260 | for determining the start-up costs ⍺<sub>seq</sub> and ⍺<sub>par</sub> it seems to be better |
| 1261 | to use fewer vector lengths and also shorter vectors. |
| 1262 | </p> |
| 1263 | </li> |
| 1264 | <li> |
| 1265 | <p> |
| 1266 | for determining the per-item costs β<sub>seq</sub> and β<sub>par</sub> it is better to |
| 1267 | use longer vectors. |
| 1268 | </p> |
| 1269 | </li> |
| 1270 | <li> |
| 1271 | <p> |
| 1272 | scalar functions with a low β (like A+B) tend to give more obscure results |
| 1273 | (and lower speed-ups) than scalar functions with a higher β. This is |
| 1274 | primarily caused by the fact that all cores share the same interface to the |
| 1275 | (shared) main memory of the machine. |
| 1276 | </p> |
| 1277 | </li> |
| 1278 | <li> |
| 1279 | <p> |
| 1280 | The speed-up of additional virtual cores (compared to physical ones) seems |
| 1281 | to be rather low. That is, for example, the speed-up of 12 virtual cores (on |
| 1282 | a hyper-threaded CPU with 6 physical cores) is only marginally higher than on |
| 1283 | 6 physical cores. GNU APL addresses this fact by distributing the load over |
| 1284 | the physical cores before placing hyper-threads on the physical cores. |
| 1285 | </p> |
| 1286 | </li> |
| 1287 | </ul></div> |
| 1288 | </div> |
| 1289 | <div class="sect2"> |
| 1290 | <h3 id="_the_benchmark_workspace_scalar2_apl">The Benchmark Workspace Scalar2.apl</h3> |
| 1291 | <div class="paragraph"><p>The workspace <strong>workspaces/Scalar2.apl</strong> can be used to measure the execution |
| 1292 | times of scalar functions. GNU APL provides a number of internal performance |
| 1293 | counters. These counters need to be enabled with |
| 1294 | <strong>PERFORMANCE_COUNTERS_WANTED=yes</strong> in <strong>./configure</strong>, and the CPU must have a |
| 1295 | cycle counter and an instruction to read it (currently only Intel CPUs can use |
| 1296 | this feature). The cycle counter of the CPU is read before and after the |
| 1297 | computation of a scalar function, and the difference can be read in APL via |
| 1298 | <strong>⎕FIO[200]</strong> and <strong>⎕FIO[201]</strong>. Measuring execution times this way is far more |
| 1299 | precise than old-fashioned measurements using ⎕TS at the APL level.</p></div> |
| 1300 | <div class="paragraph"><p>Scalar2.apl is most conveniently called from the command line, and what is |
| 1301 | being measured can be controlled via command line arguments. For example |
| 1302 | (from the top-level directory of GNU APL):</p></div> |
| 1303 | <div class="listingblock"> |
| 1304 | <div class="content"> |
| 1305 | <pre> |
| 1306 | |
| 1307 | <code>make parallel1 # runs ./configure with suitable options |
| 1308 | src/apl -f workspaces/Scalar2.apl -- -c 3,6 -d 200×⍳20</code> |
| 1309 | |
| 1310 | </pre> |
| 1311 | </div></div> |
| 1312 | <div class="paragraph"><p>The <strong>Scalar2.apl</strong> workspace understands the following command line options:</p></div> |
| 1313 | <div class="tableblock"> |
| 1314 | <table rules="all" |
| 1315 | width="75%" |
| 1316 | frame="border" |
| 1317 | cellspacing="0" cellpadding="4"> |
| 1318 | <caption class="title">Table 1. Table Scalar2.apl command line options (after --)</caption> |
| 1319 | <col width="25%" /> |
| 1320 | <col width="41%" /> |
| 1321 | <col width="16%" /> |
| 1322 | <col width="16%" /> |
| 1323 | <thead> |
| 1324 | <tr> |
| 1325 | <th align="left" valign="top">Option </th> |
| 1326 | <th align="left" valign="top">Effect </th> |
| 1327 | <th align="center" valign="top">Example </th> |
| 1328 | <th align="center" valign="top">Default</th> |
| 1329 | </tr> |
| 1330 | </thead> |
| 1331 | <tbody> |
| 1332 | <tr> |
| 1333 | <td align="left" valign="top"><p class="table">-c core-counts</p></td> |
| 1334 | <td align="left" valign="top"><p class="table">set the number of cores</p></td> |
| 1335 | <td align="center" valign="top"><p class="table">-c 2,3</p></td> |
| 1336 | <td align="center" valign="top"><p class="table">2</p></td> |
| 1337 | </tr> |
| 1338 | <tr> |
| 1339 | <td align="left" valign="top"><p class="table">-d vector-lengths</p></td> |
| 1340 | <td align="left" valign="top"><p class="table">set the vector lengths (N-axis)</p></td> |
| 1341 | <td align="center" valign="top"><p class="table">-d 200×⍳2</p></td> |
| 1342 | <td align="center" valign="top"><p class="table">⍳20</p></td> |
| 1343 | </tr> |
| 1344 | <tr> |
| 1345 | <td align="left" valign="top"><p class="table">-f function</p></td> |
| 1346 | <td align="left" valign="top"><p class="table">select the function to measure</p></td> |
| 1347 | <td align="center" valign="top"><p class="table">-f 20</p></td> |
| 1348 | <td align="center" valign="top"><p class="table">39</p></td> |
| 1349 | </tr> |
| 1350 | </tbody> |
| 1351 | </table> |
| 1352 | </div> |
| 1353 | <div class="paragraph"><p>For every core count, <strong>Scalar2.apl</strong> displays a separate plot window with the |
| 1354 | measurement results for sequential execution and for the parallel execution |
| 1355 | with the given core count.</p></div> |
| 1356 | </div> |
| 1357 | </div> |
| 1358 | </div> |
| 1359 | <div class="sect1"> |
| 1360 | <h2 id="_recursive_parallelization">Recursive Parallelization</h2> |
| 1361 | <div class="sectionbody"> |
| 1362 | <div class="paragraph"><p>The purpose of the joblist mentioned above is as follows. Consider the |
| 1363 | APL expression below, computed in parallel on 4 cores:</p></div> |
| 1364 | <div class="listingblock"> |
| 1365 | <div class="content"> |
| 1366 | <pre> |
| 1367 | |
| 1368 | <code>Z←1 2 (⍳1000) 4 + 1 (20 21 22) 3 4</code> |
| 1369 | |
| 1370 | </pre> |
| 1371 | </div></div> |
| 1372 | <div class="paragraph"><p>The 4 ravel elements of the left and right arguments of dyadic + are stored in |
| 1373 | 4 consecutive Cells, which are distributed in a round-robin fashion over the |
| 1374 | cores. That is:</p></div> |
| 1375 | <div class="listingblock"> |
| 1376 | <div class="content"> |
| 1377 | <pre> |
| 1378 | |
| 1379 | <code>Core #1 computes: 1 + 1 (1 addition) |
| 1380 | Core #2 computes: 2 + 20 21 22 (3 additions) |
| 1381 | Core #3 computes: (⍳1000) + 3 (1000 additions) |
| 1382 | Core #4 computes: 4 + 4 (1 addition)</code> |
| 1383 | |
| 1384 | </pre> |
| 1385 | </div></div> |
| 1386 | <div class="paragraph"><p>Therefore cores #1 and #4 compute one sum, core #2 computes 3 sums, and |
| 1387 | core #3 computes 1000 sums. This is obviously not optimal since cores #1, #2, |
| 1388 | and #3 are most of the time idle, waiting for core #3 to finish.</p></div> |
| 1389 | <div class="paragraph"><p>To avoid this case, GNU APL parallelizes scalar functions recursively with the |
| 1390 | following algorithm.</p></div> |
| 1391 | <div class="olist arabic"><ol class="arabic"> |
| 1392 | <li> |
| 1393 | <p> |
| 1394 | the interpreter starts with an empty joblist. |
| 1395 | </p> |
| 1396 | </li> |
| 1397 | <li> |
| 1398 | <p> |
| 1399 | when the interpreter evaluates a scalar function, then it puts a new job |
| 1400 | into the joblist. The job describes the relevant parameters (essentially |
| 1401 | the scalar function to be computed and the address(es) of its argument(s). |
| 1402 | </p> |
| 1403 | </li> |
| 1404 | <li> |
| 1405 | <p> |
| 1406 | LOOP: while the joblist is not empty: |
| 1407 | </p> |
| 1408 | <div class="olist loweralpha"><ol class="loweralpha"> |
| 1409 | <li> |
| 1410 | <p> |
| 1411 | remove the first job from the list |
| 1412 | </p> |
| 1413 | </li> |
| 1414 | <li> |
| 1415 | <p> |
| 1416 | perform the computation defined in the job in parallel |
| 1417 | </p> |
| 1418 | </li> |
| 1419 | <li> |
| 1420 | <p> |
| 1421 | if a core comes across a nested ravel item, then: |
| 1422 | </p> |
| 1423 | <div class="ulist"><ul> |
| 1424 | <li> |
| 1425 | <p> |
| 1426 | if the item (and hence the result) is small: compute it immediately |
| 1427 | </p> |
| 1428 | </li> |
| 1429 | <li> |
| 1430 | <p> |
| 1431 | if the item is large: create a new APL value whose ravel is un-initialized |
| 1432 | (this operation takes constant time) and add a new entry into the joblist |
| 1433 | (for computing the ravel of the nested result later on). |
| 1434 | </p> |
| 1435 | </li> |
| 1436 | </ul></div> |
| 1437 | </li> |
| 1438 | </ol></div> |
| 1439 | </li> |
| 1440 | </ol></div> |
| 1441 | <div class="paragraph"><p>For performance reasons, there are actually two such joblists: |
| 1442 | <strong>Thread_context::joblist_B</strong> for monadic scalar functions, and |
| 1443 | <strong>Thread_context::joblist_AB</strong> for dyadic scalar functions (and |
| 1444 | inner and outer products of them).</p></div> |
| 1445 | </div> |
| 1446 | </div> |
| 1447 | <div class="sect1"> |
| 1448 | <h2 id="_setting_thresholds">Setting Thresholds</h2> |
| 1449 | <div class="sectionbody"> |
| 1450 | <div class="paragraph"><p>One purpose of benchmarking is to find the break-even lengths for |
| 1451 | scalar functions. After that length is found, one can inform the APL |
| 1452 | interpreter about the break-even lengths. This is done via a configuration |
| 1453 | file, normally <strong>/usr/local/etc/gnu-apl.d/parallel_thresholds</strong>.</p></div> |
| 1454 | <div class="paragraph"><p>This file is installed by <em>make install</em>, but the values in the file |
| 1455 | are usually not optimal. One can, however, enter better values manually. |
| 1456 | Consider a few non-empty lines in the file:</p></div> |
| 1457 | <div class="listingblock"> |
| 1458 | <div class="content"> |
| 1459 | <pre> |
| 1460 | |
| 1461 | <code>perfo_1(F12_PLUS, _B, "+ B", 8888888888888888888ULL) |
| 1462 | perfo_1(F12_POWER, _B, "⋆ B", 12 ) |
| 1463 | perfo_2(F12_TIMES, _AB, "A × B", 33 )</code> |
| 1464 | |
| 1465 | </pre> |
| 1466 | </div></div> |
| 1467 | <div class="paragraph"><p>The first line above sets the break-even point of <strong>monadic +</strong> to |
| 1468 | 8888888888888888888ULL, which is a value so large that parallel execution will |
| 1469 | never happen for monadic +.</p></div> |
| 1470 | <div class="paragraph"><p>The second line sets the break-even point of <strong>monadic *</strong> to 12. Arrays (of any |
| 1471 | rank) with fewer than 12 ravel items will be computed sequentially, but longer |
| 1472 | arrays in parallel.</p></div> |
| 1473 | <div class="paragraph"><p>The third line sets the break-even point of <strong>dyadic ×</strong> to 33. Arrays (of any |
| 1474 | rank) with fewer than 33 ravel items will be computed sequentially, but longer |
| 1475 | arrays in parallel.</p></div> |
| 1476 | <div class="paragraph"><p>In general, the fewer cycles a function needs, the higher should the threshold |
| 1477 | be set.</p></div> |
| 1478 | </div> |
| 1479 | </div> |
| 1480 | <div class="sect1"> |
| 1481 | <h2 id="_the_optimal_vs_the_maximal_core_count">The Optimal vs. the Maximal Core Count</h2> |
| 1482 | <div class="sectionbody"> |
| 1483 | <div class="paragraph"><p>The last plot window shown by the <strong>Scalar2</strong> workspace summarizes the speed-ups |
| 1484 | that were achieved for the different core counts that were selected with the |
| 1485 | -c option.</p></div> |
| 1486 | <div class="imageblock"> |
| 1487 | <div class="content"> |
| 1488 | <img src="./APL5.png" alt="APL5" /> |
| 1489 | </div> |
| 1490 | </div> |
| 1491 | <div class="admonitionblock"> |
| 1492 | <table><tr> |
| 1493 | <td class="icon"> |
| 1494 | <img src="/usr/share/asciidoc/icons/note.png" alt="Note" /> |
| 1495 | </td> |
| 1496 | <td class="content">leave at least one of the available cores unused because otherwise the |
| 1497 | operating system could grab one of the cores for its own purposes and that |
| 1498 | core would then become much slower than the others. The operating system is |
| 1499 | usually smart enough to locate an unused core for its own purposes, but that |
| 1500 | must fail if all cores are fully loaded with APL work.</td> |
| 1501 | </tr></table> |
| 1502 | </div> |
| 1503 | <div class="paragraph"><p>The speed-ups plotted in the last window are usually reasonable if:</p></div> |
| 1504 | <div class="ulist"><ul> |
| 1505 | <li> |
| 1506 | <p> |
| 1507 | the APL function that is being bench-marked (as selected by the -f option) |
| 1508 | is not too lightweight, and |
| 1509 | </p> |
| 1510 | </li> |
| 1511 | <li> |
| 1512 | <p> |
| 1513 | the vector lengths (-d option) are not too short. |
| 1514 | </p> |
| 1515 | </li> |
| 1516 | </ul></div> |
| 1517 | <div class="paragraph"><p>The measurement shown above was executed on a 6-core i7-8700 CPU. The CPU has |
| 1518 | 6 (physical) cores with 12 (logical) core threads where the 12 core threads |
| 1519 | are mapped to 12 "CPUs" in the operating system as (per <strong>/proc/cpuinfo</strong>).</p></div> |
| 1520 | <div class="paragraph"><p>The benchmark command used was:</p></div> |
| 1521 | <div class="listingblock"> |
| 1522 | <div class="content"> |
| 1523 | <pre> |
| 1524 | |
| 1525 | <code>src/apl -f workspaces/Scalar2.apl -- -c ⍳11 -d 5000×⍳20 -f 39</code> |
| 1526 | |
| 1527 | </pre> |
| 1528 | </div></div> |
| 1529 | <div class="paragraph"><p>which means that:</p></div> |
| 1530 | <div class="ulist"><ul> |
| 1531 | <li> |
| 1532 | <p> |
| 1533 | <strong>-f 39</strong> : selects <strong>Z←¯6○B</strong> aka. <strong>arccosh(B)</strong> as the benchmarking function |
| 1534 | with a mix of Integer, Real, and Complex numbers, |
| 1535 | </p> |
| 1536 | </li> |
| 1537 | <li> |
| 1538 | <p> |
| 1539 | <strong>-d 5000×⍳20</strong> : use vector lengths ⍴B = 5,000, 10,000, 15,000 … 100,000, and |
| 1540 | </p> |
| 1541 | </li> |
| 1542 | <li> |
| 1543 | <p> |
| 1544 | <strong>-c ⍳11</strong> : use core counts of 1, 2, 3, … and 11. |
| 1545 | </p> |
| 1546 | </li> |
| 1547 | </ul></div> |
| 1548 | <div class="paragraph"><p>The 11 different core counts and 20 different vector lengths above |
| 1549 | amounted to a total of 220 (= 11×20) individual measurements in the benchmark |
| 1550 | plotted above.</p></div> |
| 1551 | <div class="paragraph"><p>Had we run the benchmark with <strong>-c ⍳12</strong> instead of <strong>-c ⍳11</strong> then the |
| 1552 | measurement with 12 cores would have shown a rather bad speed-up (try it |
| 1553 | yourself with <strong>-c</strong> set to the number of cores on your computer).</p></div> |
| 1554 | <div class="paragraph"><p><strong>Corollary:</strong> the optimal performance is achieved when the number of cores used |
| 1555 | for parallel APL is slightly smaller than the number of cores available. The |
| 1556 | number of cores available is also influenced by other (even idle) processes on |
| 1557 | the machine because they also influence the scheduling of the threads that |
| 1558 | perform the APL work.</p></div> |
| 1559 | </div> |
| 1560 | </div> |
| 1561 | </div> |
| 1562 | <div id="footnotes"><hr /></div> |
| 1563 | <div id="footer"> |
| 1564 | <div id="footer-text"> |
| 1565 | Last updated |
| 1566 | 2024-03-14 14:48:59 CET |
| 1567 | </div> |
| 1568 | </div> |
| 1569 | </body> |
| 1570 | </html> |