1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413
|
/***** spin: pangen7.h *****/
/*
* This file is part of the public release of Spin. It is subject to the
* terms in the LICENSE file that is included in this source directory.
* Tool documentation is available at http://spinroot.com
*/
static const char *pan_par[] = { /* generates pan.p */
"#include <sys/ipc.h>",
"#include <sys/shm.h>",
"#include <time.h>", /* for nanosleep */
"#include <assert.h>",
"#include <limits.h>",
"#ifdef BFS_DISK",
"#include <unistd.h>", /* for rmdir */
"#include <sys/stat.h>", /* for mkdir */
"#include <sys/types.h>",
"#include <fcntl.h>", /* for open */
"#endif",
"",
"#define Max(a,b) (((a)>(b))?(a):(b))",
"#ifndef WAIT_MAX",
" #define WAIT_MAX 2 /* seconds */",
"#endif",
"#define BFS_GEN 2 /* current and next generation */",
"",
"typedef struct BFS_Slot BFS_Slot;",
"typedef struct BFS_shared BFS_shared;",
"typedef struct BFS_data BFS_data;",
"",
"struct BFS_Slot {",
" #ifdef BFS_FIFO",
" enum bfs_types type; /* message type */",
" #endif",
" BFS_State *s_data; /* state data */",
" #ifndef BFS_QSZ",
" BFS_Slot *nxt; /* linked list */",
" #endif",
"};",
"",
"struct BFS_data {",
" double memcnt;",
" double nstates;",
" double nlinks;",
" double truncs;",
" ulong mreached;",
" ulong vsize;",
" ulong memory_left;",
" ulong punted;",
" ulong errors;",
" int override; /* after crash, if another proc clears locks */",
"};",
"",
"struct BFS_shared { /* about 13K for BFS_MAXPROCS=16 and BFS_MAXLOCKS=1028 */",
" volatile ulong quit; /* set to signal termination -- one word */",
" volatile ulong started;",
"",
" volatile uchar sh_owner[BFS_MAXLOCKS]; /* optional */",
"#ifdef BFS_CHECK",
" volatile uchar in_count[BFS_MAXLOCKS]; /* optional */",
"#endif",
" volatile int sh_locks[BFS_MAXLOCKS];",
" volatile ulong wait_count[BFS_MAXLOCKS]; /* optional */",
"",
" volatile BFS_data bfs_data[BFS_MAXPROCS];",
" volatile uchar bfs_flag[BFS_MAXPROCS]; /* running 0, normal exit 1, abnormal 2 */",
" volatile uchar bfs_idle[BFS_MAXPROCS]; /* set when all input queues are empty */",
"#ifdef BFS_DISK",
" volatile uchar bfs_out_cnt[BFS_MAXPROCS]; /* set when core writes a state */",
"#endif",
"",
"#ifdef BFS_QSZ",
" #define BFS_NORECYCLE",
" #if BFS_QSZ<=0",
" #error BFS_QSZ must be positive",
" #endif",
" #ifdef BFS_FIFO",
" #error BFS_QSZ cannot be combined with BFS_FIFO",
" #endif",
" #ifdef BFS_DISK",
" #error BFS_QSZ cannot be combined with BFS_DISK",
" #endif",
" volatile BFS_Slot bfsq[BFS_GEN][BFS_MAXPROCS][BFS_MAXPROCS][BFS_QSZ];",
" volatile uint bfs_ix[BFS_GEN][BFS_MAXPROCS][BFS_MAXPROCS];",
"#else",
" volatile BFS_Slot *head[BFS_GEN][BFS_MAXPROCS][BFS_MAXPROCS];",
"#endif",
"",
"#ifdef BFS_FIFO",
" volatile BFS_Slot *tail[BFS_GEN][BFS_MAXPROCS][BFS_MAXPROCS];",
" volatile BFS_Slot *dels[BFS_GEN][BFS_MAXPROCS][BFS_MAXPROCS];",
"#endif",
"#ifdef BFS_LOGMEM",
" volatile ulong logmem[1024];",
"#endif",
" volatile ulong mem_left;",
" volatile uchar *allocator; /* start of shared heap, must be last */",
"};",
"",
"enum bfs_types { EMPTY = 0, STATE, DELETED };",
"",
"extern volatile uchar *bfs_get_shared_mem(key_t, size_t);",
"extern BFS_Slot * bfs_new_slot(BFS_Trail *);",
"extern BFS_Slot * bfs_prep_slot(BFS_Trail *, BFS_Slot *);",
"extern BFS_Slot * bfs_next(void);",
"extern BFS_Slot * bfs_pack_state(Trail *, BFS_Trail *, int, BFS_Slot *);",
"extern SV_Hold * bfs_new_sv(int);",
"#if NRUNS>0",
"extern EV_Hold * bfs_new_sv_mask(int);",
"#endif",
"extern BFS_Trail * bfs_grab_trail(void);",
"extern BFS_Trail * bfs_unpack_state(BFS_Slot *);",
"extern int bfs_all_empty(void);",
"extern int bfs_all_idle(void);",
"extern int bfs_all_running(void);",
"extern int bfs_idle_and_empty(void);",
"extern size_t bfs_find_largest(key_t);",
"",
"extern void bfs_clear_locks(void);",
"extern void bfs_drop_shared_memory(void);",
"extern void bfs_explore_state(BFS_Slot *);",
"extern void bfs_initial_state(void);",
"extern void bfs_mark_done(int);",
"extern void bfs_printf(const char *fmt, ...);",
"extern void bfs_push_state(Trail *, BFS_Trail *, int);",
"extern void bfs_recycle(BFS_Slot *);",
"extern void bfs_release_trail(BFS_Trail *);",
"extern void bfs_run(void);",
"extern void bfs_setup_mem(void);",
"extern void bfs_setup(void);",
"extern void bfs_shutdown(const char *);",
"extern void bfs_statistics(void);",
"extern void bfs_store_state(Trail *, short);",
"extern void bfs_set_toggle(void);",
"extern void bfs_update(void);",
"",
"#ifdef MA",
" #error cannot combine -DMA with -DBFS_PAR",
" /* would require us to parallelize g_store */",
"#endif",
"#ifdef BCS",
" #error cannot combine -DBCS with -DBFS_PAR",
"#endif",
"#ifdef BFS_DISK",
" #ifdef BFS_FIFO",
" #error cannot combine BFS_DISK and BFS_FIFO",
" #endif",
" extern void bfs_disk_start(void);",
" extern void bfs_disk_stop(void);",
" extern void bfs_disk_out(void);",
" extern void bfs_disk_inp(void);",
" extern void bfs_disk_iclose(void);",
" extern void bfs_disk_oclose(void);",
" int bfs_out_fd[BFS_MAXPROCS];",
" int bfs_inp_fd[BFS_MAXPROCS];",
"#endif",
"",
"static BFS_shared *shared_memory;",
"#ifndef BFS_QSZ",
"static BFS_Slot *bfs_free_slot; /* local free list */",
"#endif",
"static BFS_Slot bfs_null;",
"static SV_Hold *bfs_svfree[VECTORSZ];",
"static uchar *bfs_heap; /* local pointer into heap */",
"static ulong bfs_left; /* local part of shared heap */",
"#if NRUNS>0",
"static void bfs_keep(EV_Hold *);",
"#endif",
"static long bfs_sent; /* nr msgs sent -- local to each process */",
"static long bfs_rcvd; /* nr msgs rcvd */",
"static long bfs_sleep_cnt; /* stats */",
"static long bfs_wcount;",
"static long bfs_gcount;",
"static ulong bfs_total_shared;",
"#ifdef BFS_STAGGER",
" static int bfs_stage_cnt = 0;",
" static void bfs_stagger_flush(void);",
"#endif",
"static int bfs_toggle; /* local variable, 0 or 1 */",
"static int bfs_qscan; /* scan input queues in order */",
"static ulong bfs_snapped;",
"static int shared_mem_id;",
"#ifndef NOREDUCE",
"static int bfs_nps; /* no preselection */",
"#endif",
"ulong bfs_punt; /* states dropped for lack of memory */",
"#if defined(VERBOSE) || defined(BFS_CHECK)",
"static const char *bfs_sname[] = {",
" \"EMPTY\", /* 0 */",
" \"STATE\", /* 1 */",
" \"STATE\", /* 2 = DELETED */",
" 0",
"};",
"#endif",
"static const char *bfs_lname[] = { /* match values defined in pangen2.c */",
" \"global lock\", /* BFS_GLOB */",
" \"ordinal\", /* BFS_ORD */",
" \"shared memory\", /* BFS_MEM */",
" \"print to stdout\", /* BFS_PRINT */",
" \"hashtable\", /* BFS_STATE */",
" 0",
"};",
"",
"static ulong bfs_count[DELETED+1]; /* indexed with bfs_types: EMPTY=0, STATE=1, DELETED=2 */",
"",
"static int bfs_keep_state;",
"",
"int Cores = 1;",
"int who_am_i = 0; /* root */",
"",
"#ifdef L_BOUND",
" int L_bound = L_BOUND;",
"#endif",
"",
"#ifdef BFS_CHECK",
"void",
"bfs_dump_now(char *s)",
"{ int i; char *p = (char *) &now;",
"",
" e_critical(BFS_PRINT);",
" printf(\"%%s\\t\", s);",
" printf(\"%%3lu: \", vsize);",
" for (i = 0; i < vsize; i++)",
" { printf(\"%%3d \", *p++);",
" }",
" printf(\" %%s\\noffsets:\\t\", s);",
" for (i = 0; i < now._nr_pr; i++)",
" { printf(\"%%3d \", proc_offset[i]);",
" }",
" printf(\"\\n\");",
" x_critical(BFS_PRINT);",
"}",
"",
"void",
"view_state(char *s) /* debugging */",
"{ int i;",
" char *p;",
" e_critical(BFS_PRINT);",
" printf(\"cpu%%02d %%s: \", who_am_i, s);",
" p = (char *)&now;",
" for (i = 0; i < vsize; i++)",
" printf(\"%%3d, \", *p++);",
" printf(\"\\n\"); fflush(stdout);",
" x_critical(BFS_PRINT);",
"}",
"#endif",
"",
"void",
"bfs_main(int ncores, int cycles)",
"{",
" if (cycles)",
" { fprintf(stderr, \"pan: cycle detection is not supported in this mode\\n\");",
" exit(1);",
" }",
"",
" if (ncores == 0) /* i.e., find out */",
" { FILE *fd;",
" char buf[512];",
" if ((fd = fopen(\"/proc/cpuinfo\", \"r\")) == NULL)",
" { /* cannot tell */",
" ncores = Cores; /* use the default */",
" } else",
" { while (fgets(buf, sizeof(buf), fd))",
" { if (strncmp(buf, \"processor\", strlen(\"processor\")) == 0)",
" { ncores++;",
" } }",
" fclose(fd);",
" ncores--;",
" if (verbose)",
" { printf(\"pan: %%d available cores\\n\", ncores+1);",
" } } }",
" if (ncores >= BFS_MAXPROCS)",
" { Cores = BFS_MAXPROCS-1; /* why -1? */",
" } else if (ncores < 1)",
" { Cores = 1;",
" } else",
" { Cores = ncores;",
" }",
" printf(\"pan: using %%d core%%s\\n\", Cores, (Cores>1)?\"s\":\"\");",
" fflush(stdout);",
"#ifdef BFS_DISK",
" bfs_disk_start();", /* create .spin */
"#endif",
" bfs_setup(); /* shared memory segments and fork */",
" bfs_run();",
" if (who_am_i == 0)",
" { stop_timer(0);",
" }",
" bfs_statistics();",
" bfs_mark_done(1);",
" if (who_am_i == 0)",
" { report_time();",
"#ifdef BFS_DISK",
" bfs_disk_stop();",
"#endif",
" }",
"#ifdef C_EXIT",
" C_EXIT; /* trust that it defines a fct */",
"#endif",
" bfs_drop_shared_memory();",
" exit(0);",
"}",
"",
"void",
"bfs_setup_mem(void)",
"{ size_t n;",
" key_t key;",
"#ifdef BFS_FIFO",
" bfs_null.type = EMPTY;",
"#endif",
" ntrpt = (Trail *) emalloc(sizeof(Trail));", /* just once */
"",
" if ((key = ftok(\".\", (int) 'L')) == -1)",
" { perror(\"ftok shared memory\");",
" exit(1);",
" }",
" n = bfs_find_largest(key);",
" bfs_total_shared = (ulong) n;",
"",
" shared_memory = (BFS_shared *) bfs_get_shared_mem(key, n); /* root */",
" shared_memory->allocator = (uchar *) shared_memory + sizeof(BFS_shared);",
" shared_memory->mem_left = (ulong) (n - sizeof(BFS_shared));",
"}",
"",
"ulong bfs_LowLim;",
"#ifndef BFS_RESERVE",
" #define BFS_RESERVE 5",
/* keep memory on global heap in reserve for first few cores */
/* that run out of their local allocation of shared mem */
/* 1~50 percent, 2~30 percent, 5~20 percent, >Cores=none */
"#else",
" #if BFS_RESERVE<1",
" #error BFS_RESERVE must be at least 1",
" #endif",
"#endif",
"",
"void",
"bfs_setup(void) /* executed by root */",
"{ int i, j;",
" ulong n; /* share of shared memory allocated to each core */",
"",
" n = shared_memory->mem_left / (Cores + Cores/(BFS_RESERVE)); /* keep some reserve */",
"",
" if ((n%%sizeof(void *)) != 0)",
" { n -= (n%%sizeof(void *)); /* align, without exceeding total */",
" }",
" for (i = 0; i < Cores-1; i++)",
" { j = fork();",
" if (j == -1)",
" { bfs_printf(\"fork failed\\n\");",
" exit(1);",
" }",
" if (j == 0)",
" { who_am_i = i+1; /* 1..Cores-1 */",
" break;",
" } }",
"",
" e_critical(BFS_MEM);",
" bfs_heap = (uchar *) shared_memory->allocator;",
" shared_memory->allocator += n;",
" shared_memory->mem_left -= n;",
" x_critical(BFS_MEM);",
"",
" bfs_left = n;",
" bfs_runs = 1;",
" bfs_LowLim = n / (2 * (ulong) Cores);", /* 50% */
"}",
"",
"void",
"bfs_run(void)",
"{ BFS_Slot *v;",
"",
"#ifdef BFS_DISK",
" bfs_disk_out();", /* create outqs */
"#endif",
" if (who_am_i == 0)",
" { bfs_initial_state();",
" }",
"#ifdef BFS_DISK",
" #ifdef BFS_STAGGER",
" bfs_stagger_flush();",
" #endif",
" bfs_disk_oclose();", /* sync and close outqs */
"#endif",
"#ifdef BFS_FIFO",
" static int i_count;",
"#endif",
"",
" srand(s_rand+HASH_NR);",
" bfs_qscan = 0;",
" bfs_toggle = 1 - bfs_toggle; /* after initial state */",
" e_critical(BFS_GLOB);",
" shared_memory->started++;",
" x_critical(BFS_GLOB);",
"",
" while (shared_memory->started != Cores) /* wait for all cores to connect */",
" { usleep(1);",
" }",
"",
"#ifdef BFS_DISK",
" bfs_disk_out();",
" bfs_disk_inp();",
"#endif",
"",
" start_timer();",
" while (shared_memory->quit == 0)",
" { v = bfs_next(); /* get next message from current generation */",
" if (v->s_data) /* v->type == STATE || v->type == DELETED */",
" { bfs_count[STATE]++;",
"#ifdef VERBOSE",
" bfs_printf(\"GOT STATE (depth %%d, nr %%u)\\n\",",
" v->s_data->t_info->o_tt, v->s_data->nr);",
"#endif",
" /* last resort: start dropping states when out of memory */",
" if (bfs_left > 1024 || shared_memory->mem_left > 1024)",
" { bfs_explore_state(v);",
" } else",
" { static int warned_loss = 0;",
" if (warned_loss == 0 && who_am_i == 0)",
" { warned_loss++;",
" bfs_printf(\"out of shared memory - losing states\\n\");",
" }",
" bfs_punt++;",
" }",
"#if !defined(BFS_FIFO) && !defined(BFS_NORECYCLE)",
" bfs_recycle(v);",
"#endif",
"#ifdef BFS_FIFO",
" i_count = 0;",
"#endif",
" } else",
" { bfs_count[EMPTY]++;",
"#if defined(BFS_FIFO) && defined(BFS_CHECK)",
" assert(v->type == EMPTY);",
"#endif",
"#ifdef BFS_FIFO",
" if (who_am_i == 0)",
" { if (bfs_idle_and_empty())",
" { if (i_count++ > 10)",
" { shared_memory->quit = 1;",
" }",
" else usleep(1);",
" }",
" } else if (!bfs_all_running())",
" { bfs_shutdown(\"early termination\");",
" }",
"#else",
" if (who_am_i == 0)",
" { if (bfs_all_idle()) /* wait for it */",
" { if (!bfs_all_empty()) /* more states to process */",
" { bfs_set_toggle();",
" goto do_toggle;",
" } else /* done */",
" { shared_memory->quit = 1; /* step 4 */",
" }",
" } else",
" { bfs_sleep_cnt++;",
" }",
" } else",
" { /* wait for quit or idle bit to be reset by root */",
" while (shared_memory->bfs_idle[who_am_i] == 1",
" && shared_memory->quit == 0)",
" { if (bfs_all_running())",
" { bfs_sleep_cnt++;",
" usleep(10); /* new 6.2.3 */",
" } else",
" { bfs_shutdown(\"early termination\");",
" /* no return */",
" } }",
"do_toggle: bfs_qscan = 0;",
"#ifdef BFS_DISK",
" bfs_disk_iclose();",
" bfs_disk_oclose();",
"#endif",
" bfs_toggle = 1 - bfs_toggle;",
"#ifdef BFS_DISK",
" bfs_disk_out();",
" bfs_disk_inp();",
"#endif",
" #ifdef BFS_CHECK",
" bfs_printf(\"toggle: recv from %%d, send to %%d\\n\",",
" bfs_toggle, 1 - bfs_toggle);",
" #endif",
" }",
"#endif",
" } }",
"#ifdef BFS_CHECK",
" bfs_printf(\"done, sent %%5ld recvd %%5ld punt %%5lu sleep: %%ld\\n\",",
" bfs_sent, bfs_rcvd, bfs_punt, bfs_sleep_cnt);",
"#endif",
"}",
"",
"void",
"bfs_report_mem(void) /* called from within wrapup() */",
"{",
" printf(\"%%9.3f total shared memory usage\\n\\n\",",
" ((double) bfs_total_shared - (double) bfs_left)/(1024.*1024.));",
"}",
"",
"void",
"bfs_statistics(void)",
"{",
" #ifdef VERBOSE",
" enum bfs_types i;",
" #endif",
" if (verbose)",
" bfs_printf(\"states sent %%7ld recvd %%7ld stored %%8g sleeps: %%4ld, %%4ld, %%ld\\n\",",
" bfs_sent, bfs_rcvd, nstates, bfs_wcount, bfs_gcount, bfs_sleep_cnt);",
" if (0) bfs_printf(\"states punted %%7lu\\n\", bfs_punt);",
" #ifdef VERBOSE",
" for (i = EMPTY; i <= DELETED; i++)",
" { if (bfs_count[i] > 0)",
" { bfs_printf(\"%%6s %%8lu\\n\",",
" bfs_sname[i], bfs_count[i]);",
" } }",
" #endif",
" bfs_update();",
"",
" if (who_am_i == 0 && shared_memory)",
" { int i; ulong count = 0L;",
" done = 1;",
"",
" e_critical(BFS_PRINT);",
" wrapup();",
" if (verbose)",
" { printf(\"\\nlock-wait counts:\\n\");",
" for (i = 0; i < BFS_STATE; i++)",
" printf(\"%%16s %%9lu\\n\",",
" bfs_lname[i], shared_memory->wait_count[i]);",
"#ifndef BITSTATE",
" for (i = BFS_STATE; i < BFS_MAXLOCKS; i++)",
" { if (0)",
" printf(\" [%%6d] %%9lu\\n\",",
" i, shared_memory->wait_count[i]);",
" count += shared_memory->wait_count[i];",
" }",
" printf(\"%%16s %%9lu (avg per region)\\n\",",
" bfs_lname[BFS_STATE], count/(BFS_MAXLOCKS - BFS_STATE));",
"#endif",
" }",
" fflush(stdout);",
" x_critical(BFS_PRINT);",
" }",
"}",
"",
"void",
"bfs_snapshot(void)",
"{ clock_t stop_time;",
" double delta_time;",
" struct tms stop_tm;",
" volatile BFS_data *s;",
"",
" e_critical(BFS_PRINT);",
" printf(\"cpu%%02d Depth= %%7lu States= %%8.3g Transitions= %%8.3g \",",
" who_am_i, mreached, nstates, nstates+truncs);",
" printf(\"Memory= %%9.3f\\t\", memcnt/1048576.);",
" printf(\"SharedMLeft= %%4lu \", bfs_left/1048576);",
" stop_time = times(&stop_tm);",
" delta_time = ((double) (stop_time - start_time))/((double) sysconf(_SC_CLK_TCK));",
" if (delta_time > 0.01)",
" { printf(\"t= %%6.3g R= %%6.0g\\n\", delta_time, nstates/delta_time);",
" } else",
" { printf(\"t= %%6.3g R= %%6.0g\\n\", 0., 0.);",
" }",
" fflush(stdout);",
" x_critical(BFS_PRINT);",
"",
" s = &shared_memory->bfs_data[who_am_i];",
" s->mreached = (ulong) mreached;",
" s->vsize = (ulong) vsize;",
" s->errors = (int) errors;",
" s->memcnt = (double) memcnt;",
" s->nstates = (double) nstates;",
" s->nlinks = (double) nlinks;",
" s->truncs = (double) truncs;",
" s->memory_left = (ulong) bfs_left;",
" s->punted = (ulong) bfs_punt;",
" bfs_snapped++; /* for bfs_best */",
"}",
"",
"void",
"bfs_shutdown(const char *s)",
"{",
" bfs_clear_locks(); /* in case we interrupted at a bad point */",
" if (!strstr(s, \"early \") || verbose)",
" { bfs_printf(\"stop (%%s)\\n\", s);",
" }",
" bfs_update();",
" if (who_am_i == 0)",
" { wrapup();",
"#ifdef BFS_DISK",
" bfs_disk_stop();",
"#endif",
" }",
" bfs_mark_done(2);",
" pan_exit(2);",
"}",
"",
"SV_Hold *bfs_free_hold;",
"",
"SV_Hold *",
"bfs_get_hold(void)",
"{ SV_Hold *x;",
" if (bfs_free_hold)",
" { x = bfs_free_hold;",
" bfs_free_hold = bfs_free_hold->nxt;",
" } else",
" { x = (SV_Hold *) sh_malloc((ulong) sizeof(SV_Hold));",
" }",
" return x;",
"}",
"",
"BFS_Trail *",
"bfs_unpack_state(BFS_Slot *n) /* called in bfs_explore_state */",
"{ BFS_Trail *otrpt;",
" BFS_State *bfs_t;",
" int vecsz;",
"",
" if (!n || !n->s_data || !n->s_data->t_info)",
" { bfs_Uerror(\"internal error\");",
" }",
" otrpt = (BFS_Trail *) ((BFS_State *) n->s_data)->t_info;",
"",
" trpt->ostate = otrpt->ostate;",
" trpt->st = otrpt->st;",
" trpt->o_tt = otrpt->o_tt;",
" trpt->pr = otrpt->pr;",
" trpt->tau = otrpt->tau;",
" trpt->o_pm = otrpt->o_pm;",
" if (trpt->ostate)",
" trpt->o_t = t_id_lkup[otrpt->t_id];",
"#if defined(C_States) && (HAS_TRACK==1)",
" c_revert((uchar *) &(now.c_state[0]));",
"#endif",
" if (trpt->o_pm & 4) /* rv succeeded */",
" { return (BFS_Trail *) 0; /* revisit not needed */",
" }",
"#ifndef NOREDUCE",
" bfs_nps = 0;",
"#endif",
" if (trpt->o_pm & 8) /* rv attempt failed */",
" { revrv++;",
" if (trpt->tau&8)",
" { trpt->tau &= ~8; /* break atomic */",
"#ifndef NOREDUCE",
" } else if (trpt->tau&32) /* void preselection */",
" { trpt->tau &= ~32;",
" bfs_nps = 1; /* no preselection in repeat */",
"#endif",
" } }",
" trpt->o_pm &= ~(4|8);",
" if (trpt->o_tt > mreached)",
" { static ulong nr = 0L, nc;",
" mreached = trpt->o_tt;",
" nc = (long) nstates/FREQ;",
" if (nc > nr)",
" { nr = nc;",
" bfs_snapshot();",
" } }",
" depth = trpt->o_tt;",
" if (depth >= maxdepth)",
" {",
"#if SYNC",
" if (boq != -1)",
" { BFS_Trail *x = (BFS_Trail *) trpt->ostate;",
" if (x) x->o_pm |= 4; /* rv not failing */",
" }",
"#endif",
" truncs++;",
" if (!warned)",
" { warned = 1;",
" bfs_printf(\"error: max search depth too small\\n\");",
" }",
" if (bounded)",
" { bfs_uerror(\"depth limit reached\");",
" }",
" return (BFS_Trail *) 0;",
" }",
"",
" bfs_t = n->s_data;",
"#if NRUNS>0",
" vsize = bfs_t->omask->sz;",
"#else",
" vsize = ((State *) (bfs_t->osv))->_vsz;",
"#endif",
"#if SYNC",
" boq = bfs_t->boq;",
"#endif",
"",
"#if defined(Q_PROVISO) && !defined(BITSTATE) && defined(FULLSTACK)",
" #ifdef USE_TDH",
" if (((uchar *)(bfs_t->lstate))) /* if BFS_INQ is set */",
" { *((uchar *) bfs_t->lstate) = 0; /* turn it off */",
" }",
" #else",
" if (bfs_t->lstate) /* bfs_par */",
" { bfs_t->lstate->tagged = 0; /* bfs_par state removed from q */",
" }",
" #endif",
"#endif",
" memcpy((char *) &now, (uchar *) bfs_t->osv, vsize);",
"#if !defined(NOCOMP) && !defined(HC) && NRUNS>0",
" Mask = (uchar *) bfs_t->omask->sv; /* in shared memory */",
"#endif",
"#ifdef BFS_CHECK",
" if (0) bfs_dump_now(\"got1\");",
"#endif",
"#ifdef TRIX",
" re_populate();",
"#else",
" #if NRUNS>0",
" if (now._nr_pr > 0)",
" {",
" #if VECTORSZ>32000",
" proc_offset = (int *) bfs_t->omask->po;",
" #else",
" proc_offset = (short *) bfs_t->omask->po;",
" #endif",
" proc_skip = (uchar *) bfs_t->omask->ps;",
" }",
" if (now._nr_qs > 0)",
" {",
" #if VECTORSZ>32000",
" q_offset = (int *) bfs_t->omask->qo;",
" #else",
" q_offset = (short *) bfs_t->omask->qo;",
" #endif",
" q_skip = (uchar *) bfs_t->omask->qs;",
" }",
" #endif",
"#endif",
" vecsz = ((State *) bfs_t->osv)->_vsz;",
"#ifdef BFS_CHECK",
" assert(vecsz > 0 && vecsz < VECTORSZ);",
"#endif",
" { SV_Hold *x = bfs_get_hold();",
" x->sv = bfs_t->osv;",
" x->nxt = bfs_svfree[vecsz];",
" bfs_svfree[vecsz] = x;",
" bfs_t->osv = (State *) 0;",
" }",
"#if NRUNS>0",
" bfs_keep(bfs_t->omask);",
"#endif",
"",
"#ifdef BFS_CHECK",
" if (0) bfs_dump_now(\"got2\");",
" if (0) view_state(\"after\");",
"#endif",
" return (BFS_Trail *) bfs_t->t_info;",
"}",
"void",
"bfs_initial_state(void)",
"{",
"#ifdef BFS_CHECK",
" assert(trpt != NULL);",
"#endif",
" trpt->ostate = (H_el *) 0;",
" trpt->o_tt = -1;",
" trpt->tau = 0;",
"#ifdef VERI",
" trpt->tau |= 4; /* claim moves first */",
"#endif",
" bfs_store_state(trpt, boq); /* initial state : bfs_lib.c */",
"}",
"",
"#ifdef BITSTATE",
" #define bfs_do_store(v, n) b_store(v, n)",
"#else",
" #ifdef USE_TDH",
" #define bfs_do_store(v, n) o_store(v, n)",
" #else",
" #define bfs_do_store(v, n) h_store(v, n)",
" #endif",
"#endif",
"",
"#ifdef BFS_SEP_HASH",
"int",
"bfs_seen_before(void)",
"{ /* cannot set trpt->tau |= 64 to mark successors outside stack */",
" /* since the check is done remotely and the trpt value is gone */",
" #ifdef VERI",
" if (!trpt->ostate /* initial state */",
" || ((trpt->tau&4) /* starting claim moves(s) */",
" && !(((BFS_Trail *)trpt->ostate)->tau&4))) /* prev move: prog */",
" { return 0; /* claim move: mid-state not stored */",
" } /* else */",
" #endif",
" if (!bfs_do_store((char *)&now, vsize)) /* sep_hash */",
" { nstates++; /* local count */",
" return 0; /* new state */",
" }",
" #ifdef BFS_CHECK",
" bfs_printf(\"seen before\\n\");",
" #endif",
" truncs++;",
" return 1; /* old state */",
"}",
"#endif",
"",
"void",
"bfs_explore_state(BFS_Slot *v) /* generate all successors of v */",
"{ BFS_Trail *otrpt;",
" Trans *t;",
"#ifdef HAS_UNLESS",
" int E_state;",
"#endif",
" int tt;",
" short II, To = BASE, From = (short) (now._nr_pr-1);",
" short oboq = boq;",
" uchar _n, _m, ot;",
"",
" memset(ntrpt, 0, sizeof(Trail));",
" otrpt = bfs_unpack_state(v); /* BFS_Trail */",
"",
" if (!otrpt) { return; } /* e.g., depth limit reached */",
"#ifdef L_BOUND",
" #if defined(VERBOSE)",
" bfs_printf(\"Unpacked state with l_bound %%d -- sds %%p\\n\",",
" now._l_bnd, now._l_sds);",
" #endif",
"#endif",
"",
"#if defined(C_States) && (HAS_TRACK==1)",
" c_revert((uchar *) &(now.c_state[0]));",
"#endif",
"",
"#ifdef BFS_SEP_HASH",
" if (bfs_seen_before()) return;",
"#endif",
"",
"#ifdef VERI", /* could move to just before store_state */
" if (now._nr_pr == 0 /* claim terminated */",
" || stopstate[((Pclaim *)pptr(0))->_t][((Pclaim *)pptr(0))->_p])",
" { bfs_uerror(\"end state in claim reached\");",
" }",
"#endif",
" trpt->tau &= ~1; /* timeout off */",
"#ifdef VERI",
" if (trpt->tau&4) /* claim move */",
" { trpt->tau |= (otrpt->tau)&1; /* inherit from prog move */",
" From = To = 0; /* claim */",
" goto Repeat_two;",
" }",
"#endif",
"#ifndef NOREDUCE",
" if (boq == -1 && !(trpt->tau&8) && bfs_nps == 0)",
" for (II = now._nr_pr-1; II >= BASE; II -= 1)",
" {",
"Pickup: _this = pptr(II);",
" tt = (int) ((P0 *)_this)->_p;",
" ot = (uchar) ((P0 *)_this)->_t;",
" if (trans[ot][tt]->atom & 8)",
" { t = trans[ot][tt];",
" if (t->qu[0] != 0)",
" { if (!q_cond(II, t))",
" continue;",
" }",
" From = To = II;",
" trpt->tau |= 32; /* preselect marker */",
" #ifdef VERBOSE",
" bfs_printf(\"%%3ld: proc %%d PreSelected (tau=%%d)\\n\", ",
" depth, II, trpt->tau);",
" #endif",
" goto Repeat_two;",
" } }",
" trpt->tau &= ~32;",
"#endif",
"",
"Repeat_one:",
" if (trpt->tau&8)",
" { From = To = (short ) trpt->pr; /* atomic */",
" } else",
" { From = now._nr_pr-1;",
" To = BASE;",
" }",
"#if defined(VERI) || !defined(NOREDUCE) || defined(ETIM)",
"Repeat_two: /* MainLoop */",
"#endif",
" _n = _m = 0;",
" for (II = From; II >= To; II -= 1) /* all processes */",
" {",
"#ifdef BFS_CHECK",
" bfs_printf(\"proc %%d (%%d - %%d)\\n\", II, From, To);",
"#endif",
"#if SYNC ",
" if (boq != -1 && trpt->pr == II)",
" { continue; /* no rendezvous with same proc */",
" }",
"#endif",
" _this = pptr(II);",
" tt = (int) ((P0 *)_this)->_p;",
" ot = (uchar) ((P0 *)_this)->_t;",
" ntrpt->pr = (uchar) II;",
" ntrpt->st = tt; ",
" trpt->o_pm &= ~1; /* no move yet */",
"#ifdef EVENT_TRACE",
" trpt->o_event = now._event;",
"#endif",
"#ifdef HAS_PRIORITY",
" if (!highest_priority(((P0 *)_this)->_pid, II, t))",
" { continue;",
" }",
"#else",
" #ifdef HAS_PROVIDED",
" if (!provided(II, ot, tt, t))",
" { continue;",
" }",
" #endif",
"#endif",
"#ifdef HAS_UNLESS",
" E_state = 0;",
"#endif",
" for (t = trans[ot][tt]; t; t = t->nxt) /* all process transitions */",
" {",
"#ifdef BFS_CHECK",
" assert(t_id_lkup[t->t_id] == t); /* for reverse lookup in bfs_unpack_state */",
"#endif",
"#ifdef VERBOSE",
" if (0) bfs_printf(\"\\tproc %%d tr %%d\\n\", II, t->forw);",
"#endif",
"#ifdef HAS_UNLESS",
" if (E_state > 0",
" && E_state != t->e_trans)",
" break;",
"#endif",
" /* trpt->o_t = */ ntrpt->o_t = t;",
" oboq = boq;",
"",
" if (!(_m = do_transit(t, II)))",
" continue;",
"",
" trpt->o_pm |= 1; /* we moved */",
" (trpt+1)->o_m = _m; /* for unsend */",
"#ifdef PEG",
" peg[t->forw]++;",
"#endif",
"#ifdef VERBOSE",
" e_critical(BFS_PRINT);",
" printf(\"%%3ld: proc %%d exec %%d, \",",
" depth, II, t->forw);",
" printf(\"%%d to %%d, %%s %%s %%s\",",
" tt, t->st, t->tp,",
" (t->atom&2)?\"atomic\":\"\",",
" (boq != -1)?\"rendez-vous\":\"\");",
" #ifdef HAS_UNLESS",
" if (t->e_trans)",
" printf(\" (escapes to state %%d)\", t->st);",
" #endif",
" printf(\" %%saccepting [tau=%%d]\\n\",",
" (trpt->o_pm&2)?\"\":\"non-\", trpt->tau);",
" x_critical(BFS_PRINT);",
"#endif",
"#ifdef HAS_UNLESS",
" E_state = t->e_trans;",
" #if SYNC>0",
" if (t->e_trans > 0 && boq != -1)",
" { fprintf(efd, \"error: rendezvous stmnt in the escape clause\\n\");",
" fprintf(efd, \" of unless stmnt not compatible with -DBFS\\n\");",
" pan_exit(1);",
" }",
" #endif",
"#endif",
" if (t->st > 0)",
" { ((P0 *)_this)->_p = t->st;",
" }",
" /* use the ostate ptr, with type *H_el, to temporarily store *BFS_Trail */",
"#ifdef BFS_NOTRAIL",
" ntrpt->ostate = (H_el *) 0; /* no error-traces in this mode */",
"#else",
" ntrpt->ostate = (H_el *) otrpt; /* parent stackframe */",
"#endif",
" /* ntrpt->st = tt; * was already set above */",
"",
" if (boq == -1 && (t->atom&2)) /* atomic */",
" { ntrpt->tau = 8; /* record for next move */",
" } else",
" { ntrpt->tau = 0; /* no timeout or preselect etc */",
" }",
"#ifdef VERI",
" ntrpt->tau |= trpt->tau&4; /* if claim, inherit */",
" if (boq == -1 && !(ntrpt->tau&8)) /* unless rv or atomic */",
" { if (ntrpt->tau&4) /* claim */",
" { ntrpt->tau &= ~4; /* switch to prog */",
" } else",
" { ntrpt->tau |= 4; /* switch to claim */",
" } }",
"#endif",
"#ifdef L_BOUND",
" { uchar obnd = now._l_bnd;",
" uchar *os = now._l_sds;",
" #ifdef VERBOSE",
" bfs_printf(\"saving bound %%d -- sds %%p\\n\", obnd, (void *) os);",
" #endif",
"#endif",
"",
" bfs_store_state(ntrpt, oboq);",
"#ifdef EVENT_TRACE",
" now._event = trpt->o_event;",
"#endif",
" /* undo move and generate other successor states */",
" trpt++; /* this is where ovals and ipt are set */",
" do_reverse(t, II, _m); /* restore now. */",
"#ifdef L_BOUND",
" #ifdef VERBOSE",
" bfs_printf(\"restoring bound %%d -- sds %%p\\n\", obnd, (void *) os);",
" #endif",
" now._l_bnd = obnd;",
" now._l_sds = os;",
" }",
"#endif",
" trpt--;",
"#ifdef VERBOSE",
" e_critical(BFS_PRINT);",
" printf(\"%%3ld: proc %%d \", depth, II);",
" printf(\"reverses %%d, %%d to %%d,\", t->forw, tt, t->st);",
" printf(\" %%s [abit=%%d,adepth=%%d,\", t->tp, now._a_t, 0);",
" printf(\"tau=%%d,%%d]\\n\", trpt->tau, (trpt-1)->tau);",
" x_critical(BFS_PRINT);",
"#endif",
" reached[ot][t->st] = 1;",
" reached[ot][tt] = 1;",
"",
" ((P0 *)_this)->_p = tt;",
" _n |= _m;",
" } }",
"#ifdef VERBOSE",
" bfs_printf(\"done _n = %%d\\n\", _n);",
"#endif",
"",
"#ifndef NOREDUCE",
" /* preselected - no succ definitely outside stack */",
" if ((trpt->tau&32) && !(trpt->tau&64))",
" { From = now._nr_pr-1; To = BASE;",
" #ifdef VERBOSE",
" bfs_printf(\"%%3ld: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
" depth, II+1, (int) _n, trpt->tau);",
" #endif",
" _n = 0; trpt->tau &= ~32;",
" if (II >= BASE)",
" { goto Pickup;",
" }",
" goto Repeat_two;",
" }",
" trpt->tau &= ~(32|64);",
"#endif",
" if (_n == 0",
"#ifdef VERI",
" && !(trpt->tau&4)",
"#endif",
" )",
" { /* no successor states generated */",
" if (boq != -1) /* was rv move */",
" { BFS_Trail *x = (BFS_Trail *) trpt->ostate; /* pre-rv state */",
" if (x && ((x->tau&8) || (x->tau&32))) /* break atomic or preselect */",
" { x->o_pm |= 8; /* mark failure */",
" _this = pptr(otrpt->pr);",
" ((P0 *) _this)->_p = otrpt->st; /* reset state */",
" unsend(boq); /* retract rv offer */",
" boq = -1;",
"#ifdef VERBOSE",
" printf(\"repush state\\n\");",
"#endif",
" bfs_push_state(NULL, x, x->o_tt); /* repush rv fail */",
" } /* else the rv need not be retried */",
" } else if (now._nr_pr > BASE) /* possible deadlock */",
" { if ((trpt->tau&8)) /* atomic step blocked */",
" { trpt->tau &= ~(1|8); /* 1=timeout, 8=atomic */",
" goto Repeat_one;",
" }",
"#ifdef ETIM",
" /* if timeouts were used in the model */",
" if (!(trpt->tau&1))",
" { trpt->tau |= 1; /* enable timeout */",
" goto Repeat_two;",
" }",
"#endif",
" if (!noends && !endstate())",
" { bfs_uerror(\"invalid end state.\");",
" }",
" }",
"#ifdef VERI",
" else /* boq == -1 && now._nr_pr == BASE && trpt->tau != 4 */",
" { trpt->tau |= 4; /* switch to claim for stutter moves */",
" #ifdef VERBOSE",
" printf(\"%%3ld: proc -1 exec -1, (stutter move)\\n\", depth, II);",
" #endif",
" bfs_store_state(trpt, boq);", /* doesn't store it but queues it */
" #ifdef VERBOSE",
" printf(\"%%3ld: proc -1 reverses -1, (stutter move)\\n\", depth, II);",
" #endif",
" trpt->tau &= ~4; /* undo, probably not needed */",
" }",
"#endif",
" }",
"#ifdef BFS_NOTRAIL",
" bfs_release_trail(otrpt);",
"#endif",
"}",
"#if !defined(BFS_FIFO) && !defined(BFS_NORECYCLE)",
"void",
"bfs_recycle(BFS_Slot *n)",
"{",
" #ifdef BFS_CHECK",
" assert(n != &bfs_null);",
" #endif",
" n->nxt = bfs_free_slot;",
" bfs_free_slot = n;",
"",
" #ifdef BFS_CHECK",
" bfs_printf(\"recycles %%s -- %%p\\n\",",
" n->s_data?\"STATE\":\"EMPTY\", (void *) n);",
" #endif",
"}",
"#endif",
"#ifdef BFS_FIFO",
"int",
"bfs_empty(int p)", /* return Cores if all empty or index of first non-empty q of p */
"{ int i;",
" const int dst = 0;",
" for (i = 0; i < Cores; i++)",
" { if (shared_memory->head[dst][p][i] != (BFS_Slot *) 0)",
" {",
" volatile BFS_Slot *x = shared_memory->head[dst][p][i];",
" while (x && x->type == DELETED)",
" { x = x->nxt;",
" }",
" if (!x)",
" { continue;",
" }",
" if (p == who_am_i)",
" { shared_memory->head[dst][p][i] = x;",
" }",
" #ifdef BFS_CHECK",
" bfs_printf(\"input q [%%d][%%d][%%d] !empty\\n\",",
" dst, p, i);",
" #endif",
" return i;",
" } }",
" #ifdef BFS_CHECK",
" bfs_printf(\"all input qs [%%d][%%d][0..max] empty\\n\",",
" dst, p);",
" #endif ",
" return Cores;",
"}",
"#endif",
"#ifdef BFS_DISK",
"void",
"bfs_ewrite(int fd, const void *p, size_t count)",
"{",
" if (write(fd, p, count) != count)",
" { perror(\"diskwrite\");",
" Uerror(\"aborting\");",
" }",
"}",
"",
"void",
"bfs_eread(int fd, void *p, size_t count)",
"{",
" if (read(fd, p, count) != count)",
" { perror(\"diskread\");",
" Uerror(\"aborting\");",
" }",
"}",
"",
"void",
"bfs_sink_disk(int who_are_you, BFS_Slot *n)",
"{ SV_Hold *x;",
"#ifdef VERBOSE",
" bfs_printf(\"sink_disk -> %%d\\n\", who_are_you);",
"#endif",
" bfs_ewrite(bfs_out_fd[who_are_you], (const void *) n->s_data->t_info, sizeof(BFS_Trail));",
" bfs_ewrite(bfs_out_fd[who_are_you], (const void *) &vsize, sizeof(ulong));",
" bfs_ewrite(bfs_out_fd[who_are_you], &now, vsize);",
"",
" bfs_release_trail(n->s_data->t_info);",
" n->s_data->t_info = (BFS_Trail *) 0;",
"",
"#if NRUNS>0",
" bfs_ewrite(bfs_out_fd[who_are_you], (const void *) &(n->s_data->omask), sizeof(EV_Hold *));",
"#endif",
"#ifdef Q_PROVISO",
" bfs_ewrite(bfs_out_fd[who_are_you], (const void *) &(n->s_data->lstate), sizeof(H_el *));",
"#endif",
"#if SYNC>0",
" bfs_ewrite(bfs_out_fd[who_are_you], (const void *) &(n->s_data->boq), sizeof(short));",
"#endif",
"#if VERBOSE",
" bfs_ewrite(bfs_out_fd[who_are_you], (const void *) &(n->s_data->nr), sizeof(ulong));",
"#endif",
" shared_memory->bfs_out_cnt[who_am_i] = 1;", /* wrote at least one state */
"}",
"void",
"bfs_source_disk(int fd, volatile BFS_Slot *n)",
"{ ulong nb; /* local temporary */",
" SV_Hold *x;",
"#ifdef VERBOSE",
" bfs_printf(\"source_disk <- %%d\\n\", who_am_i);",
"#endif",
" n->s_data->t_info = bfs_grab_trail();",
" bfs_eread(fd, (void *) n->s_data->t_info, sizeof(BFS_Trail));",
" bfs_eread(fd, (void *) &nb, sizeof(ulong));",
"",
" x = bfs_new_sv(nb); /* space for osv isn't already allocated */",
" n->s_data->osv = x->sv;",
" x->sv = (State *) 0;",
" x->nxt = bfs_free_hold;",
" bfs_free_hold = x;",
"",
" bfs_eread(fd, (void *) n->s_data->osv, (size_t) nb);",
"#if NRUNS>0",
" bfs_eread(fd, (void *) &(n->s_data->omask), sizeof(EV_Hold *));",
"#endif",
"#ifdef Q_PROVISO",
" bfs_eread(fd, (void *) &(n->s_data->lstate), sizeof(H_el *));",
"#endif",
"#if SYNC>0",
" bfs_eread(fd, (void *) &(n->s_data->boq), sizeof(short));",
"#endif",
"#if VERBOSE",
" bfs_eread(fd, (void *) &(n->s_data->nr), sizeof(ulong));",
"#endif",
"}",
"#endif",
"",
"#ifndef BFS_QSZ",
" #ifdef BFS_STAGGER",
"static BFS_Slot *bfs_stage[BFS_STAGGER];",
"",
"static void",
"bfs_stagger_flush(void)",
"{ int i, who_are_you;",
" int dst = 1 - bfs_toggle;",
" BFS_Slot *n;",
" who_are_you = (rand()%%Cores);", /* important: all to the same cpu, but reversed */
" for (i = bfs_stage_cnt-1; i >= 0; i--)",
" { n = bfs_stage[i];",
" #ifdef BFS_DISK",
" bfs_sink_disk(who_are_you, n);",
" bfs_stage[i] = (BFS_Slot *) 0;",
" #endif",
" n->nxt = (BFS_Slot *) shared_memory->head[dst][who_are_you][who_am_i];",
" shared_memory->head[dst][who_are_you][who_am_i] = n;",
" /* bfs_sent++; */",
" }",
" #ifdef VERBOSE",
" bfs_printf(\"stagger flush %%d states to %%d\\n\",",
" bfs_stage_cnt, who_are_you);",
" #endif",
" bfs_stage_cnt = 0;",
"}",
"",
"void",
"bfs_stagger_add(BFS_Slot *n)",
"{",
" if (bfs_stage_cnt == BFS_STAGGER)",
" { bfs_stagger_flush();",
" }",
" bfs_stage[bfs_stage_cnt++] = n;",
"}",
" #endif",
"#endif",
"",
"void",
"bfs_push_state(Trail *x, BFS_Trail *y, int tt)",
"{ int who_are_you;",
"#ifdef BFS_FIFO",
" const int dst = 0;",
"#else",
" int dst = 1 - bfs_toggle;",
"#endif",
"#ifdef BFS_QSZ",
" uint z;",
" if (bfs_keep_state > 0)",
" { who_are_you = bfs_keep_state - 1;",
" } else",
" { who_are_you = (rand()%%Cores);",
" }",
" z = shared_memory->bfs_ix[dst][who_are_you][who_am_i];",
" if (z >= BFS_QSZ)",
" { static int warned_qloss = 0;",
" if (warned_qloss == 0 && who_am_i == 0)",
" { warned_qloss++;",
" bfs_printf(\"BFS_QSZ too small - losing states\\n\");",
" }",
" bfs_punt++;",
" return;",
" }",
" shared_memory->bfs_ix[dst][who_are_you][who_am_i] = z+1;",
" BFS_Slot *n = bfs_pack_state(x, y, tt, bfs_prep_slot(y, ",
" (BFS_Slot *) &(shared_memory->bfsq[dst][who_are_you][who_am_i][z])));",
"#else",
" BFS_Slot *n = bfs_pack_state(x, y, tt, bfs_new_slot(y));",
"",
" #ifdef BFS_GREEDY",
" who_are_you = who_am_i; /* for testing only */",
" #else",
" if (bfs_keep_state > 0)",
" { who_are_you = bfs_keep_state - 1;",
" } else",
" {",
" #ifdef BFS_STAGGER",
" who_are_you = -1;",
" bfs_stagger_add(n);",
" goto done;",
" #else",
" who_are_you = (rand()%%Cores);",
" #endif",
" }",
" #endif",
" #ifdef BFS_FIFO",
" if (!shared_memory->tail[dst][who_are_you][who_am_i])",
" { shared_memory->dels[dst][who_are_you][who_am_i] =",
" shared_memory->tail[dst][who_are_you][who_am_i] =",
" shared_memory->head[dst][who_are_you][who_am_i] = n;",
" } else",
" { shared_memory->tail[dst][who_are_you][who_am_i]->nxt = n;",
" shared_memory->tail[dst][who_are_you][who_am_i] = n;",
" }",
" shared_memory->bfs_idle[who_are_you] = 0;",
" #else",
" #ifdef BFS_DISK",
" bfs_sink_disk(who_are_you, n);",
" #endif",
" n->nxt = (BFS_Slot *) shared_memory->head[dst][who_are_you][who_am_i];",
" shared_memory->head[dst][who_are_you][who_am_i] = n;",
" #endif",
" #ifdef BFS_STAGGER",
"done:",
" #endif",
"#endif", /* BFS_QSZ */
"#ifdef VERBOSE",
" bfs_printf(\"PUT STATE (depth %%ld, nr %%u) to %%d -- s_data: %%p\\n\",",
" tt, n->s_data->nr, who_are_you, n->s_data);",
"#endif",
" bfs_sent++;",
"}",
"",
"BFS_Slot *",
"bfs_next(void)",
"{ volatile BFS_Slot *n = &bfs_null;",
" #ifdef BFS_FIFO",
" const int src = 0;",
" bfs_qscan = bfs_empty(who_am_i);",
" #else",
" const int src = bfs_toggle;",
" #ifdef BFS_QSZ",
" while (bfs_qscan < Cores",
" && shared_memory->bfs_ix[src][who_am_i][bfs_qscan] == 0)",
" { bfs_qscan++;",
" }",
" #else",
" while (bfs_qscan < Cores",
" && shared_memory->head[src][who_am_i][bfs_qscan] == (BFS_Slot *) 0)",
" { bfs_qscan++;",
" }",
" #endif",
" #endif",
" if (bfs_qscan < Cores)",
" {",
" #ifdef BFS_FIFO", /* no wait for toggles */
" shared_memory->bfs_idle[who_am_i] = 0;",
" for (n = shared_memory->head[src][who_am_i][bfs_qscan]; n; n = n->nxt)",
" { if (n->type != DELETED)",
" { break;",
" } }",
" #ifdef BFS_CHECK",
" assert(n && n->type == STATE); /* q cannot be empty */",
" #endif",
" if (n->nxt)",
" { shared_memory->head[src][who_am_i][bfs_qscan] = n->nxt;",
" }", /* else, do not remove it - yet - avoid empty queues */
" n->type = DELETED;",
" #else",
" #ifdef BFS_QSZ",
" uint x = --shared_memory->bfs_ix[src][who_am_i][bfs_qscan];",
" n = &(shared_memory->bfsq[src][who_am_i][bfs_qscan][x]);",
" #else",
" n = shared_memory->head[src][who_am_i][bfs_qscan];",
" shared_memory->head[src][who_am_i][bfs_qscan] = n->nxt;",
" #if defined(BFS_FIFO) && defined(BFS_CHECK)",
" assert(n->type == STATE);",
" #endif",
" n->nxt = (BFS_Slot *) 0;",
" #endif",
" #ifdef BFS_DISK",
" /* the states actually show up in reverse order (FIFO iso LIFO) here */",
" /* but that doesn't really matter as long as the count is right */",
" bfs_source_disk(bfs_inp_fd[bfs_qscan], n); /* get the data */",
" #endif",
" #endif",
" #ifdef BFS_CHECK",
" bfs_printf(\"rcv STATE from [%%d][%%d][%%d]\\n\",",
" src, who_am_i, bfs_qscan);",
" #endif",
" bfs_rcvd++;",
" } else",
" {",
" #if defined(BFS_STAGGER) && !defined(BFS_QSZ)",
" if (bfs_stage_cnt > 0)",
" { bfs_stagger_flush();",
" }",
" #endif",
" shared_memory->bfs_idle[who_am_i] = 1;",
" #if defined(BFS_FIFO) && defined(BFS_CHECK)",
" assert(n->type == EMPTY);",
" #endif",
" }",
" return (BFS_Slot *) n;",
"}",
"",
"int",
"bfs_all_empty(void)",
"{ int i;",
"#ifdef BFS_DISK",
" for (i = 0; i < Cores; i++)",
" { if (shared_memory->bfs_out_cnt[i] != 0)",
" {",
" #ifdef VERBOSE",
" bfs_printf(\"bfs_all_empty %%d not empty\\n\", i);",
" #endif",
" return 0;",
" } }",
"#else",
" int p;",
" #ifdef BFS_FIFO",
" const int dst = 0;",
" #else",
" int dst = 1 - bfs_toggle; /* next generation */",
" #endif",
" for (p = 0; p < Cores; p++)",
" for (i = 0; i < Cores; i++)",
" #ifdef BFS_QSZ",
" { if (shared_memory->bfs_ix[dst][p][i] > 0)",
" #else",
" { if (shared_memory->head[dst][p][i] != (BFS_Slot *) 0)",
" #endif",
" { return 0;",
" } }",
"#endif",
"#ifdef VERBOSE",
" bfs_printf(\"bfs_all_empty\\n\");",
"#endif",
" return 1;",
"}",
"",
"#ifdef BFS_FIFO",
"BFS_Slot *",
"bfs_sweep(void)",
"{ BFS_Slot *n;",
" int i;",
" for (i = 0; i < Cores; i++)",
" for (n = (BFS_Slot *) shared_memory->dels[0][who_am_i][i];",
" n && n != shared_memory->head[0][who_am_i][i];",
" n = n->nxt)",
" { if (n->type == DELETED && n->nxt)",
" { shared_memory->dels[0][who_am_i][i] = n->nxt;",
" n->nxt = (BFS_Slot *) 0;",
" return n;",
" } }",
" return (BFS_Slot *) sh_malloc((ulong) sizeof(BFS_Slot));",
"}",
"#endif",
"",
"typedef struct BFS_T_Hold BFS_T_Hold;",
"struct BFS_T_Hold {",
" volatile BFS_Trail *t;",
" BFS_T_Hold *nxt;",
"};",
"BFS_T_Hold *bfs_t_held, *bfs_t_free;",
"",
"BFS_Trail *",
"bfs_grab_trail(void)", /* call in bfs_source_disk and bfs_new_slot */
"{ BFS_Trail *t;",
" BFS_T_Hold *h;",
"",
"#ifdef VERBOSE",
" bfs_printf(\"grab trail - bfs_t_held %%p\\n\", (void *) bfs_t_held);",
"#endif",
" if (bfs_t_held)",
" { h = bfs_t_held;",
" bfs_t_held = bfs_t_held->nxt;",
" t = (BFS_Trail *) h->t;",
" h->t = (BFS_Trail *) 0; /* make sure it cannot be reused */",
" h->nxt = bfs_t_free;",
" bfs_t_free = h;",
"",
" } else",
" { t = (BFS_Trail *) sh_malloc((ulong) sizeof(BFS_Trail));",
" }",
"#ifdef BFS_CHECK",
" assert(t);",
"#endif",
" t->ostate = (H_el *) 0;",
"#ifdef VERBOSE",
" bfs_printf(\"grab trail %%p\\n\", (void *) t);",
"#endif",
" return t;",
"}",
"",
"#if defined(BFS_DISK) || defined(BFS_NOTRAIL)",
"void",
"bfs_release_trail(BFS_Trail *t)", /* call in bfs_sink_disk (not bfs_recycle) */
"{ BFS_T_Hold *h;",
" #ifdef BFS_CHECK",
" assert(t);",
" #endif",
" #ifdef VERBOSE",
" bfs_printf(\"release trail %%p\\n\", (void *) t);",
" #endif",
" if (bfs_t_free)",
" { h = bfs_t_free;",
" bfs_t_free = bfs_t_free->nxt;",
" } else",
" { h = (BFS_T_Hold *) emalloc(sizeof(BFS_T_Hold));",
" }",
" h->t = t;",
" h->nxt = bfs_t_held;",
" bfs_t_held = h;",
" #ifdef VERBOSE",
" bfs_printf(\"release trail - bfs_t_held %%p\\n\", (void *) bfs_t_held);",
" #endif",
"}",
"#endif",
"",
"#ifndef BFS_QSZ",
"BFS_Slot *",
"bfs_new_slot(BFS_Trail *f)",
"{ BFS_Slot *t;",
"",
"#ifdef BFS_FIFO",
" t = bfs_sweep();",
"#else",
" if (bfs_free_slot) /* local */",
" { t = bfs_free_slot;",
" bfs_free_slot = bfs_free_slot->nxt;",
" t->nxt = (BFS_Slot *) 0;",
" } else",
" { t = (BFS_Slot *) sh_malloc((ulong) sizeof(BFS_Slot));",
" }",
"#endif",
" if (t->s_data)",
" { memset(t->s_data, 0, sizeof(BFS_State));",
" } else",
" { t->s_data = (BFS_State *) sh_malloc((ulong) sizeof(BFS_State));",
" }",
"",
" /* we keep a ptr to the frame of parent states, which is */",
" /* used for reconstructing path and recovering failed rvs etc */",
" /* we should not overwrite the data at this address with a memset */",
"",
" if (f)",
" { t->s_data->t_info = f;",
" } else",
" { t->s_data->t_info = bfs_grab_trail();",
" }",
" return t;",
"}",
"#else",
"BFS_Slot *",
"bfs_prep_slot(BFS_Trail *f, BFS_Slot *t)",
"{",
" if (t->s_data)",
" { memset(t->s_data, 0, sizeof(BFS_State));",
" } else",
" { t->s_data = (BFS_State *) sh_malloc((ulong) sizeof(BFS_State));",
" }",
" if (f)",
" { t->s_data->t_info = f;",
" } else",
" { t->s_data->t_info = bfs_grab_trail();",
" }",
" return t;",
"}",
"#endif",
"",
"SV_Hold *",
"bfs_new_sv(int n)",
"{ SV_Hold *h;",
"",
" if (bfs_svfree[n])",
" { h = bfs_svfree[n];",
" bfs_svfree[n] = h->nxt;",
" h->nxt = (SV_Hold *) 0;",
" } else",
" { h = (SV_Hold *) sh_malloc((ulong) sizeof(SV_Hold));",
"#if 0",
" h->sz = n;",
"#endif",
" h->sv = (State *) sh_malloc((ulong)(sizeof(State) - VECTORSZ + n));",
" }",
" memcpy((char *)h->sv, (char *)&now, n);",
" return h;",
"}",
"#if NRUNS>0",
"static EV_Hold *kept[VECTORSZ]; /* local */",
"",
"static void",
"bfs_keep(EV_Hold *v)",
"{ EV_Hold *h;",
"",
" for (h = kept[v->sz]; h; h = h->nxt) /* check local list */",
" { if (v->nrpr == h->nrpr",
" && v->nrqs == h->nrqs",
"#if !defined(NOCOMP) && !defined(HC)",
" && (v->sv == h->sv || memcmp((char *) v->sv, (char *) h->sv, v->sz) == 0)",
"#endif",
"#ifdef TRIX",
" )",
"#else",
" #if NRUNS>0",
" #if VECTORSZ>32000",
" && (memcmp((char *) v->po, (char *) h->po, v->nrpr * sizeof(int)) == 0)",
" && (memcmp((char *) v->qo, (char *) h->qo, v->nrqs * sizeof(int)) == 0)",
" #else",
" && (memcmp((char *) v->po, (char *) h->po, v->nrpr * sizeof(short)) == 0)",
" && (memcmp((char *) v->qo, (char *) h->qo, v->nrqs * sizeof(short)) == 0)",
" #endif",
" && (memcmp((char *) v->ps, (char *) h->ps, v->nrpr * sizeof(uchar)) == 0)",
" && (memcmp((char *) v->qs, (char *) h->qs, v->nrqs * sizeof(uchar)) == 0))",
" #else",
" )",
" #endif",
"#endif",
" { break;",
" } }",
"",
" if (!h) /* we don't have one like it yet */",
" { v->nxt = kept[v->sz]; /* keep the original owner field */",
" kept[v->sz] = v;",
" /* all ptrs inside are to shared memory, but nxt is local */",
" }",
"}",
"",
"EV_Hold *",
"bfs_new_sv_mask(int n)",
"{ EV_Hold *h;",
"",
" for (h = kept[n]; h; h = h->nxt)",
" { if ((now._nr_pr == h->nrpr)",
" && (now._nr_qs == h->nrqs)",
"#if !defined(NOCOMP) && !defined(HC) && NRUNS>0",
" && ((char *) Mask == h->sv || (memcmp((char *) Mask, h->sv, n) == 0))",
"#endif",
"#ifdef TRIX",
" )",
"#else",
" #if NRUNS>0",
" #if VECTORSZ>32000",
" && (memcmp((char *) proc_offset, (char *) h->po, now._nr_pr * sizeof(int)) == 0)",
" && (memcmp((char *) q_offset, (char *) h->qo, now._nr_qs * sizeof(int)) == 0)",
" #else",
" && (memcmp((char *) proc_offset, (char *) h->po, now._nr_pr * sizeof(short)) == 0)",
" && (memcmp((char *) q_offset, (char *) h->qo, now._nr_qs * sizeof(short)) == 0)",
" #endif",
" && (memcmp((char *) proc_skip, (char *) h->ps, now._nr_pr * sizeof(uchar)) == 0)",
" && (memcmp((char *) q_skip, (char *) h->qs, now._nr_qs * sizeof(uchar)) == 0))",
" #else",
" )",
" #endif",
"#endif",
" { break;",
" } }",
"",
" if (!h)",
" { /* once created, the contents are never modified */",
" h = (EV_Hold *) sh_malloc((ulong)sizeof(EV_Hold));",
" h->owner = who_am_i;",
" h->sz = n;",
" h->nrpr = now._nr_pr;",
" h->nrqs = now._nr_qs;",
"#if !defined(NOCOMP) && !defined(HC) && NRUNS>0",
" h->sv = (char *) Mask; /* in shared memory, and never modified */",
"#endif",
"#if NRUNS>0 && !defined(TRIX)",
" if (now._nr_pr > 0)",
" { h->ps = (char *) proc_skip;",
" h->po = (char *) proc_offset;",
" }",
" if (now._nr_qs > 0)",
" { h->qs = (char *) q_skip;",
" h->qo = (char *) q_offset;",
" }",
"#endif",
" h->nxt = kept[n];",
" kept[n] = h;",
" }",
" return h;",
"}",
"#endif", /* NRUNS>0 */
"BFS_Slot *",
"bfs_pack_state(Trail *f, BFS_Trail *g, int search_depth, BFS_Slot *t)",
"{",
"#ifdef BFS_CHECK",
" assert(t->s_data != NULL);",
" assert(t->s_data->t_info != NULL);",
" assert(f || g);",
"#endif",
" if (!g)",
" { t->s_data->t_info->ostate = f->ostate;",
" t->s_data->t_info->st = f->st;",
" t->s_data->t_info->o_tt = search_depth;",
" t->s_data->t_info->pr = f->pr;",
" t->s_data->t_info->tau = f->tau;",
" t->s_data->t_info->o_pm = f->o_pm;",
" if (f->o_t)",
" { t->s_data->t_info->t_id = f->o_t->t_id;",
" } else",
" { t->s_data->t_info->t_id = -1;",
" t->s_data->t_info->ostate = NULL;",
" }",
" } /* else t->s_data->t_info == g */",
"#if SYNC",
" t->s_data->boq = boq;",
"#endif",
"#ifdef VERBOSE",
" { static ulong u_cnt;",
" t->s_data->nr = u_cnt++;",
" }",
"#endif",
"#ifdef TRIX",
" sv_populate(); /* make sure now is up to date */",
"#endif",
"#ifndef BFS_DISK",
" { SV_Hold *x = bfs_new_sv(vsize);",
" t->s_data->osv = x->sv;",
" x->sv = (State *) 0;",
" x->nxt = bfs_free_hold;",
" bfs_free_hold = x;",
" }",
"#endif",
"#if NRUNS>0",
" t->s_data->omask = bfs_new_sv_mask(vsize);",
"#endif",
"",
"#if defined(Q_PROVISO) && !defined(BITSTATE) && !defined(NOREDUCE)",
" t->s_data->lstate = Lstate; /* Lstate is set in o_store or h_store */",
"#endif",
"#ifdef BFS_FIFO",
" t->type = STATE;",
"#endif",
" return t;",
"}",
"",
"void",
"bfs_store_state(Trail *t, short oboq)",
"{",
"#ifdef TRIX",
" sv_populate();",
"#endif",
"#if defined(VERI) && defined(Q_PROVISO) && !defined(BITSTATE) && defined(FULLSTACK)",
" if (!(t->tau&4)", /* prog move */
" && t->ostate)", /* not initial state */
" { t->tau |= ((BFS_Trail *) t->ostate)->tau&64;",
" } /* lift 64 across claim moves */",
"#endif",
"",
"#ifdef BFS_SEP_HASH",
" #if SYNC",
" if (boq == -1 && oboq != -1) /* post-rv */",
" { BFS_Trail *x = (BFS_Trail *) trpt->ostate; /* pre-rv state */",
" if (x)",
" { x->o_pm |= 4; /* rv complete */",
" } }",
" #endif",
" d_sfh((uchar *)&now, (int) vsize); /* sep-hash -- sets K1 -- overkill */",
" bfs_keep_state = K1%%Cores + 1;",
" bfs_push_state(t, NULL, trpt->o_tt+1); /* bfs_store_state - sep_hash */",
" bfs_keep_state = 0;",
"#else",
" #ifdef VERI",
#if 0
in VERI mode store the state when
(!t->ostate || (t->tau&4)) in initial state and after each program move
i.e., dont store when !(!t->ostate || (t->tau&4)) = (t->ostate && !(t->tau&4))
the *first* time that the tau flag is not set:
possibly after a series of claim moves in an atomic sequence
#endif
" if (!(t->tau&4) && t->ostate && (((BFS_Trail *)t->ostate)->tau&4))",
" { /* do not store intermediate state */",
" #if defined(VERBOSE) && defined(L_BOUND)",
" bfs_printf(\"Un-Stored state bnd %%d -- sds %%p\\n\",",
" now._l_bnd, now._l_sds);",
" #endif",
" bfs_push_state(t, NULL, trpt->o_tt+1); /* claim move */",
" } else",
" #endif",
" if (!bfs_do_store((char *)&now, vsize)) /* includes bfs_visited */",
" { nstates++; /* local count */",
" trpt->tau |= 64; /* bfs: succ outside stack */",
" #if SYNC",
" if (boq == -1 && oboq != -1) /* post-rv */",
" { BFS_Trail *x = ",
" (BFS_Trail *) trpt->ostate; /* pre-rv state */",
" if (x)",
" { x->o_pm |= 4; /* rv complete */",
" } }",
" #endif",
" bfs_push_state(t, NULL, trpt->o_tt+1); /* successor */",
" } else",
" { truncs++;",
" #ifdef BFS_CHECK",
" bfs_printf(\"seen before\\n\");",
" #endif",
" #if defined(Q_PROVISO) && !defined(BITSTATE) && defined(FULLSTACK)",
" #ifdef USE_TDH",
" if (Lstate)", /* if BFS_INQ is set */
" { trpt->tau |= 64;",
" }",
" #else",
" if (Lstate && Lstate->tagged) /* bfs_store_state */",
" { trpt->tau |= 64;",
" }",
" #endif",
" #endif",
" }",
"#endif",
"}",
"",
"/*** support routines ***/",
"",
"void",
"bfs_clear_locks(void)",
"{ int i;",
"",
" /* clear any locks held by this process only */",
" if (shared_memory)",
" for (i = 0; i < BFS_MAXLOCKS; i++)",
" { if (shared_memory->sh_owner[i] == who_am_i + 1)",
" { shared_memory->sh_locks[i] = 0;",
"#ifdef BFS_CHECK",
" shared_memory->in_count[i] = 0;",
"#endif",
" shared_memory->sh_owner[i] = 0;",
" } }",
"}",
"",
"void",
"e_critical(int which)",
"{ int w;",
"#ifdef BFS_CHECK",
" assert(which >= 0 && which < BFS_MAXLOCKS);",
"#endif",
" if (shared_memory == NULL) return;",
" while (tas(&(shared_memory->sh_locks[which])) != 0)",
" { w = shared_memory->sh_owner[which]; /* sh_locks[which] could be 0 by now */",
" assert(w >= 0 && w <= BFS_MAXPROCS);",
" if (w > 0 && shared_memory->bfs_flag[w-1] == 2)",
" { /* multiple processes can get here; only one should do this: */",
" if (tas(&(shared_memory->bfs_data[w - 1].override)) == 0)",
" { fprintf(stderr, \"cpu%%02d: override lock %%d - held by %%d\\n\",",
" who_am_i, which, shared_memory->sh_owner[which]);",
"#ifdef BFS_CHECK",
" shared_memory->in_count[which] = 0;",
"#endif",
" shared_memory->sh_locks[which] = 0;",
" shared_memory->sh_owner[which] = 0;",
" } }",
" shared_memory->wait_count[which]++; /* not atomic of course */",
" }",
"#ifdef BFS_CHECK",
" if (shared_memory->in_count[which] != 0)",
" { fprintf(stderr, \"cpu%%02d: cannot happen lock %%d count %%d\\n\", who_am_i,",
" which, shared_memory->in_count[which]);",
" }",
" shared_memory->in_count[which]++;",
"#endif",
" shared_memory->sh_owner[which] = who_am_i+1;",
"}",
"",
"void",
"x_critical(int which)",
"{",
" if (shared_memory == NULL) return;",
"#ifdef BFS_CHECK",
" assert(shared_memory->in_count[which] == 1);",
" shared_memory->in_count[which] = 0;",
"#endif",
" shared_memory->sh_locks[which] = 0;",
" shared_memory->sh_owner[which] = 0;",
"}",
"",
"void",
"bfs_printf(const char *fmt, ...)",
"{ va_list args;",
"",
" e_critical(BFS_PRINT);",
"#ifdef BFS_CHECK",
" if (1) { int i=who_am_i; while (i-- > 0) printf(\" \"); }",
"#endif",
" printf(\"cpu%%02d: \", who_am_i);",
" va_start(args, fmt);",
" vprintf(fmt, args);",
" va_end(args);",
" fflush(stdout);",
" x_critical(BFS_PRINT);",
"}",
"",
"int",
"bfs_all_idle(void)",
"{ int i;",
"",
" if (shared_memory)",
" for (i = 0; i < Cores; i++)",
" { if (shared_memory->bfs_flag[i] == 0",
" && shared_memory->bfs_idle[i] == 0)",
" { return 0;",
" } }",
" return 1;",
"}",
"",
"#ifdef BFS_FIFO",
"int",
"bfs_idle_and_empty(void)",
"{ int p; /* read-only */",
" for (p = 0; p < Cores; p++)",
" { if (shared_memory->bfs_flag[p] == 0",
" && shared_memory->bfs_idle[p] == 0)",
" { return 0;",
" } }",
" for (p = 0; p < Cores; p++)",
" { if (bfs_empty(p) < Cores)",
" { return 0;",
" } }",
" return 1;",
"}",
"#endif",
"",
"void",
"bfs_set_toggle(void) /* executed by root */",
"{ int i;",
"",
" if (shared_memory)",
" for (i = 0; i < Cores; i++)",
" { shared_memory->bfs_idle[i] = 0;",
" }",
"}",
"",
"int",
"bfs_all_running(void) /* crash detection */",
"{ int i;",
" for (i = 0; i < Cores; i++)",
" { if (!shared_memory || shared_memory->bfs_flag[i] > 1)",
" { return 0;",
" } }",
" return 1;",
"}",
"",
"void",
"bfs_mark_done(int code)",
"{",
" if (shared_memory)",
" { shared_memory->bfs_flag[who_am_i] = (int) code;",
" shared_memory->quit = 1;",
" }",
"}",
"",
"static uchar *",
"bfs_offset(int c)",
"{ int p, N;",
"#ifdef COLLAPSE",
" uchar *q = (uchar *) ncomps; /* it is the first object allocated */",
" q += (256+2) * sizeof(ulong); /* preserve contents of ncomps */",
"#else",
" uchar *q = (uchar *) &(shared_memory->allocator);",
"#endif",
" /* _NP_+1 proctypes, reachability info:",
" * reached[x : 0 .. _NP_+1][ 0 .. NrStates[x] ]",
" */",
" for (p = N = 0; p <= _NP_; p++)",
" { N += NrStates[p]; /* sum for all proctypes */",
" }",
"",
" /* space needed per proctype: N bytes */",
" /* rounded up to a multiple of the word size */",
" if ((N%%sizeof(void *)) != 0) /* aligned */",
" { N += sizeof(void *) - (N%%sizeof(void *));",
" }",
"",
" q += ((c - 1) * (_NP_ + 1) * N);",
" return q;",
"}",
"",
"static void",
"bfs_putreached(void)",
"{ uchar *q;",
" int p;",
"",
" assert(who_am_i > 0);",
"",
" q = bfs_offset(who_am_i);",
" for (p = 0; p <= _NP_; p++)",
" { memcpy((void *) q, (const void *) reached[p], (size_t) NrStates[p]);",
" q += NrStates[p];",
" }",
"}",
"",
"static void",
"bfs_getreached(int c)",
"{ uchar *q;",
" int p, i;",
"",
" assert(who_am_i == 0 && c >= 1 && c < Cores);",
"",
" q = (uchar *) bfs_offset(c);",
" for (p = 0; p <= _NP_; p++)",
" for (i = 0; i < NrStates[p]; i++)",
" { reached[p][i] += *q++; /* update local copy */",
" }",
"}",
"",
"void",
"bfs_update(void)",
"{ int i;",
" volatile BFS_data *s;",
"",
" if (!shared_memory) return;",
"",
" s = &shared_memory->bfs_data[who_am_i];",
" if (who_am_i == 0)",
" { shared_memory->bfs_flag[who_am_i] = 3; /* or else others don't stop */",
" bfs_gcount = 0;",
" for (i = 1; i < Cores; i++) /* start at 1 not 0 */",
" { while (shared_memory->bfs_flag[i] == 0)",
" { sleep(1);",
" if (bfs_gcount++ > WAIT_MAX) /* excessively long wait */",
" { printf(\"cpu00: give up waiting for cpu%%2d (%%d cores)\\n\", i, Cores);",
" bfs_gcount = 0;",
" break;",
" } }",
" s = &shared_memory->bfs_data[i];",
" mreached = Max(mreached, s->mreached);",
" hmax = vsize = Max(vsize, s->vsize);",
" errors += s->errors;",
" memcnt += s->memcnt;",
" nstates += s->nstates;",
" nlinks += s->nlinks;",
" truncs += s->truncs;",
" bfs_left += s->memory_left;",
" bfs_punt += s->punted;",
" bfs_getreached(i);",
" }",
" } else",
" { s->mreached = (ulong) mreached;",
" s->vsize = (ulong) vsize;",
" s->errors = (int) errors;",
" s->memcnt = (double) memcnt;",
" s->nstates = (double) nstates;",
" s->nlinks = (double) nlinks;",
" s->truncs = (double) truncs;",
" s->memory_left = (ulong) bfs_left;",
" s->punted = (ulong) bfs_punt;",
" bfs_putreached();",
" }",
"}",
"",
"volatile uchar *",
"sh_pre_malloc(ulong n) /* used before the local heaps are populated */",
"{ volatile uchar *ptr = NULL;",
"",
" assert(!bfs_runs);",
" if ((n%%sizeof(void *)) != 0)",
" { n += sizeof(void *) - (n%%sizeof(void *));",
" assert((n%%sizeof(void *)) == 0);",
" }",
"",
" e_critical(BFS_MEM); /* needed? */",
" if (shared_memory->mem_left < n + 7)", /* 7 for possible alignment */
" { x_critical(BFS_MEM);",
" bfs_printf(\"want %%lu, have %%lu\\n\",",
" n, shared_memory->mem_left);",
" bfs_shutdown(\"out of shared memory\");",
" assert(0); /* should be unreachable */",
" }",
" ptr = shared_memory->allocator;",
"#if WS>4", /* align to 8 byte boundary */
" { int b = (int) ((uint64_t) ptr)&7;",
" if (b != 0)",
" { ptr += (8-b);",
" shared_memory->allocator = ptr;",
" } }",
"#endif",
" shared_memory->allocator += n;",
" shared_memory->mem_left -= n;",
" x_critical(BFS_MEM);",
"",
" bfs_pre_allocated += n;",
"",
" return ptr;",
"}",
"",
"volatile uchar *",
"sh_malloc(ulong n)",
"{ volatile uchar *ptr = NULL;",
"#ifdef BFS_CHECK",
" assert(bfs_runs);",
"#endif",
" if ((n%%sizeof(void *)) != 0)",
" { n += sizeof(void *) - (n%%sizeof(void *));",
"#ifdef BFS_CHECK",
" assert((n%%sizeof(void *)) == 0);",
"#endif",
" }",
"",
" /* local heap -- no locks needed */",
" if (bfs_left < n)",
" { e_critical(BFS_MEM);",
" if (shared_memory->mem_left >= n)",
" { ptr = (uchar *) shared_memory->allocator;",
" shared_memory->allocator += n;",
" shared_memory->mem_left -= n;",
" x_critical(BFS_MEM);",
" return ptr;",
" }",
" x_critical(BFS_MEM);",
"#ifdef BFS_LOGMEM",
" int i;",
" e_critical(BFS_MEM);",
" for (i = 0; i < 1024; i++)",
" { if (shared_memory->logmem[i] > 0)",
" { bfs_printf(\"\tlog[%%d]\t%%d\\n\", i, shared_memory->logmem[i]);",
" } }",
" x_critical(BFS_MEM);",
"#endif",
" bfs_shutdown(\"out of shared memory\"); /* no return */",
" }",
"#ifdef BFS_LOGMEM",
" e_critical(BFS_MEM);",
" if (n < 1023)",
" { shared_memory->logmem[n]++;",
" } else",
" { shared_memory->logmem[1023]++;",
" }",
" x_critical(BFS_MEM);",
"#endif",
" ptr = (uchar *) bfs_heap;",
" bfs_heap += n;",
" bfs_left -= n;",
"",
" if (0) printf(\"sh_malloc %%ld\\n\", n);",
" return ptr;",
"}",
"",
"volatile uchar *",
"bfs_get_shared_mem(key_t key, size_t n)",
"{ char *rval;",
"",
" assert(who_am_i == 0);",
"",
" shared_mem_id = shmget(key, n, 0600 | IPC_CREAT | IPC_EXCL); /* create */",
" if (shared_mem_id == -1)",
" { fprintf(stderr, \"cpu%%02d: tried to get %%d MB of shared memory\\n\",",
" who_am_i, (int) n/(1024*1024));",
" perror(\"shmget\");",
" exit(1);",
" }",
" if ((rval = (char *) shmat(shared_mem_id, (void *) 0, 0)) == (char *) -1) /* attach */",
" { perror(\"shmat\");",
" exit(1);",
" }",
" return (uchar *) rval;",
"}",
"",
"void",
"bfs_drop_shared_memory(void)",
"{",
" if (who_am_i == 0)",
" { printf(\"pan: releasing shared memory...\");",
" fflush(stdout);",
" }",
" if (shared_memory)",
" { shmdt(shared_memory); /* detach */",
" if (who_am_i == 0)",
" { shmctl(shared_mem_id, IPC_RMID, (void *) 0); /* remove */",
" } }",
" if (who_am_i == 0)",
" { printf(\"done\\n\");",
" fflush(stdout);",
" }",
"}",
"",
"size_t",
"bfs_find_largest(key_t key)",
"{ size_t n;",
" const size_t delta = 32*1024*1024;",
" int temp_id = -1;",
" int atleastonce = 0;",
"",
" for (n = delta; ; n += delta)",
" { if (WS <= 4 && n >= 1024*1024*1024)", /* was n >= INT_MAX */
" { n = 1024*1024*1024;",
" break;",
" }",
"#ifdef MEMLIM",
" if ((double) n > memlim)",
" { n = (size_t) memlim;",
" break;",
" }",
"#endif",
" temp_id = shmget(key, n, 0600); /* check for stale copy */",
" if (temp_id != -1)",
" { if (shmctl(temp_id, IPC_RMID, ((void *) 0)) < 0) /* remove */",
" { perror(\"remove_segment_fails 2\");",
" exit(1);",
" } }",
"",
" temp_id = shmget(key, n, 0600 | IPC_CREAT | IPC_EXCL); /* create new */",
" if (temp_id == -1)",
" { n -= delta;",
" break;",
" } else",
" { atleastonce++;",
" if (shmctl(temp_id, IPC_RMID, ((void *) 0)) < 0)",
" { perror(\"remove_segment_fails 0\");",
" exit(1);",
" } } }",
"",
" if (!atleastonce)",
" { printf(\"cpu%%02d: no shared memory n=%%d\\n\", who_am_i, (int) n);",
" exit(1);",
" }",
"",
" printf(\"cpu%%02d: largest shared memory segment: %%lu MB\\n\",",
" who_am_i, (ulong) n/(1024*1024));",
"#if 0",
" #ifdef BFS_SEP_HASH",
" n /= 2; /* not n /= Cores because the queues take most memory */",
" printf(\"cpu%%02d: using %%lu MB\\n\", who_am_i, (ulong) n/(1024*1024));",
" #endif",
"#endif",
" fflush(stdout);",
"",
" if ((n/(1024*1024)) == 32)",
" { if (sizeof(void *) == 4) /* a 32 bit machine */",
" { fprintf(stderr, \"\\t32MB is the default; increase it to 1 GB with:\\n\");",
" fprintf(stderr, \"\\tsudo /sbin/sysctl kernel.shmmax=%%d\\n\", (1<<30));",
" fprintf(stderr, \"\\tsudo /sbin/sysctl kernel.shmall=%%d\\n\", (1<<30)/8192);",
" } else if (sizeof(void *) == 8) /* a 64 bit machine */",
" { fprintf(stderr, \"\\t32MB is the default; increase it to 30 GB with:\\n\");",
" fprintf(stderr, \"\\tsudo /sbin/sysctl kernel.shmmax=32212254720\\n\");",
" fprintf(stderr, \"\\tsudo /sbin/sysctl kernel.shmall=7864320\\n\");",
" fprintf(stderr, \"\\tor for 60 GB:\\n\");",
" fprintf(stderr, \"\\tsudo /sbin/sysctl kernel.shmmax=60000000000\\n\");",
" fprintf(stderr, \"\\tsudo /sbin/sysctl kernel.shmall=30000000\\n\");",
" } else",
" { fprintf(stderr, \"\\tweird wordsize %%d\\n\", (int) sizeof(void *));",
" } }",
"",
" return n;",
"}",
"#ifdef BFS_DISK",
"void",
"bfs_disk_start(void)", /* setup .spin*/
"{ int unused = system(\"rm -fr .spin\");",
" if (mkdir(\".spin\", 0777) != 0)",
" { perror(\"mkdir\");",
" Uerror(\"aborting\");",
" }",
"}",
"void",
"bfs_disk_stop(void)", /* remove .spin */
"{",
" if (system(\"rm -fr .spin\") < 0)",
" { perror(\"rm -fr .spin/\");",
" }",
"}",
"void",
"bfs_disk_inp(void)", /* this core only */
"{ int i; char fnm[16];",
"#ifdef VERBOSE",
" bfs_printf(\"inp %%d %%d 0..%%d\\n\", bfs_toggle, who_am_i, Cores);",
"#endif",
" for (i = 0; i < Cores; i++)",
" { sprintf(fnm, \".spin/q%%d_%%d_%%d\", bfs_toggle, who_am_i, i);",
" if ((bfs_inp_fd[i] = open(fnm, 0444)) < 0)",
" { perror(\"open\");",
" Uerror(fnm);",
" } }",
"}",
"void",
"bfs_disk_out(void)", /* this core only */
"{ int i; char fnm[16];",
"#ifdef VERBOSE",
" bfs_printf(\"out %%d 0..%%d %%d\\n\", 1-bfs_toggle, Cores, who_am_i);",
"#endif",
" shared_memory->bfs_out_cnt[who_am_i] = 0;",
" for (i = 0; i < Cores; i++)",
" { sprintf(fnm, \".spin/q%%d_%%d_%%d\", 1-bfs_toggle, i, who_am_i);",
" if ((bfs_out_fd[i] = creat(fnm, 0666)) < 0)",
" { perror(\"creat\");",
" Uerror(fnm);",
" } }",
"}",
"void",
"bfs_disk_iclose(void)",
"{ int i;",
"#ifdef VERBOSE",
" bfs_printf(\"close_inp\\n\");",
"#endif",
" for (i = 0; i < Cores; i++)",
" { if (close(bfs_inp_fd[i]) < 0)",
" { perror(\"iclose\");",
" } }",
"}",
"void",
"bfs_disk_oclose(void)",
"{ int i;",
"#ifdef VERBOSE",
" bfs_printf(\"close_out\\n\");",
"#endif",
" for (i = 0; i < Cores; i++)",
" { if (fsync(bfs_out_fd[i]) < 0)",
" { perror(\"fsync\");",
" }",
" if (close(bfs_out_fd[i]) < 0)",
" { perror(\"oclose\");",
" } }",
"}",
"#endif",
"void",
"bfs_write_snap(int fd)",
"{ if (write(fd, snap, strlen(snap)) != strlen(snap))",
" { printf(\"pan: error writing %%s\\n\", fnm);",
" bfs_shutdown(\"file system error\");",
" }",
"}",
"",
"void",
"bfs_one_step(BFS_Trail *t, int fd)",
"{ if (t && t->t_id != (T_ID) -1)",
" { sprintf(snap, \"%%d:%%d:%%d\\n\",",
" trcnt++, t->pr, t->t_id);",
" bfs_write_snap(fd);",
" }",
"}",
"",
"void",
"bfs_putter(BFS_Trail *t, int fd)",
"{ if (t && t != (BFS_Trail *) t->ostate)",
" bfs_putter((BFS_Trail *) t->ostate, fd);",
"#ifdef L_BOUND",
" if (depthfound == trcnt)",
" { strcpy(snap, \"-1:-1:-1\\n\");",
" bfs_write_snap(fd);",
" depthfound = -1;",
" }",
"#endif",
" bfs_one_step(t, fd);",
"}",
"",
"void",
"bfs_nuerror(char *str)",
"{ int fd = make_trail();",
"",
" if (fd < 0) return;",
"#ifdef VERI",
" sprintf(snap, \"-2:%%d:-2\\n\", (uchar) ((P0 *)pptr(0))->_t);",
" bfs_write_snap(fd);",
"#endif",
"#ifdef MERGED",
" sprintf(snap, \"-4:-4:-4\\n\");",
" bfs_write_snap(fd);",
"#endif",
" trcnt = 1;",
" if (strstr(str, \"invalid\"))",
" { bfs_putter((BFS_Trail *) trpt->ostate, fd);",
" } else",
" { BFS_Trail x;",
" memset((char *) &x, 0, sizeof(BFS_Trail));",
" x.pr = trpt->pr;",
" x.t_id = (trpt->o_t)?trpt->o_t->t_id:0;",
" x.ostate = trpt->ostate;",
" bfs_putter(&x, fd);",
" }",
" close(fd);",
" if (errors >= upto && upto != 0)",
" { bfs_shutdown(str);",
" }",
"}",
"",
"void",
"bfs_uerror(char *str)",
"{ static char laststr[256];",
"",
" errors++;",
" if (strncmp(str, laststr, 254) != 0)",
" { bfs_printf(\"pan:%%lu: %%s (at depth %%ld)\\n\",",
" errors, str, ((depthfound == -1)?depth:depthfound));",
" strncpy(laststr, str, 254);",
" }",
"#ifdef HAS_CODE",
" if (readtrail) { wrap_trail(); return; }",
"#endif",
" if (every_error != 0 || errors == upto)",
" { bfs_nuerror(str);",
" }",
" if (errors >= upto && upto != 0)",
" { bfs_shutdown(\"bfs_uerror\");",
" }",
" depthfound = -1;",
"}\n",
"void",
"bfs_Uerror(char *str)",
"{ /* bfs_uerror(str); */",
" bfs_printf(\"pan:%%lu: %%s (at depth %%ld)\\n\", ++errors, str,",
" ((depthfound == -1)?depth:depthfound));",
" bfs_shutdown(\"bfs_Uerror\");",
"}",
0,
};
|