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
|
<center><a href="https://gitlab.com/petsc/petsc/-/blob/966382dc56242773704ef5f5cee7aa2db3ebc577/include/petscmacros.h">Actual source code: petscmacros.h</a></center><br>
<html>
<head>
<title></title>
<meta name="generator" content="c2html 0.9.6">
<meta name="date" content="2025-04-30T18:14:50+00:00">
</head>
<body bgcolor="#FFFFFF">
<pre width=80>
<a name="line1"> 1: </a><font color="#A020F0">#pragma once</font>
<a name="line3"> 3: </a><font color="#A020F0">#include <petscconf.h></font>
<a name="line4"> 4: </a><font color="#A020F0">#include <petscconf_poison.h> </font><font color="#B22222">/* for <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>() error checking */</font><font color="#A020F0"></font>
<a name="line6"> 6: </a><font color="#B22222">/* SUBMANSEC = Sys */</font>
<a name="line8"> 8: </a><font color="#A020F0">#if defined(__cplusplus)</font>
<a name="line9"> 9: </a><font color="#A020F0"> #if __cplusplus <= 201103L</font>
<a name="line10"> 10: </a><strong><font color="#228B22"> #define PETSC_CPP_VERSION 11</font></strong>
<a name="line11"> 11: </a><font color="#A020F0"> #elif __cplusplus <= 201402L</font>
<a name="line12"> 12: </a><strong><font color="#228B22"> #define PETSC_CPP_VERSION 14</font></strong>
<a name="line13"> 13: </a><font color="#A020F0"> #elif __cplusplus <= 201703L</font>
<a name="line14"> 14: </a><strong><font color="#228B22"> #define PETSC_CPP_VERSION 17</font></strong>
<a name="line15"> 15: </a><font color="#A020F0"> #elif __cplusplus <= 202002L</font>
<a name="line16"> 16: </a><strong><font color="#228B22"> #define PETSC_CPP_VERSION 20</font></strong>
<a name="line17"> 17: </a><font color="#A020F0"> #else</font>
<a name="line18"> 18: </a><strong><font color="#228B22"> #define PETSC_CPP_VERSION 22 // current year, or date of c++2b ratification</font></strong>
<a name="line19"> 19: </a><font color="#A020F0"> #endif</font>
<a name="line20"> 20: </a><font color="#A020F0">#endif // __cplusplus</font>
<a name="line22"> 22: </a><font color="#A020F0">#ifndef PETSC_CPP_VERSION</font>
<a name="line23"> 23: </a><strong><font color="#228B22"> #define PETSC_CPP_VERSION 0</font></strong>
<a name="line24"> 24: </a><font color="#A020F0">#endif</font>
<a name="line26"> 26: </a><font color="#A020F0">#if defined(__STDC_VERSION__)</font>
<a name="line27"> 27: </a><font color="#A020F0"> #if __STDC_VERSION__ <= 199901L</font>
<a name="line28"> 28: </a> <font color="#B22222">// C99 except that 99 is >= 11 or 17 so we shorten it to 9 instead</font>
<a name="line29"> 29: </a><strong><font color="#228B22"> #define PETSC_C_VERSION 9</font></strong>
<a name="line30"> 30: </a><font color="#A020F0"> #elif __STDC_VERSION__ <= 201112L</font>
<a name="line31"> 31: </a><strong><font color="#228B22"> #define PETSC_C_VERSION 11</font></strong>
<a name="line32"> 32: </a><font color="#A020F0"> #elif __STDC_VERSION__ <= 201710L</font>
<a name="line33"> 33: </a><strong><font color="#228B22"> #define PETSC_C_VERSION 17</font></strong>
<a name="line34"> 34: </a><font color="#A020F0"> #else</font>
<a name="line35"> 35: </a><strong><font color="#228B22"> #define PETSC_C_VERSION 22 // current year, or date of c2b ratification</font></strong>
<a name="line36"> 36: </a><font color="#A020F0"> #endif</font>
<a name="line37"> 37: </a><font color="#A020F0">#endif // __STDC_VERSION__</font>
<a name="line39"> 39: </a><font color="#A020F0">#ifndef PETSC_C_VERSION</font>
<a name="line40"> 40: </a><strong><font color="#228B22"> #define PETSC_C_VERSION 0</font></strong>
<a name="line41"> 41: </a><font color="#A020F0">#endif</font>
<a name="line43"> 43: </a><font color="#B22222">/* ========================================================================== */</font>
<a name="line44"> 44: </a><font color="#B22222">/* This facilitates using the C version of PETSc from C++ and the C++ version from C. */</font>
<a name="line45"> 45: </a><font color="#A020F0">#if defined(__cplusplus)</font>
<a name="line46"> 46: </a><strong><font color="#228B22"> #define PETSC_FUNCTION_NAME PETSC_FUNCTION_NAME_CXX</font></strong>
<a name="line47"> 47: </a><font color="#A020F0">#else</font>
<a name="line48"> 48: </a><strong><font color="#228B22"> #define PETSC_FUNCTION_NAME PETSC_FUNCTION_NAME_C</font></strong>
<a name="line49"> 49: </a><font color="#A020F0">#endif</font>
<a name="line51"> 51: </a><font color="#B22222">/* ========================================================================== */</font>
<a name="line52"> 52: </a><font color="#B22222">/* Since PETSc manages its own extern "C" handling users should never include PETSc include</font>
<a name="line53"> 53: </a><font color="#B22222"> * files within extern "C". This will generate a compiler error if a user does put the include</font>
<a name="line54"> 54: </a><font color="#B22222"> * file within an extern "C".</font>
<a name="line55"> 55: </a><font color="#B22222"> */</font>
<a name="line56"> 56: </a><font color="#A020F0">#if defined(__cplusplus)</font>
<a name="line57"> 57: </a><strong><font color="#4169E1">void assert_never_put_petsc_headers_inside_an_extern_c(int)</font></strong>;
<a name="line58"> 58: </a><strong><font color="#4169E1">void assert_never_put_petsc_headers_inside_an_extern_c(double)</font></strong>;
<a name="line59"> 59: </a><font color="#A020F0">#endif</font>
<a name="line61"> 61: </a><font color="#A020F0">#if defined(__cplusplus)</font>
<a name="line62"> 62: </a><strong><font color="#228B22"> #define PETSC_RESTRICT PETSC_CXX_RESTRICT</font></strong>
<a name="line63"> 63: </a><font color="#A020F0">#else</font>
<a name="line64"> 64: </a><strong><font color="#228B22"> #define PETSC_RESTRICT restrict</font></strong>
<a name="line65"> 65: </a><font color="#A020F0">#endif</font>
<a name="line67"> 67: </a><strong><font color="#228B22">#define PETSC_INLINE PETSC_DEPRECATED_MACRO(3, 17, 0, </font><font color="#666666">"inline"</font><font color="#228B22">, ) inline</font></strong>
<a name="line68"> 68: </a><strong><font color="#228B22">#define PETSC_STATIC_INLINE PETSC_DEPRECATED_MACRO(3, 17, 0, </font><font color="#666666">"static inline"</font><font color="#228B22">, ) static inline</font></strong>
<a name="line70"> 70: </a><font color="#A020F0">#if defined(_WIN32) && defined(PETSC_USE_SHARED_LIBRARIES) </font><font color="#B22222">/* For Win32 shared libraries */</font><font color="#A020F0"></font>
<a name="line71"> 71: </a><strong><font color="#228B22"> #define __declspec(dllexport)</font></strong>
<a name="line72"> 72: </a><strong><font color="#228B22"> #define PETSC_DLLIMPORT __declspec(dllimport)</font></strong>
<a name="line73"> 73: </a><strong><font color="#228B22"> #define PETSC_VISIBILITY_INTERNAL</font></strong>
<a name="line74"> 74: </a><font color="#A020F0">#elif defined(__cplusplus) && defined(PETSC_USE_VISIBILITY_CXX)</font>
<a name="line75"> 75: </a><strong><font color="#228B22"> #define __attribute__((visibility(</font><font color="#666666">"default"</font><font color="#228B22">)))</font></strong>
<a name="line76"> 76: </a><strong><font color="#228B22"> #define PETSC_DLLIMPORT __attribute__((visibility(</font><font color="#666666">"default"</font><font color="#228B22">)))</font></strong>
<a name="line77"> 77: </a><strong><font color="#228B22"> #define PETSC_VISIBILITY_INTERNAL __attribute__((visibility(</font><font color="#666666">"hidden"</font><font color="#228B22">)))</font></strong>
<a name="line78"> 78: </a><font color="#A020F0">#elif !defined(__cplusplus) && defined(PETSC_USE_VISIBILITY_C)</font>
<a name="line79"> 79: </a><strong><font color="#228B22"> #define __attribute__((visibility(</font><font color="#666666">"default"</font><font color="#228B22">)))</font></strong>
<a name="line80"> 80: </a><strong><font color="#228B22"> #define PETSC_DLLIMPORT __attribute__((visibility(</font><font color="#666666">"default"</font><font color="#228B22">)))</font></strong>
<a name="line81"> 81: </a><strong><font color="#228B22"> #define PETSC_VISIBILITY_INTERNAL __attribute__((visibility(</font><font color="#666666">"hidden"</font><font color="#228B22">)))</font></strong>
<a name="line82"> 82: </a><font color="#A020F0">#else</font>
<a name="line83"> 83: </a><strong><font color="#228B22"> #define </font></strong>
<a name="line84"> 84: </a><strong><font color="#228B22"> #define PETSC_DLLIMPORT</font></strong>
<a name="line85"> 85: </a><strong><font color="#228B22"> #define PETSC_VISIBILITY_INTERNAL</font></strong>
<a name="line86"> 86: </a><font color="#A020F0">#endif</font>
<a name="line88"> 88: </a><font color="#A020F0">#if defined(petsc_EXPORTS) </font><font color="#B22222">/* CMake defines this when building the shared library */</font><font color="#A020F0"></font>
<a name="line89"> 89: </a><strong><font color="#228B22"> #define PETSC_VISIBILITY_PUBLIC </font></strong>
<a name="line90"> 90: </a><font color="#A020F0">#else </font><font color="#B22222">/* Win32 users need this to import symbols from petsc.dll */</font><font color="#A020F0"></font>
<a name="line91"> 91: </a><strong><font color="#228B22"> #define PETSC_VISIBILITY_PUBLIC PETSC_DLLIMPORT</font></strong>
<a name="line92"> 92: </a><font color="#A020F0">#endif</font>
<a name="line94"> 94: </a><font color="#B22222">/* Functions tagged with PETSC_EXTERN in the header files are always defined as extern "C" when</font>
<a name="line95"> 95: </a><font color="#B22222"> * compiled with C++ so they may be used from C and are always visible in the shared libraries</font>
<a name="line96"> 96: </a><font color="#B22222"> */</font>
<a name="line97"> 97: </a><font color="#A020F0">#if defined(__cplusplus)</font>
<a name="line98"> 98: </a><strong><font color="#228B22"> #define PETSC_EXTERN extern </font><font color="#666666">"C"</font><font color="#228B22"> PETSC_VISIBILITY_PUBLIC</font></strong>
<a name="line99"> 99: </a><strong><font color="#228B22"> #define PETSC_EXTERN_TYPEDEF extern </font><font color="#666666">"C"</font><font color="#228B22"></font></strong>
<a name="line100">100: </a><strong><font color="#228B22"> #define PETSC_INTERN extern </font><font color="#666666">"C"</font><font color="#228B22"> PETSC_VISIBILITY_INTERNAL</font></strong>
<a name="line101">101: </a><font color="#A020F0">#else</font>
<a name="line102">102: </a><strong><font color="#228B22"> #define PETSC_EXTERN extern PETSC_VISIBILITY_PUBLIC</font></strong>
<a name="line103">103: </a><strong><font color="#228B22"> #define PETSC_EXTERN_TYPEDEF</font></strong>
<a name="line104">104: </a><strong><font color="#228B22"> #define PETSC_INTERN extern PETSC_VISIBILITY_INTERNAL</font></strong>
<a name="line105">105: </a><font color="#A020F0">#endif</font>
<a name="line107">107: </a><font color="#A020F0">#if defined(PETSC_USE_SINGLE_LIBRARY)</font>
<a name="line108">108: </a><strong><font color="#228B22"> #define PETSC_SINGLE_LIBRARY_VISIBILITY_INTERNAL PETSC_VISIBILITY_INTERNAL</font></strong>
<a name="line109">109: </a><strong><font color="#228B22"> #define PETSC_SINGLE_LIBRARY_INTERN PETSC_INTERN</font></strong>
<a name="line110">110: </a><font color="#A020F0">#else</font>
<a name="line111">111: </a><strong><font color="#228B22"> #define PETSC_SINGLE_LIBRARY_VISIBILITY_INTERNAL PETSC_VISIBILITY_PUBLIC</font></strong>
<a name="line112">112: </a><strong><font color="#228B22"> #define PETSC_SINGLE_LIBRARY_INTERN PETSC_EXTERN</font></strong>
<a name="line113">113: </a><font color="#A020F0">#endif</font>
<a name="line117">117: </a><font color="#A020F0">#endif</font>
<a name="line119">119: </a><font color="#B22222">/*MC</font>
<a name="line120">120: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a> - Determine whether a particular __attribute__ is supported by the compiler</font>
<a name="line122">122: </a><font color="#B22222"> Synopsis:</font>
<a name="line123">123: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line124">124: </a><font color="#B22222"> int <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(name)</font>
<a name="line126">126: </a><font color="#B22222"> Input Parameter:</font>
<a name="line127">127: </a><font color="#B22222">. name - The name of the attribute to test</font>
<a name="line129">129: </a><font color="#B22222"> Level: intermediate</font>
<a name="line131">131: </a><font color="#B22222"> Notes:</font>
<a name="line132">132: </a><font color="#B22222"> name should be identical to what you might pass to the __attribute__ declaration itself --</font>
<a name="line133">133: </a><font color="#B22222"> plain, unbroken text.</font>
<a name="line135">135: </a><font color="#B22222"> As `<a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>()` is wrapper over the function-like macro `__has_attribute()`, the</font>
<a name="line136">136: </a><font color="#B22222"> exact type and value returned is implementation defined. In practice however, it usually</font>
<a name="line137">137: </a><font color="#B22222"> returns `1` if the attribute is supported and `0` if the attribute is not supported.</font>
<a name="line139">139: </a><font color="#B22222"> Example Usage:</font>
<a name="line140">140: </a><font color="#B22222"> Typical usage is using the preprocessor</font>
<a name="line142">142: </a><font color="#B22222">.vb</font>
<a name="line143">143: </a><font color="#B22222"> #if <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(always_inline)</font>
<a name="line144">144: </a><font color="#B22222"> # define MY_ALWAYS_INLINE __attribute__((always_inline))</font>
<a name="line145">145: </a><font color="#B22222"> #else</font>
<a name="line146">146: </a><font color="#B22222"> # define MY_ALWAYS_INLINE</font>
<a name="line147">147: </a><font color="#B22222"> #endif</font>
<a name="line149">149: </a><font color="#B22222"> void foo(void) MY_ALWAYS_INLINE;</font>
<a name="line150">150: </a><font color="#B22222">.ve</font>
<a name="line152">152: </a><font color="#B22222"> but it can also be used in regular code</font>
<a name="line154">154: </a><font color="#B22222">.vb</font>
<a name="line155">155: </a><font color="#B22222"> if (<a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(some_attribute)) {</font>
<a name="line156">156: </a><font color="#B22222"> foo();</font>
<a name="line157">157: </a><font color="#B22222"> } else {</font>
<a name="line158">158: </a><font color="#B22222"> bar();</font>
<a name="line159">159: </a><font color="#B22222"> }</font>
<a name="line160">160: </a><font color="#B22222">.ve</font>
<a name="line162">162: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>()`, `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()`, `<a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>()`, `<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>()`,</font>
<a name="line163">163: </a><font color="#B22222">`<a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a>`, `<a href="../manualpages/Sys/PETSC_ATTRIBUTE_MAY_ALIAS.html">PETSC_ATTRIBUTE_MAY_ALIAS</a>`</font>
<a name="line164">164: </a><font color="#B22222">M*/</font>
<a name="line167">167: </a><font color="#A020F0">#endif</font>
<a name="line168">168: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(name) __has_attribute(name)</font></strong>
<a name="line170">170: </a><font color="#B22222">/*MC</font>
<a name="line171">171: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a> - Determine whether a particular builtin method is supported by the compiler</font>
<a name="line173">173: </a><font color="#B22222"> Synopsis:</font>
<a name="line174">174: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line175">175: </a><font color="#B22222"> int <a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>(name)</font>
<a name="line177">177: </a><font color="#B22222"> Input Parameter:</font>
<a name="line178">178: </a><font color="#B22222">. name - the name of the builtin routine</font>
<a name="line180">180: </a><font color="#B22222"> Level: intermediate</font>
<a name="line182">182: </a><font color="#B22222"> Notes:</font>
<a name="line183">183: </a><font color="#B22222"> Evaluates to `1` if the builtin is supported and `0` otherwise. Note the term "evaluates"</font>
<a name="line184">184: </a><font color="#B22222"> (vs "expands") is deliberate; even though `<a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>()` is a macro the underlying</font>
<a name="line185">185: </a><font color="#B22222"> detector is itself is a compiler extension with implementation-defined return type and</font>
<a name="line186">186: </a><font color="#B22222"> semantics. Some compilers implement it as a macro, others as a compiler function. In practice</font>
<a name="line187">187: </a><font color="#B22222"> however, all supporting compilers return an integer boolean as described.</font>
<a name="line189">189: </a><font color="#B22222"> Example Usage:</font>
<a name="line190">190: </a><font color="#B22222"> Typical usage is in preprocessor directives</font>
<a name="line192">192: </a><font color="#B22222">.vb</font>
<a name="line193">193: </a><font color="#B22222"> #if <a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>(__builtin_trap)</font>
<a name="line194">194: </a><font color="#B22222"> __builtin_trap();</font>
<a name="line195">195: </a><font color="#B22222"> #else</font>
<a name="line196">196: </a><font color="#B22222"> abort();</font>
<a name="line197">197: </a><font color="#B22222"> #endif</font>
<a name="line198">198: </a><font color="#B22222">.ve</font>
<a name="line200">200: </a><font color="#B22222"> But it may also be used in regular code</font>
<a name="line202">202: </a><font color="#B22222">.vb</font>
<a name="line203">203: </a><font color="#B22222"> if (<a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>(__builtin_alloca)) {</font>
<a name="line204">204: </a><font color="#B22222"> foo();</font>
<a name="line205">205: </a><font color="#B22222"> } else {</font>
<a name="line206">206: </a><font color="#B22222"> bar();</font>
<a name="line207">207: </a><font color="#B22222"> }</font>
<a name="line208">208: </a><font color="#B22222">.ve</font>
<a name="line210">210: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>()`, `<a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>()`</font>
<a name="line211">211: </a><font color="#B22222">M*/</font>
<a name="line214">214: </a><font color="#A020F0">#endif</font>
<a name="line215">215: </a><font color="#B22222">// clangs __has_builtin prior to clang 10 did not properly handle non-function builtins such as</font>
<a name="line216">216: </a><font color="#B22222">// __builtin_types_compatible_p which take types or other non-functiony things as</font>
<a name="line217">217: </a><font color="#B22222">// arguments. The correct way to detect these then is to use __is_identifier (also a clang</font>
<a name="line218">218: </a><font color="#B22222">// extension). GCC has always worked as expected. see https://stackoverflow.com/a/45043153</font>
<a name="line219">219: </a><font color="#A020F0">#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ < 10) && defined(__is_identifier)</font>
<a name="line220">220: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>(name) __is_identifier(name)</font></strong>
<a name="line221">221: </a><font color="#A020F0">#else</font>
<a name="line222">222: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>(name) __has_builtin(name)</font></strong>
<a name="line223">223: </a><font color="#A020F0">#endif</font>
<a name="line225">225: </a><font color="#A020F0">#if !defined(PETSC_SKIP_ATTRIBUTE_MPI_TYPE_TAG)</font>
<a name="line226">226: </a> <font color="#B22222">/*</font>
<a name="line227">227: </a><font color="#B22222"> Support for Clang (>=3.2) matching type tag arguments with void* buffer types.</font>
<a name="line228">228: </a><font color="#B22222"> This allows the compiler to detect cases where the MPI datatype argument passed to a MPI routine</font>
<a name="line229">229: </a><font color="#B22222"> does not match the actual type of the argument being passed in</font>
<a name="line230">230: </a><font color="#B22222">*/</font>
<a name="line231">231: </a><font color="#A020F0"> #if <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(pointer_with_type_tag)</font>
<a name="line232">232: </a><strong><font color="#228B22"> #define PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(bufno, typeno) __attribute__((pointer_with_type_tag(MPI, bufno, typeno)))</font></strong>
<a name="line233">233: </a><font color="#A020F0"> #endif</font>
<a name="line235">235: </a><font color="#A020F0"> #if <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(type_tag_for_datatype)</font>
<a name="line236">236: </a><strong><font color="#228B22"> #define PETSC_ATTRIBUTE_MPI_TYPE_TAG(type) __attribute__((type_tag_for_datatype(MPI, type)))</font></strong>
<a name="line237">237: </a><strong><font color="#228B22"> #define PETSC_ATTRIBUTE_MPI_TYPE_TAG_LAYOUT_COMPATIBLE(type) __attribute__((type_tag_for_datatype(MPI, type, layout_compatible)))</font></strong>
<a name="line238">238: </a><font color="#A020F0"> #endif</font>
<a name="line239">239: </a><font color="#A020F0">#endif // PETSC_SKIP_ATTRIBUTE_MPI_TYPE_TAG</font>
<a name="line241">241: </a><font color="#A020F0">#ifndef PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE</font>
<a name="line242">242: </a><strong><font color="#228B22"> #define PETSC_ATTRIBUTE_MPI_POINTER_WITH_TYPE(bufno, typeno)</font></strong>
<a name="line243">243: </a><font color="#A020F0">#endif</font>
<a name="line245">245: </a><font color="#A020F0">#ifndef PETSC_ATTRIBUTE_MPI_TYPE_TAG</font>
<a name="line246">246: </a><strong><font color="#228B22"> #define PETSC_ATTRIBUTE_MPI_TYPE_TAG(type)</font></strong>
<a name="line247">247: </a><font color="#A020F0">#endif</font>
<a name="line249">249: </a><font color="#A020F0">#ifndef PETSC_ATTRIBUTE_MPI_TYPE_TAG_LAYOUT_COMPATIBLE</font>
<a name="line250">250: </a><strong><font color="#228B22"> #define PETSC_ATTRIBUTE_MPI_TYPE_TAG_LAYOUT_COMPATIBLE(type)</font></strong>
<a name="line251">251: </a><font color="#A020F0">#endif</font>
<a name="line253">253: </a><font color="#B22222">/*MC</font>
<a name="line254">254: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a> - Indicate to the compiler that specified arguments should be treated</font>
<a name="line255">255: </a><font color="#B22222"> as format specifiers and checked for validity</font>
<a name="line257">257: </a><font color="#B22222"> Synopsis:</font>
<a name="line258">258: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line259">259: </a><font color="#B22222"> <attribute declaration> <a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a>(int strIdx, int vaArgIdx)</font>
<a name="line261">261: </a><font color="#B22222"> Input Parameters:</font>
<a name="line262">262: </a><font color="#B22222">+ strIdx - The (1-indexed) location of the format string in the argument list</font>
<a name="line263">263: </a><font color="#B22222">- vaArgIdx - The (1-indexed) location of the first formattable argument in the argument list</font>
<a name="line265">265: </a><font color="#B22222"> Level: developer</font>
<a name="line267">267: </a><font color="#B22222"> Notes:</font>
<a name="line268">268: </a><font color="#B22222"> This function attribute causes the compiler to issue warnings when the format specifier does</font>
<a name="line269">269: </a><font color="#B22222"> not match the type of the variable that will be formatted, or when there exists a mismatch</font>
<a name="line270">270: </a><font color="#B22222"> between the number of format specifiers and variables to be formatted. It is safe to use this</font>
<a name="line271">271: </a><font color="#B22222"> macro if your compiler does not support format specifier checking (though this is</font>
<a name="line272">272: </a><font color="#B22222"> exceeedingly rare).</font>
<a name="line274">274: </a><font color="#B22222"> Both `strIdx` and `vaArgIdx` must be compile-time constant integer literals and cannot have the</font>
<a name="line275">275: </a><font color="#B22222"> same value.</font>
<a name="line277">277: </a><font color="#B22222"> The arguments to be formatted (and therefore checked by the compiler) must be "contiguous" in</font>
<a name="line278">278: </a><font color="#B22222"> the argument list, that is, there is no way to indicate gaps which should not be checked.</font>
<a name="line280">280: </a><font color="#B22222"> Definition is suppressed by defining `PETSC_SKIP_ATTRIBUTE_FORMAT` prior to including PETSc</font>
<a name="line281">281: </a><font color="#B22222"> header files. In this case the macro will expand empty.</font>
<a name="line283">283: </a><font color="#B22222"> Example Usage:</font>
<a name="line284">284: </a><font color="#B22222">.vb</font>
<a name="line285">285: </a><font color="#B22222"> // format string is 2nd argument, variable argument list containing args is 3rd argument</font>
<a name="line286">286: </a><font color="#B22222"> void my_printf(void *obj, const char *fmt_string, ...) <a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a>(2,3)</font>
<a name="line288">288: </a><font color="#B22222"> int x = 1;</font>
<a name="line289">289: </a><font color="#B22222"> double y = 50.0;</font>
<a name="line291">291: </a><font color="#B22222"> my_printf(NULL,"%g",x); // WARNING, format specifier does not match for 'int'!</font>
<a name="line292">292: </a><font color="#B22222"> my_printf(NULL,"%d",x,y); // WARNING, more arguments than format specifiers!</font>
<a name="line293">293: </a><font color="#B22222"> my_printf(NULL,"%d %g",x,y); // OK</font>
<a name="line294">294: </a><font color="#B22222">.ve</font>
<a name="line296">296: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a>`, `<a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>()`</font>
<a name="line297">297: </a><font color="#B22222">M*/</font>
<a name="line298">298: </a><font color="#A020F0">#if <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(format) && !defined(PETSC_SKIP_ATTRIBUTE_FORMAT)</font>
<a name="line299">299: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a>(strIdx, vaArgIdx) __attribute__((format(printf, strIdx, vaArgIdx)))</font></strong>
<a name="line300">300: </a><font color="#A020F0">#else</font>
<a name="line301">301: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a>(strIdx, vaArgIdx)</font></strong>
<a name="line302">302: </a><font color="#A020F0">#endif</font>
<a name="line304">304: </a><font color="#B22222">/*MC</font>
<a name="line305">305: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a> - Indicate to the compiler that a function is very unlikely to be</font>
<a name="line306">306: </a><font color="#B22222"> executed</font>
<a name="line308">308: </a><font color="#B22222"> Level: intermediate</font>
<a name="line310">310: </a><font color="#B22222"> Notes:</font>
<a name="line311">311: </a><font color="#B22222"> The marked function is often optimized for size rather than speed and may be grouped alongside</font>
<a name="line312">312: </a><font color="#B22222"> other equally frigid routines improving code locality of lukewarm or hotter parts of program.</font>
<a name="line314">314: </a><font color="#B22222"> The paths leading to cold functions are usually automatically marked as unlikely by the</font>
<a name="line315">315: </a><font color="#B22222"> compiler. It may thus be useful to mark functions used to handle unlikely conditions -- such</font>
<a name="line316">316: </a><font color="#B22222"> as error handlers -- as cold to improve optimization of the surrounding temperate functions.</font>
<a name="line318">318: </a><font color="#B22222"> Example Usage:</font>
<a name="line319">319: </a><font color="#B22222">.vb</font>
<a name="line320">320: </a><font color="#B22222"> void my_error_handler(...) <a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a>;</font>
<a name="line322">322: </a><font color="#B22222"> if (temperature < 0) {</font>
<a name="line323">323: </a><font color="#B22222"> return my_error_handler(...); // chilly!</font>
<a name="line324">324: </a><font color="#B22222"> }</font>
<a name="line325">325: </a><font color="#B22222">.ve</font>
<a name="line327">327: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>()`, `<a href="../manualpages/Sys/PetscUnlikelyDebug.html">PetscUnlikelyDebug</a>()`, `<a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>()`, `PetscLikelyDebug()`,</font>
<a name="line328">328: </a><font color="#B22222"> `<a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>()`, `<a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a>`</font>
<a name="line329">329: </a><font color="#B22222">M*/</font>
<a name="line330">330: </a><font color="#A020F0">#if <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(__cold__)</font>
<a name="line331">331: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a> __attribute__((__cold__))</font></strong>
<a name="line332">332: </a><font color="#A020F0">#elif <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(cold) </font><font color="#B22222">/* some implementations (old gcc) use no underscores */</font><font color="#A020F0"></font>
<a name="line333">333: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a> __attribute__((cold))</font></strong>
<a name="line334">334: </a><font color="#A020F0">#else</font>
<a name="line335">335: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a></font></strong>
<a name="line336">336: </a><font color="#A020F0">#endif</font>
<a name="line338">338: </a><font color="#B22222">/*MC</font>
<a name="line339">339: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_ATTRIBUTE_MAY_ALIAS.html">PETSC_ATTRIBUTE_MAY_ALIAS</a> - Indicate to the compiler that a type is not</font>
<a name="line340">340: </a><font color="#B22222"> subjected to type-based alias analysis, but is instead assumed to be able to</font>
<a name="line341">341: </a><font color="#B22222"> alias any other type of objects</font>
<a name="line343">343: </a><font color="#B22222"> Example Usage:</font>
<a name="line344">344: </a><font color="#B22222">.vb</font>
<a name="line345">345: </a><font color="#B22222"> typedef <a href="../manualpages/Sys/PetscScalar.html">PetscScalar</a> PetscScalarAlias <a href="../manualpages/Sys/PETSC_ATTRIBUTE_MAY_ALIAS.html">PETSC_ATTRIBUTE_MAY_ALIAS</a>;</font>
<a name="line347">347: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscReal.html">PetscReal</a> *pointer;</font>
<a name="line348">348: </a><font color="#B22222"> PetscScalarAlias *other_pointer = reinterpret_cast<PetscScalarAlias *>(pointer);</font>
<a name="line349">349: </a><font color="#B22222">.ve</font>
<a name="line351">351: </a><font color="#B22222"> Level: advanced</font>
<a name="line353">353: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>()`</font>
<a name="line354">354: </a><font color="#B22222">M*/</font>
<a name="line355">355: </a><font color="#A020F0">#if <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(may_alias) && !defined(PETSC_SKIP_ATTRIBUTE_MAY_ALIAS)</font>
<a name="line356">356: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_ATTRIBUTE_MAY_ALIAS.html">PETSC_ATTRIBUTE_MAY_ALIAS</a> __attribute__((may_alias))</font></strong>
<a name="line357">357: </a><font color="#A020F0">#else</font>
<a name="line358">358: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_ATTRIBUTE_MAY_ALIAS.html">PETSC_ATTRIBUTE_MAY_ALIAS</a></font></strong>
<a name="line359">359: </a><font color="#A020F0">#endif</font>
<a name="line361">361: </a><font color="#B22222">/*MC</font>
<a name="line362">362: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a> - Standard way of indicating a null value or pointer</font>
<a name="line364">364: </a><font color="#B22222"> No Fortran Support</font>
<a name="line366">366: </a><font color="#B22222"> Level: beginner</font>
<a name="line368">368: </a><font color="#B22222"> Notes:</font>
<a name="line369">369: </a><font color="#B22222"> Equivalent to `NULL` in C source, and `nullptr` in C++ source. Note that for the purposes of</font>
<a name="line370">370: </a><font color="#B22222"> interoperability between C and C++, setting a pointer to `<a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>` in C++ is functonially</font>
<a name="line371">371: </a><font color="#B22222"> equivalent to setting the same pointer to `NULL` in C. That is to say that the following</font>
<a name="line372">372: </a><font color="#B22222"> expressions are equivalent\:</font>
<a name="line374">374: </a><font color="#B22222">.vb</font>
<a name="line375">375: </a><font color="#B22222"> ptr == <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a></font>
<a name="line376">376: </a><font color="#B22222"> ptr == NULL</font>
<a name="line377">377: </a><font color="#B22222"> ptr == 0</font>
<a name="line378">378: </a><font color="#B22222"> !ptr</font>
<a name="line380">380: </a><font color="#B22222"> ptr = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a></font>
<a name="line381">381: </a><font color="#B22222"> ptr = NULL</font>
<a name="line382">382: </a><font color="#B22222"> ptr = 0</font>
<a name="line383">383: </a><font color="#B22222">.ve</font>
<a name="line385">385: </a><font color="#B22222"> and for completeness' sake\:</font>
<a name="line387">387: </a><font color="#B22222">.vb</font>
<a name="line388">388: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a> == NULL</font>
<a name="line389">389: </a><font color="#B22222">.ve</font>
<a name="line391">391: </a><font color="#B22222"> Example Usage:</font>
<a name="line392">392: </a><font color="#B22222">.vb</font>
<a name="line393">393: </a><font color="#B22222"> // may be used in place of '\0' or other such terminators in the definition of char arrays</font>
<a name="line394">394: </a><font color="#B22222"> const char *const MyEnumTypes[] = {</font>
<a name="line395">395: </a><font color="#B22222"> "foo",</font>
<a name="line396">396: </a><font color="#B22222"> "bar",</font>
<a name="line397">397: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a></font>
<a name="line398">398: </a><font color="#B22222"> };</font>
<a name="line400">400: </a><font color="#B22222"> // may be used to nullify objects</font>
<a name="line401">401: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscObject.html">PetscObject</a> obj = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>;</font>
<a name="line403">403: </a><font color="#B22222"> // may be used in any function expecting NULL</font>
<a name="line404">404: </a><font color="#B22222"> <a href="../manualpages/Log/PetscInfo.html">PetscInfo</a>(<a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>,"Lorem Ipsum Dolor");</font>
<a name="line405">405: </a><font color="#B22222">.ve</font>
<a name="line407">407: </a><font color="#B22222"> Developer Notes:</font>
<a name="line408">408: </a><font color="#B22222"> `<a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>` must be used in place of `NULL` in all C++ source files. Using `NULL` in source</font>
<a name="line409">409: </a><font color="#B22222"> files compiled with a C++ compiler may lead to unexpected side-effects in function overload</font>
<a name="line410">410: </a><font color="#B22222"> resolution and/or compiler warnings.</font>
<a name="line412">412: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PETSC_CONSTEXPR_14.html">PETSC_CONSTEXPR_14</a>`, `<a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a>`</font>
<a name="line413">413: </a><font color="#B22222">M*/</font>
<a name="line415">415: </a><font color="#B22222">/*MC</font>
<a name="line416">416: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_CONSTEXPR_14.html">PETSC_CONSTEXPR_14</a> - C++14 constexpr</font>
<a name="line418">418: </a><font color="#B22222"> No Fortran Support</font>
<a name="line420">420: </a><font color="#B22222"> Level: beginner</font>
<a name="line422">422: </a><font color="#B22222"> Notes:</font>
<a name="line423">423: </a><font color="#B22222"> Equivalent to `constexpr` when using a C++ compiler that supports C++14. Expands to nothing</font>
<a name="line424">424: </a><font color="#B22222"> if the C++ compiler does not support C++14 or when not compiling with a C++ compiler. Note</font>
<a name="line425">425: </a><font color="#B22222"> that this cannot be used in cases where an empty expansion would result in invalid code. It</font>
<a name="line426">426: </a><font color="#B22222"> is safe to use this in C source files.</font>
<a name="line428">428: </a><font color="#B22222"> Example Usage:</font>
<a name="line429">429: </a><font color="#B22222">.vb</font>
<a name="line430">430: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_CONSTEXPR_14.html">PETSC_CONSTEXPR_14</a> int factorial(int n)</font>
<a name="line431">431: </a><font color="#B22222"> {</font>
<a name="line432">432: </a><font color="#B22222"> int r = 1;</font>
<a name="line434">434: </a><font color="#B22222"> do {</font>
<a name="line435">435: </a><font color="#B22222"> r *= n;</font>
<a name="line436">436: </a><font color="#B22222"> } while (--n);</font>
<a name="line437">437: </a><font color="#B22222"> return r;</font>
<a name="line438">438: </a><font color="#B22222"> }</font>
<a name="line439">439: </a><font color="#B22222">.ve</font>
<a name="line441">441: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>`, `<a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a>`</font>
<a name="line442">442: </a><font color="#B22222">M*/</font>
<a name="line444">444: </a><font color="#B22222">/*MC</font>
<a name="line445">445: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a> - Mark the return value of a function as non-discardable</font>
<a name="line447">447: </a><font color="#B22222"> Not available in Fortran</font>
<a name="line449">449: </a><font color="#B22222"> Level: beginner</font>
<a name="line451">451: </a><font color="#B22222"> Notes:</font>
<a name="line452">452: </a><font color="#B22222"> Hints to the compiler that the return value of a function must be captured. A diagnostic may</font>
<a name="line453">453: </a><font color="#B22222"> (but is not required to) be emitted if the value is discarded. It is safe to use this in both</font>
<a name="line454">454: </a><font color="#B22222"> C and C++ source files.</font>
<a name="line456">456: </a><font color="#B22222"> In this context "captured" means assigning the return value of a function to a named</font>
<a name="line457">457: </a><font color="#B22222"> variable or casting it to `void`. Between the two, assigning to a named variable is the most</font>
<a name="line458">458: </a><font color="#B22222"> portable way of silencing any warnings, since `<a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a>` may expand to GCC's</font>
<a name="line459">459: </a><font color="#B22222"> `__attribute__((warn_unused_result))` which will still emit warnings when casting results to</font>
<a name="line460">460: </a><font color="#B22222"> `void`.</font>
<a name="line462">462: </a><font color="#B22222"> Example Usage:</font>
<a name="line463">463: </a><font color="#B22222">.vb</font>
<a name="line464">464: </a><font color="#B22222"> class Foo</font>
<a name="line465">465: </a><font color="#B22222"> {</font>
<a name="line466">466: </a><font color="#B22222"> int x;</font>
<a name="line468">468: </a><font color="#B22222"> public:</font>
<a name="line469">469: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a> Foo(int y) : x(y) { }</font>
<a name="line470">470: </a><font color="#B22222"> };</font>
<a name="line472">472: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a> int factorial(int n)</font>
<a name="line473">473: </a><font color="#B22222"> {</font>
<a name="line474">474: </a><font color="#B22222"> return n <= 1 ? 1 : (n * factorial(n - 1));</font>
<a name="line475">475: </a><font color="#B22222"> }</font>
<a name="line477">477: </a><font color="#B22222"> factorial(10); // Warning: ignoring return value of function declared 'nodiscard'</font>
<a name="line478">478: </a><font color="#B22222"> auto x = factorial(10); // OK, capturing return value</font>
<a name="line479">479: </a><font color="#B22222"> (void)factorial(10); // Maybe OK, casting to void</font>
<a name="line480">480: </a><font color="#B22222"> auto y = factorial(10); // OK, capturing in y (and casting y to void to silence</font>
<a name="line481">481: </a><font color="#B22222"> (void)y; // set-but-not-used warnings)</font>
<a name="line483">483: </a><font color="#B22222"> Foo(x); // Warning: Ignoring temporary created by a constructor declared 'nodiscard'</font>
<a name="line484">484: </a><font color="#B22222"> auto f = Foo(x); // OK, capturing constructed object</font>
<a name="line485">485: </a><font color="#B22222"> (void)Foo(x); // Maybe OK, casting to void</font>
<a name="line486">486: </a><font color="#B22222"> auto g = Foo(x); // OK, capturing in g (and casting g to void to silence set-but-not-used</font>
<a name="line487">487: </a><font color="#B22222"> (void)g; // warnings)</font>
<a name="line488">488: </a><font color="#B22222">.ve</font>
<a name="line490">490: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>`, `<a href="../manualpages/Sys/PETSC_CONSTEXPR_14.html">PETSC_CONSTEXPR_14</a>`</font>
<a name="line491">491: </a><font color="#B22222">M*/</font>
<a name="line493">493: </a><font color="#B22222">/* C++11 features */</font>
<a name="line494">494: </a><font color="#A020F0">#if defined(__cplusplus) || (PETSC_C_VERSION >= 23)</font>
<a name="line495">495: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a> nullptr</font></strong>
<a name="line496">496: </a><font color="#A020F0">#else</font>
<a name="line497">497: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a> NULL</font></strong>
<a name="line498">498: </a><font color="#A020F0">#endif</font>
<a name="line500">500: </a><font color="#B22222">/* C++14 features */</font>
<a name="line501">501: </a><font color="#A020F0">#if PETSC_CPP_VERSION >= 14</font>
<a name="line502">502: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_CONSTEXPR_14.html">PETSC_CONSTEXPR_14</a> constexpr</font></strong>
<a name="line503">503: </a><font color="#A020F0">#else</font>
<a name="line504">504: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_CONSTEXPR_14.html">PETSC_CONSTEXPR_14</a></font></strong>
<a name="line505">505: </a><font color="#A020F0">#endif</font>
<a name="line507">507: </a><font color="#B22222">/* C++17 features */</font>
<a name="line508">508: </a><font color="#A020F0">#if PETSC_CPP_VERSION >= 17</font>
<a name="line509">509: </a><strong><font color="#228B22"> #define PETSC_CONSTEXPR_17 constexpr</font></strong>
<a name="line510">510: </a><font color="#A020F0">#else</font>
<a name="line511">511: </a><strong><font color="#228B22"> #define PETSC_CONSTEXPR_17</font></strong>
<a name="line512">512: </a><font color="#A020F0">#endif</font>
<a name="line514">514: </a><font color="#A020F0">#if (PETSC_CPP_VERSION >= 17) || (PETSC_C_VERSION >= 23)</font>
<a name="line515">515: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a> [[nodiscard]]</font></strong>
<a name="line516">516: </a><font color="#A020F0">#elif <a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>(warn_unused_result)</font>
<a name="line517">517: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a> __attribute__((warn_unused_result))</font></strong>
<a name="line518">518: </a><font color="#A020F0">#else</font>
<a name="line519">519: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_NODISCARD.html">PETSC_NODISCARD</a></font></strong>
<a name="line520">520: </a><font color="#A020F0">#endif</font>
<a name="line522">522: </a>#include <A href="../include/petscversion.h.html"><petscversion.h></A>
<a name="line523">523: </a><strong><font color="#228B22">#define PETSC_AUTHOR_INFO </font><font color="#666666">" The PETSc Team\n petsc-maint@mcs.anl.gov\n https://petsc.org/\n"</font><font color="#228B22"></font></strong>
<a name="line525">525: </a><font color="#B22222">/* designated initializers since C99 and C++20, MSVC never supports them though */</font>
<a name="line526">526: </a><font color="#A020F0">#if defined(_MSC_VER) || (defined(__cplusplus) && (PETSC_CPP_VERSION < 20))</font>
<a name="line527">527: </a><strong><font color="#228B22"> #define PetscDesignatedInitializer(name, ...) __VA_ARGS__</font></strong>
<a name="line528">528: </a><font color="#A020F0">#else</font>
<a name="line529">529: </a><strong><font color="#228B22"> #define PetscDesignatedInitializer(name, ...) .name = __VA_ARGS__</font></strong>
<a name="line530">530: </a><font color="#A020F0">#endif</font>
<a name="line532">532: </a><font color="#B22222">/*MC</font>
<a name="line533">533: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a> - Hints the compiler that the given condition is usually false</font>
<a name="line535">535: </a><font color="#B22222"> Synopsis:</font>
<a name="line536">536: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line537">537: </a><font color="#B22222"> bool <a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(bool cond)</font>
<a name="line539">539: </a><font color="#B22222"> Not Collective; No Fortran Support</font>
<a name="line541">541: </a><font color="#B22222"> Input Parameter:</font>
<a name="line542">542: </a><font color="#B22222">. cond - Boolean expression</font>
<a name="line544">544: </a><font color="#B22222"> Level: advanced</font>
<a name="line546">546: </a><font color="#B22222"> Note:</font>
<a name="line547">547: </a><font color="#B22222"> This returns the same truth value, it is only a hint to compilers that the result of cond is</font>
<a name="line548">548: </a><font color="#B22222"> unlikely to be true.</font>
<a name="line550">550: </a><font color="#B22222"> Example usage:</font>
<a name="line551">551: </a><font color="#B22222">.vb</font>
<a name="line552">552: </a><font color="#B22222"> if (<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(cond)) {</font>
<a name="line553">553: </a><font color="#B22222"> foo(); // cold path</font>
<a name="line554">554: </a><font color="#B22222"> } else {</font>
<a name="line555">555: </a><font color="#B22222"> bar(); // hot path</font>
<a name="line556">556: </a><font color="#B22222"> }</font>
<a name="line557">557: </a><font color="#B22222">.ve</font>
<a name="line559">559: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>()`, `<a href="../manualpages/Sys/PetscUnlikelyDebug.html">PetscUnlikelyDebug</a>()`, `<a href="../manualpages/Sys/PetscCall.html">PetscCall</a>()`, `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()`, `<a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>()`,</font>
<a name="line560">560: </a><font color="#B22222"> `<a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a>`</font>
<a name="line561">561: </a><font color="#B22222">M*/</font>
<a name="line563">563: </a><font color="#B22222">/*MC</font>
<a name="line564">564: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a> - Hints the compiler that the given condition is usually true</font>
<a name="line566">566: </a><font color="#B22222"> Synopsis:</font>
<a name="line567">567: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line568">568: </a><font color="#B22222"> bool <a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>(bool cond)</font>
<a name="line570">570: </a><font color="#B22222"> Not Collective; No Fortran Support</font>
<a name="line572">572: </a><font color="#B22222"> Input Parameter:</font>
<a name="line573">573: </a><font color="#B22222">. cond - Boolean expression</font>
<a name="line575">575: </a><font color="#B22222"> Level: advanced</font>
<a name="line577">577: </a><font color="#B22222"> Note:</font>
<a name="line578">578: </a><font color="#B22222"> This returns the same truth value, it is only a hint to compilers that the result of cond is</font>
<a name="line579">579: </a><font color="#B22222"> likely to be true.</font>
<a name="line581">581: </a><font color="#B22222"> Example usage:</font>
<a name="line582">582: </a><font color="#B22222">.vb</font>
<a name="line583">583: </a><font color="#B22222"> if (<a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>(cond)) {</font>
<a name="line584">584: </a><font color="#B22222"> foo(); // hot path</font>
<a name="line585">585: </a><font color="#B22222"> } else {</font>
<a name="line586">586: </a><font color="#B22222"> bar(); // cold path</font>
<a name="line587">587: </a><font color="#B22222"> }</font>
<a name="line588">588: </a><font color="#B22222">.ve</font>
<a name="line590">590: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>()`, `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()`, `<a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>()`</font>
<a name="line591">591: </a><font color="#B22222"> `<a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a>`</font>
<a name="line592">592: </a><font color="#B22222">M*/</font>
<a name="line593">593: </a><font color="#A020F0">#if defined(PETSC_HAVE_BUILTIN_EXPECT)</font>
<a name="line594">594: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(cond) __builtin_expect(!!(cond), 0)</font></strong>
<a name="line595">595: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>(cond) __builtin_expect(!!(cond), 1)</font></strong>
<a name="line596">596: </a><font color="#A020F0">#else</font>
<a name="line597">597: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(cond) (cond)</font></strong>
<a name="line598">598: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>(cond) (cond)</font></strong>
<a name="line599">599: </a><font color="#A020F0">#endif</font>
<a name="line601">601: </a><font color="#B22222">/*MC</font>
<a name="line602">602: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a> - Indicate to the compiler that a code-path is logically unreachable</font>
<a name="line604">604: </a><font color="#B22222"> Synopsis:</font>
<a name="line605">605: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line606">606: </a><font color="#B22222"> void <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>(void)</font>
<a name="line608">608: </a><font color="#B22222"> Level: advanced</font>
<a name="line610">610: </a><font color="#B22222"> Note:</font>
<a name="line611">611: </a><font color="#B22222"> Indicates to the compiler (usually via some built-in) that a particular code path is always</font>
<a name="line612">612: </a><font color="#B22222"> unreachable. Behavior is undefined if this function is ever executed, the user can expect an</font>
<a name="line613">613: </a><font color="#B22222"> unceremonious crash.</font>
<a name="line615">615: </a><font color="#B22222"> Example usage:</font>
<a name="line616">616: </a><font color="#B22222"> Useful in situations such as switches over enums where not all enumeration values are</font>
<a name="line617">617: </a><font color="#B22222"> explicitly covered by the switch</font>
<a name="line619">619: </a><font color="#B22222">.vb</font>
<a name="line621">621: </a><font color="#B22222"> int foo(Color c)</font>
<a name="line622">622: </a><font color="#B22222"> {</font>
<a name="line623">623: </a><font color="#B22222"> // it is known to programmer (or checked previously) that c is either RED or GREEN</font>
<a name="line624">624: </a><font color="#B22222"> // but compiler may not be able to deduce this and/or emit spurious warnings</font>
<a name="line625">625: </a><font color="#B22222"> switch (c) {</font>
<a name="line626">626: </a><font color="#B22222"> case RED:</font>
<a name="line627">627: </a><font color="#B22222"> return bar();</font>
<a name="line628">628: </a><font color="#B22222"> case GREEN:</font>
<a name="line629">629: </a><font color="#B22222"> return baz();</font>
<a name="line630">630: </a><font color="#B22222"> default:</font>
<a name="line631">631: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>(); // program is ill-formed if executed</font>
<a name="line632">632: </a><font color="#B22222"> }</font>
<a name="line633">633: </a><font color="#B22222"> }</font>
<a name="line634">634: </a><font color="#B22222">.ve</font>
<a name="line636">636: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/SETERRABORT.html">SETERRABORT</a>()`, `<a href="../manualpages/Sys/PETSCABORT.html">PETSCABORT</a>()`, `<a href="../manualpages/Sys/PETSC_ATTRIBUTE_COLD.html">PETSC_ATTRIBUTE_COLD</a>`, `<a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>()`</font>
<a name="line637">637: </a><font color="#B22222">M*/</font>
<a name="line638">638: </a><font color="#A020F0">#if PETSC_CPP_VERSION >= 23</font>
<a name="line639">639: </a><font color="#A020F0"> #include <utility></font>
<a name="line640">640: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>() std::unreachable()</font></strong>
<a name="line641">641: </a><font color="#A020F0">#elif defined(__GNUC__)</font>
<a name="line642">642: </a> <font color="#B22222">/* GCC 4.8+, Clang, Intel and other compilers compatible with GCC (-std=c++0x or above) */</font>
<a name="line643">643: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>() __builtin_unreachable()</font></strong>
<a name="line644">644: </a><font color="#A020F0">#elif defined(_MSC_VER) </font><font color="#B22222">/* MSVC */</font><font color="#A020F0"></font>
<a name="line645">645: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>() __assume(0)</font></strong>
<a name="line646">646: </a><font color="#A020F0">#else </font><font color="#B22222">/* ??? */</font><font color="#A020F0"></font>
<a name="line647">647: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>() <a href="../manualpages/Sys/SETERRABORT.html">SETERRABORT</a>(<a href="../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, </font><font color="#666666">"Code path explicitly marked as unreachable executed"</font><font color="#228B22">)</font></strong>
<a name="line648">648: </a><font color="#A020F0">#endif</font>
<a name="line650">650: </a><font color="#B22222">/*MC</font>
<a name="line651">651: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a> - Indicate to the compiler a condition that is defined to be true</font>
<a name="line653">653: </a><font color="#B22222"> Synopsis:</font>
<a name="line654">654: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line655">655: </a><font color="#B22222"> void <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(bool cond)</font>
<a name="line657">657: </a><font color="#B22222"> Input Parameter:</font>
<a name="line658">658: </a><font color="#B22222">. cond - Boolean expression</font>
<a name="line660">660: </a><font color="#B22222"> Level: advanced</font>
<a name="line662">662: </a><font color="#B22222"> Notes:</font>
<a name="line663">663: </a><font color="#B22222"> If supported by the compiler, `cond` is used to inform the optimizer of an invariant</font>
<a name="line664">664: </a><font color="#B22222"> truth. The argument itself is never evaluated, so any side effects of the expression will be</font>
<a name="line665">665: </a><font color="#B22222"> discarded. This macro is used in `<a href="../manualpages/Sys/PetscAssert.html">PetscAssert</a>()` to retain information gained from debug</font>
<a name="line666">666: </a><font color="#B22222"> checks that would be lost in optimized builds. For example\:</font>
<a name="line668">668: </a><font color="#B22222">.vb</font>
<a name="line669">669: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> foo(<a href="../manualpages/Sys/PetscInt.html">PetscInt</a> x) {</font>
<a name="line671">671: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscAssert.html">PetscAssert</a>(x >= 0, ...);</font>
<a name="line672">672: </a><font color="#B22222"> }</font>
<a name="line673">673: </a><font color="#B22222">.ve</font>
<a name="line675">675: </a><font color="#B22222"> The assertion checks that `x` is positive when debugging is enabled (and returns from `foo()`</font>
<a name="line676">676: </a><font color="#B22222"> if it is not). This implicitly informs the optimizer that `x` cannot be negative. However,</font>
<a name="line677">677: </a><font color="#B22222"> when debugging is disabled any `<a href="../manualpages/Sys/PetscAssert.html">PetscAssert</a>()` checks are tautologically false, and hence the</font>
<a name="line678">678: </a><font color="#B22222"> optimizer cannot deduce any information from them.</font>
<a name="line680">680: </a><font color="#B22222"> Due to compiler limitations `<a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>()` works best when `cond` involves</font>
<a name="line681">681: </a><font color="#B22222"> constants. Certain compilers do not yet propagate symbolic inequalities i.e.\:</font>
<a name="line683">683: </a><font color="#B22222">.vb</font>
<a name="line684">684: </a><font color="#B22222"> int a, b, var_five;</font>
<a name="line686">686: </a><font color="#B22222"> // BEST, all supporting compilers will understand a cannot be >= 5</font>
<a name="line687">687: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(a < 5);</font>
<a name="line689">689: </a><font color="#B22222"> // OK, some compilers may understand that a cannot be >= 5</font>
<a name="line690">690: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(a <= b && b < 5);</font>
<a name="line692">692: </a><font color="#B22222"> // WORST, most compilers will not get the memo</font>
<a name="line693">693: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(a <= b && b < var_five);</font>
<a name="line694">694: </a><font color="#B22222">.ve</font>
<a name="line696">696: </a><font color="#B22222"> If the condition is violated at runtime then behavior is wholly undefined. If the</font>
<a name="line697">697: </a><font color="#B22222"> condition is violated at compile-time, the condition "supersedes" the compile-time violation</font>
<a name="line698">698: </a><font color="#B22222"> and the program is ill-formed, no diagnostic required. For example consider the following\:</font>
<a name="line700">700: </a><font color="#B22222">.vb</font>
<a name="line701">701: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscInt.html">PetscInt</a> x = 0;</font>
<a name="line703">703: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(x != 0);</font>
<a name="line704">704: </a><font color="#B22222"> if (x == 0) {</font>
<a name="line705">705: </a><font color="#B22222"> x += 10;</font>
<a name="line706">706: </a><font color="#B22222"> } else {</font>
<a name="line707">707: </a><font color="#B22222"> popen("rm -rf /", "w");</font>
<a name="line708">708: </a><font color="#B22222"> }</font>
<a name="line709">709: </a><font color="#B22222">.ve</font>
<a name="line711">711: </a><font color="#B22222"> Even though `x` is demonstrably `0` the compiler may opt to\:</font>
<a name="line713">713: </a><font color="#B22222"> - emit an unconditional `popen("rm -rf /", "w")`</font>
<a name="line714">714: </a><font color="#B22222"> - ignore `<a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>()` altogether and emit the correct path of `x += 10`</font>
<a name="line715">715: </a><font color="#B22222"> - reformat the primary disk partition</font>
<a name="line717">717: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscAssert.html">PetscAssert</a>()`</font>
<a name="line718">718: </a><font color="#B22222">M*/</font>
<a name="line719">719: </a><font color="#A020F0">#if PETSC_CPP_VERSION >= 23</font>
<a name="line720">720: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(...) [[assume(__VA_ARGS__)]]</font></strong>
<a name="line721">721: </a><font color="#A020F0">#elif defined(_MSC_VER) // msvc</font>
<a name="line722">722: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(...) __assume(__VA_ARGS__)</font></strong>
<a name="line723">723: </a><font color="#A020F0">#elif defined(__clang__) && <a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>(__builtin_assume) // clang</font>
<a name="line724">724: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(...) \</font></strong>
<a name="line725">725: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line726">726: </a><strong><font color="#228B22"> _Pragma(</font><font color="#666666">"clang diagnostic push"</font><font color="#228B22">); \</font></strong>
<a name="line727">727: </a><strong><font color="#228B22"> _Pragma(</font><font color="#666666">"clang diagnostic ignored \"-Wassume\""</font><font color="#228B22">); \</font></strong>
<a name="line728">728: </a><strong><font color="#228B22"> __builtin_assume(__VA_ARGS__); \</font></strong>
<a name="line729">729: </a><strong><font color="#228B22"> _Pragma(</font><font color="#666666">"clang diagnostic pop"</font><font color="#228B22">); \</font></strong>
<a name="line730">730: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line731">731: </a><font color="#A020F0">#else // gcc (and really old clang)</font>
<a name="line732">732: </a> <font color="#B22222">// gcc does not have its own __builtin_assume() intrinsic. One could fake it via</font>
<a name="line733">733: </a> <font color="#B22222">//</font>
<a name="line734">734: </a> <font color="#B22222">// if (<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(!cond)) <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>();</font>
<a name="line735">735: </a> <font color="#B22222">//</font>
<a name="line736">736: </a> <font color="#B22222">// but this it unsavory because the side effects of cond are not guaranteed to be</font>
<a name="line737">737: </a> <font color="#B22222">// discarded. Though in most circumstances gcc will optimize out the if (because any evaluation</font>
<a name="line738">738: </a> <font color="#B22222">// for which cond is false would be undefined results in undefined behavior anyway) it cannot</font>
<a name="line739">739: </a> <font color="#B22222">// always do so. This is especially the case for opaque or non-inline function calls:</font>
<a name="line740">740: </a> <font color="#B22222">//</font>
<a name="line741">741: </a> <font color="#B22222">// extern int bar(int);</font>
<a name="line742">742: </a> <font color="#B22222">//</font>
<a name="line743">743: </a> <font color="#B22222">// int foo(int x) {</font>
<a name="line744">744: </a> <font color="#B22222">// <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(bar(x) == 2);</font>
<a name="line745">745: </a> <font color="#B22222">// if (bar(x) == 2) {</font>
<a name="line746">746: </a> <font color="#B22222">// return 1;</font>
<a name="line747">747: </a> <font color="#B22222">// } else {</font>
<a name="line748">748: </a> <font color="#B22222">// return 0;</font>
<a name="line749">749: </a> <font color="#B22222">// }</font>
<a name="line750">750: </a> <font color="#B22222">// }</font>
<a name="line751">751: </a> <font color="#B22222">//</font>
<a name="line752">752: </a> <font color="#B22222">// Here gcc would (if just using builtin_expect()) emit 2 calls to bar(). Note we still have</font>
<a name="line753">753: </a> <font color="#B22222">// cond "tested" in the condition, but this is done to silence unused-but-set variable warnings</font>
<a name="line754">754: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscAssume.html">PetscAssume</a>(...) \</font></strong>
<a name="line755">755: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line756">756: </a><strong><font color="#228B22"> if (0 && (__VA_ARGS__)) <a href="../manualpages/Sys/PetscUnreachable.html">PetscUnreachable</a>(); \</font></strong>
<a name="line757">757: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line758">758: </a><font color="#A020F0">#endif</font>
<a name="line760">760: </a><font color="#B22222">/*MC</font>
<a name="line761">761: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscExpand.html">PetscExpand</a> - Expand macro argument</font>
<a name="line763">763: </a><font color="#B22222"> Synopsis:</font>
<a name="line764">764: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line765">765: </a><font color="#B22222"> <macro-expansion> <a href="../manualpages/Sys/PetscExpand.html">PetscExpand</a>(x)</font>
<a name="line767">767: </a><font color="#B22222"> Input Parameter:</font>
<a name="line768">768: </a><font color="#B22222">. x - The preprocessor token to expand</font>
<a name="line770">770: </a><font color="#B22222"> Level: beginner</font>
<a name="line772">772: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>()`, `<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>()`</font>
<a name="line773">773: </a><font color="#B22222">M*/</font>
<a name="line774">774: </a><strong><font color="#228B22">#define PetscExpand_(...) __VA_ARGS__</font></strong>
<a name="line775">775: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscExpand.html">PetscExpand</a>(...) PetscExpand_(__VA_ARGS__)</font></strong>
<a name="line777">777: </a><font color="#B22222">/*MC</font>
<a name="line778">778: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a> - Stringize a token</font>
<a name="line780">780: </a><font color="#B22222"> Synopsis:</font>
<a name="line781">781: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line782">782: </a><font color="#B22222"> const char* <a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(x)</font>
<a name="line784">784: </a><font color="#B22222"> No Fortran Support</font>
<a name="line786">786: </a><font color="#B22222"> Input Parameter:</font>
<a name="line787">787: </a><font color="#B22222">. x - The token you would like to stringize</font>
<a name="line789">789: </a><font color="#B22222"> Output Parameter:</font>
<a name="line790">790: </a><font color="#B22222">. <return-value> - The string representation of `x`</font>
<a name="line792">792: </a><font color="#B22222"> Level: beginner</font>
<a name="line794">794: </a><font color="#B22222"> Note:</font>
<a name="line795">795: </a><font color="#B22222"> `<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>()` expands `x` before stringizing it, if you do not wish to do so, use</font>
<a name="line796">796: </a><font color="#B22222"> `PetscStringize_()` instead.</font>
<a name="line798">798: </a><font color="#B22222"> Example Usage:</font>
<a name="line799">799: </a><font color="#B22222">.vb</font>
<a name="line800">800: </a><font color="#B22222"> #define MY_OTHER_VAR hello there</font>
<a name="line801">801: </a><font color="#B22222"> #define MY_VAR MY_OTHER_VAR</font>
<a name="line803">803: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(MY_VAR) -> "hello there"</font>
<a name="line804">804: </a><font color="#B22222"> PetscStringize_(MY_VAR) -> "MY_VAR"</font>
<a name="line806">806: </a><font color="#B22222"> int foo;</font>
<a name="line807">807: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(foo) -> "foo"</font>
<a name="line808">808: </a><font color="#B22222"> PetscStringize_(foo) -> "foo"</font>
<a name="line809">809: </a><font color="#B22222">.ve</font>
<a name="line811">811: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>()`, `<a href="../manualpages/Sys/PetscExpandToNothing.html">PetscExpandToNothing</a>()`, `<a href="../manualpages/Sys/PetscExpand.html">PetscExpand</a>()`</font>
<a name="line812">812: </a><font color="#B22222">M*/</font>
<a name="line813">813: </a><strong><font color="#228B22">#define PetscStringize_(...) #__VA_ARGS__</font></strong>
<a name="line814">814: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(...) PetscStringize_(__VA_ARGS__)</font></strong>
<a name="line816">816: </a><font color="#B22222">/*MC</font>
<a name="line817">817: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a> - Concatenate two tokens</font>
<a name="line819">819: </a><font color="#B22222"> Synopsis:</font>
<a name="line820">820: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line821">821: </a><font color="#B22222"> <macro-expansion> <a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>(x, y)</font>
<a name="line823">823: </a><font color="#B22222"> No Fortran Support</font>
<a name="line825">825: </a><font color="#B22222"> Input Parameters:</font>
<a name="line826">826: </a><font color="#B22222">+ x - First token</font>
<a name="line827">827: </a><font color="#B22222">- y - Second token</font>
<a name="line829">829: </a><font color="#B22222"> Level: beginner</font>
<a name="line831">831: </a><font color="#B22222"> Note:</font>
<a name="line832">832: </a><font color="#B22222"> `<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>()` will expand both arguments before pasting them together, use `PetscConcat_()`</font>
<a name="line833">833: </a><font color="#B22222"> if you don't want to expand them.</font>
<a name="line835">835: </a><font color="#B22222"> Example usage:</font>
<a name="line836">836: </a><font color="#B22222">.vb</font>
<a name="line837">837: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>(hello,there) -> hellothere</font>
<a name="line839">839: </a><font color="#B22222"> #define HELLO hello</font>
<a name="line840">840: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>(HELLO,there) -> hellothere</font>
<a name="line841">841: </a><font color="#B22222"> PetscConcat_(HELLO,there) -> HELLOthere</font>
<a name="line842">842: </a><font color="#B22222">.ve</font>
<a name="line844">844: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>()`, `<a href="../manualpages/Sys/PetscExpand.html">PetscExpand</a>()`</font>
<a name="line845">845: </a><font color="#B22222">M*/</font>
<a name="line846">846: </a><strong><font color="#228B22">#define PetscConcat_(x, y) x##y</font></strong>
<a name="line847">847: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>(x, y) PetscConcat_(x, y)</font></strong>
<a name="line849">849: </a><strong><font color="#228B22">#define PETSC_INTERNAL_COMPL_0 1</font></strong>
<a name="line850">850: </a><strong><font color="#228B22">#define PETSC_INTERNAL_COMPL_1 0</font></strong>
<a name="line852">852: </a><font color="#B22222">/*MC</font>
<a name="line853">853: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscCompl.html">PetscCompl</a> - Expands to the integer complement of its argument</font>
<a name="line855">855: </a><font color="#B22222"> Synopsis:</font>
<a name="line856">856: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line857">857: </a><font color="#B22222"> int <a href="../manualpages/Sys/PetscCompl.html">PetscCompl</a>(b)</font>
<a name="line859">859: </a><font color="#B22222"> No Fortran Support</font>
<a name="line861">861: </a><font color="#B22222"> Input Parameter:</font>
<a name="line862">862: </a><font color="#B22222">. b - Preprocessor variable, must expand to either integer literal 0 or 1</font>
<a name="line864">864: </a><font color="#B22222"> Output Parameter:</font>
<a name="line865">865: </a><font color="#B22222">. <return-value> - Either integer literal 0 or 1</font>
<a name="line867">867: </a><font color="#B22222"> Level: beginner</font>
<a name="line869">869: </a><font color="#B22222"> Notes:</font>
<a name="line870">870: </a><font color="#B22222"> Expands to integer literal 0 if b expands to 1, or integer literal 1 if b expands to</font>
<a name="line871">871: </a><font color="#B22222"> 0. Behaviour is undefined if b expands to anything else. <a href="../manualpages/Sys/PetscCompl.html">PetscCompl</a>() will expand its</font>
<a name="line872">872: </a><font color="#B22222"> argument before returning the complement.</font>
<a name="line874">874: </a><font color="#B22222"> This macro can be useful for negating `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()` inside macros e.g.</font>
<a name="line875">875: </a><font color="#B22222">.vb</font>
<a name="line876">876: </a><font color="#B22222"> #define PETSC_DONT_HAVE_FOO <a href="../manualpages/Sys/PetscCompl.html">PetscCompl</a>(<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_FOO))</font>
<a name="line877">877: </a><font color="#B22222">.ve</font>
<a name="line879">879: </a><font color="#B22222"> Example usage:</font>
<a name="line880">880: </a><font color="#B22222">.vb</font>
<a name="line881">881: </a><font color="#B22222"> #define MY_VAR 1</font>
<a name="line882">882: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscCompl.html">PetscCompl</a>(MY_VAR) -> 0</font>
<a name="line884">884: </a><font color="#B22222"> #undef MY_VAR</font>
<a name="line885">885: </a><font color="#B22222"> #define MY_VAR 0</font>
<a name="line886">886: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscCompl.html">PetscCompl</a>(MY_VAR) -> 1</font>
<a name="line887">887: </a><font color="#B22222">.ve</font>
<a name="line889">889: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>()`, `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()`</font>
<a name="line890">890: </a><font color="#B22222">M*/</font>
<a name="line891">891: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscCompl.html">PetscCompl</a>(b) PetscConcat_(PETSC_INTERNAL_COMPL_, <a href="../manualpages/Sys/PetscExpand.html">PetscExpand</a>(b))</font></strong>
<a name="line893">893: </a><font color="#B22222">/*MC</font>
<a name="line894">894: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a> - Determine whether a boolean macro is defined</font>
<a name="line896">896: </a><font color="#B22222"> Synopsis:</font>
<a name="line897">897: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line898">898: </a><font color="#B22222"> int <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(def)</font>
<a name="line900">900: </a><font color="#B22222"> No Fortran Support</font>
<a name="line902">902: </a><font color="#B22222"> Input Parameter:</font>
<a name="line903">903: </a><font color="#B22222">. def - PETSc-style preprocessor variable (without PETSC_ prepended!)</font>
<a name="line905">905: </a><font color="#B22222"> Output Parameter:</font>
<a name="line906">906: </a><font color="#B22222">. <return-value> - Either integer literal 0 or 1</font>
<a name="line908">908: </a><font color="#B22222"> Level: intermediate</font>
<a name="line910">910: </a><font color="#B22222"> Notes:</font>
<a name="line911">911: </a><font color="#B22222"> `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()` returns 1 if and only if "PETSC_ ## def" is defined (but empty) or defined to</font>
<a name="line912">912: </a><font color="#B22222"> integer literal 1. In all other cases, `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()` returns integer literal 0. Therefore</font>
<a name="line913">913: </a><font color="#B22222"> this macro should not be used if its argument may be defined to a non-empty value other than</font>
<a name="line914">914: </a><font color="#B22222"> 1.</font>
<a name="line916">916: </a><font color="#B22222"> The prefix "PETSC_" is automatically prepended to def. To avoid prepending "PETSC_", say to</font>
<a name="line917">917: </a><font color="#B22222"> add custom checks in user code, one should use `PetscDefined_()`.</font>
<a name="line918">918: </a><font color="#B22222">.vb</font>
<a name="line919">919: </a><font color="#B22222"> #define FooDefined(d) PetscDefined_(<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>(FOO_, d))</font>
<a name="line920">920: </a><font color="#B22222">.ve</font>
<a name="line922">922: </a><font color="#B22222"> Developer Notes:</font>
<a name="line923">923: </a><font color="#B22222"> Getting something that works in C and CPP for an arg that may or may not be defined is</font>
<a name="line924">924: </a><font color="#B22222"> tricky. Here, if we have "#define PETSC_HAVE_BOOGER 1" we match on the placeholder define,</font>
<a name="line925">925: </a><font color="#B22222"> insert the "0," for arg1 and generate the triplet (0, 1, 0). Then the last step cherry picks</font>
<a name="line926">926: </a><font color="#B22222"> the 2nd arg (a one). When PETSC_HAVE_BOOGER is not defined, we generate a (... 1, 0) pair,</font>
<a name="line927">927: </a><font color="#B22222"> and when the last step cherry picks the 2nd arg, we get a zero.</font>
<a name="line929">929: </a><font color="#B22222"> Our extra expansion via PetscDefined__take_second_expand() is needed with MSVC, which has a</font>
<a name="line930">930: </a><font color="#B22222"> nonconforming implementation of variadic macros.</font>
<a name="line932">932: </a><font color="#B22222"> Example Usage:</font>
<a name="line933">933: </a><font color="#B22222"> Suppose you would like to call either "foo()" or "bar()" depending on whether PETSC_USE_DEBUG</font>
<a name="line934">934: </a><font color="#B22222"> is defined then</font>
<a name="line936">936: </a><font color="#B22222">.vb</font>
<a name="line937">937: </a><font color="#B22222"> #if <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(USE_DEBUG)</font>
<a name="line938">938: </a><font color="#B22222"> foo();</font>
<a name="line939">939: </a><font color="#B22222"> #else</font>
<a name="line940">940: </a><font color="#B22222"> bar();</font>
<a name="line941">941: </a><font color="#B22222"> #endif</font>
<a name="line943">943: </a><font color="#B22222"> // or alternatively within normal code</font>
<a name="line944">944: </a><font color="#B22222"> if (<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(USE_DEBUG)) {</font>
<a name="line945">945: </a><font color="#B22222"> foo();</font>
<a name="line946">946: </a><font color="#B22222"> } else {</font>
<a name="line947">947: </a><font color="#B22222"> bar();</font>
<a name="line948">948: </a><font color="#B22222"> }</font>
<a name="line949">949: </a><font color="#B22222">.ve</font>
<a name="line951">951: </a><font color="#B22222"> is equivalent to</font>
<a name="line953">953: </a><font color="#B22222">.vb</font>
<a name="line954">954: </a><font color="#B22222"> #if defined(PETSC_USE_DEBUG)</font>
<a name="line955">955: </a><font color="#B22222"> # if MY_DETECT_EMPTY_MACRO(PETSC_USE_DEBUG) // assuming you have such a macro</font>
<a name="line956">956: </a><font color="#B22222"> foo();</font>
<a name="line957">957: </a><font color="#B22222"> # elif PETSC_USE_DEBUG == 1</font>
<a name="line958">958: </a><font color="#B22222"> foo();</font>
<a name="line959">959: </a><font color="#B22222"> # else</font>
<a name="line960">960: </a><font color="#B22222"> bar();</font>
<a name="line961">961: </a><font color="#B22222"> # endif</font>
<a name="line962">962: </a><font color="#B22222"> #else</font>
<a name="line963">963: </a><font color="#B22222"> bar();</font>
<a name="line964">964: </a><font color="#B22222"> #endif</font>
<a name="line965">965: </a><font color="#B22222">.ve</font>
<a name="line967">967: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscHasAttribute.html">PetscHasAttribute</a>()`, `<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>()`, `<a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>()`, `<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>()`,</font>
<a name="line968">968: </a><font color="#B22222"> `<a href="../manualpages/Sys/PetscExpandToNothing.html">PetscExpandToNothing</a>()`, `<a href="../manualpages/Sys/PetscCompl.html">PetscCompl</a>()`</font>
<a name="line969">969: </a><font color="#B22222">M*/</font>
<a name="line970">970: </a><strong><font color="#228B22">#define PetscDefined_arg_1 shift,</font></strong>
<a name="line971">971: </a><strong><font color="#228B22">#define PetscDefined_arg_ shift,</font></strong>
<a name="line972">972: </a><strong><font color="#228B22">#define PetscDefined__take_second_expanded(ignored, val, ...) val</font></strong>
<a name="line973">973: </a><strong><font color="#228B22">#define PetscDefined__take_second_expand(args) PetscDefined__take_second_expanded args</font></strong>
<a name="line974">974: </a><strong><font color="#228B22">#define PetscDefined__take_second(...) PetscDefined__take_second_expand((__VA_ARGS__))</font></strong>
<a name="line975">975: </a><strong><font color="#228B22">#define PetscDefined__(arg1_or_junk) PetscDefined__take_second(arg1_or_junk 1, 0, at_)</font></strong>
<a name="line976">976: </a><strong><font color="#228B22">#define PetscDefined_(value) PetscDefined__(PetscConcat_(PetscDefined_arg_, value))</font></strong>
<a name="line977">977: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(def) PetscDefined_(<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>(PETSC_, def))</font></strong>
<a name="line979">979: </a><font color="#B22222">/*MC</font>
<a name="line980">980: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscUnlikelyDebug.html">PetscUnlikelyDebug</a> - Hints the compiler that the given condition is usually false, eliding</font>
<a name="line981">981: </a><font color="#B22222"> the check in optimized mode</font>
<a name="line983">983: </a><font color="#B22222"> Synopsis:</font>
<a name="line984">984: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line985">985: </a><font color="#B22222"> bool <a href="../manualpages/Sys/PetscUnlikelyDebug.html">PetscUnlikelyDebug</a>(bool cond)</font>
<a name="line987">987: </a><font color="#B22222"> Not Collective; No Fortran Support</font>
<a name="line989">989: </a><font color="#B22222"> Input Parameter:</font>
<a name="line990">990: </a><font color="#B22222">. cond - Boolean expression</font>
<a name="line992">992: </a><font color="#B22222"> Level: advanced</font>
<a name="line994">994: </a><font color="#B22222"> Note:</font>
<a name="line995">995: </a><font color="#B22222"> This returns the same truth value, it is only a hint to compilers that the result of `cond` is</font>
<a name="line996">996: </a><font color="#B22222"> likely to be false. When PETSc is compiled in optimized mode this will always return</font>
<a name="line997">997: </a><font color="#B22222"> false. Additionally, `cond` is guaranteed to not be evaluated when PETSc is compiled in</font>
<a name="line998">998: </a><font color="#B22222"> optimized mode.</font>
<a name="line1000">1000: </a><font color="#B22222"> Example usage:</font>
<a name="line1001">1001: </a><font color="#B22222"> This routine is shorthand for checking both the condition and whether <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(USE_DEBUG)</font>
<a name="line1002">1002: </a><font color="#B22222"> is true. So</font>
<a name="line1004">1004: </a><font color="#B22222">.vb</font>
<a name="line1005">1005: </a><font color="#B22222"> if (<a href="../manualpages/Sys/PetscUnlikelyDebug.html">PetscUnlikelyDebug</a>(cond)) {</font>
<a name="line1006">1006: </a><font color="#B22222"> foo();</font>
<a name="line1007">1007: </a><font color="#B22222"> } else {</font>
<a name="line1008">1008: </a><font color="#B22222"> bar();</font>
<a name="line1009">1009: </a><font color="#B22222"> }</font>
<a name="line1010">1010: </a><font color="#B22222">.ve</font>
<a name="line1012">1012: </a><font color="#B22222"> is equivalent to</font>
<a name="line1014">1014: </a><font color="#B22222">.vb</font>
<a name="line1015">1015: </a><font color="#B22222"> if (<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(USE_DEBUG)) {</font>
<a name="line1016">1016: </a><font color="#B22222"> if (<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(cond)) {</font>
<a name="line1017">1017: </a><font color="#B22222"> foo();</font>
<a name="line1018">1018: </a><font color="#B22222"> } else {</font>
<a name="line1019">1019: </a><font color="#B22222"> bar();</font>
<a name="line1020">1020: </a><font color="#B22222"> }</font>
<a name="line1021">1021: </a><font color="#B22222"> } else {</font>
<a name="line1022">1022: </a><font color="#B22222"> bar();</font>
<a name="line1023">1023: </a><font color="#B22222"> }</font>
<a name="line1024">1024: </a><font color="#B22222">.ve</font>
<a name="line1026">1026: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>()`, `<a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>()`, `<a href="../manualpages/Sys/PetscCall.html">PetscCall</a>()`, `<a href="../manualpages/Sys/SETERRQ.html">SETERRQ</a>`</font>
<a name="line1027">1027: </a><font color="#B22222">M*/</font>
<a name="line1028">1028: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscUnlikelyDebug.html">PetscUnlikelyDebug</a>(cond) (<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(USE_DEBUG) && <a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>(cond))</font></strong>
<a name="line1030">1030: </a><font color="#A020F0">#if defined(PETSC_CLANG_STATIC_ANALYZER)</font>
<a name="line1031">1031: </a> <font color="#B22222">// silence compiler warnings when using -pedantic, this is only used by the linter and it cares</font>
<a name="line1032">1032: </a> <font color="#B22222">// not what ISO C allows</font>
<a name="line1033">1033: </a><strong><font color="#228B22"> #define PetscMacroReturns_(retexpr, ...) \</font></strong>
<a name="line1034">1034: </a><strong><font color="#228B22"> __extension__({ \</font></strong>
<a name="line1035">1035: </a><strong><font color="#228B22"> __VA_ARGS__; \</font></strong>
<a name="line1036">1036: </a><strong><font color="#228B22"> retexpr; \</font></strong>
<a name="line1037">1037: </a><strong><font color="#228B22"> })</font></strong>
<a name="line1038">1038: </a><font color="#A020F0">#else</font>
<a name="line1039">1039: </a><strong><font color="#228B22"> #define PetscMacroReturns_(retexpr, ...) \</font></strong>
<a name="line1040">1040: </a><strong><font color="#228B22"> retexpr; \</font></strong>
<a name="line1041">1041: </a><strong><font color="#228B22"> do { \</font></strong>
<a name="line1042">1042: </a><strong><font color="#228B22"> __VA_ARGS__; \</font></strong>
<a name="line1043">1043: </a><strong><font color="#228B22"> } while (0)</font></strong>
<a name="line1044">1044: </a><font color="#A020F0">#endif</font>
<a name="line1046">1046: </a><font color="#B22222">/*MC</font>
<a name="line1047">1047: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscExpandToNothing.html">PetscExpandToNothing</a> - Expands to absolutely nothing</font>
<a name="line1049">1049: </a><font color="#B22222"> Synopsis:</font>
<a name="line1050">1050: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line1051">1051: </a><font color="#B22222"> void <a href="../manualpages/Sys/PetscExpandToNothing.html">PetscExpandToNothing</a>(...)</font>
<a name="line1053">1053: </a><font color="#B22222"> No Fortran Support</font>
<a name="line1055">1055: </a><font color="#B22222"> Input Parameter:</font>
<a name="line1056">1056: </a><font color="#B22222">. __VA_ARGS__ - Anything at all</font>
<a name="line1058">1058: </a><font color="#B22222"> Level: beginner</font>
<a name="line1060">1060: </a><font color="#B22222"> Note:</font>
<a name="line1061">1061: </a><font color="#B22222"> Must have at least 1 parameter.</font>
<a name="line1063">1063: </a><font color="#B22222"> Example usage:</font>
<a name="line1064">1064: </a><font color="#B22222">.vb</font>
<a name="line1065">1065: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscExpandToNothing.html">PetscExpandToNothing</a>(a,b,c) -> *nothing*</font>
<a name="line1066">1066: </a><font color="#B22222">.ve</font>
<a name="line1068">1068: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>()`, `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()`, `<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>()`, `<a href="../manualpages/Sys/PetscExpand.html">PetscExpand</a>()`</font>
<a name="line1069">1069: </a><font color="#B22222">M*/</font>
<a name="line1070">1070: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscExpandToNothing.html">PetscExpandToNothing</a>(...)</font></strong>
<a name="line1072">1072: </a><font color="#B22222">/*MC</font>
<a name="line1073">1073: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a> - Define a macro body that returns a value</font>
<a name="line1075">1075: </a><font color="#B22222"> Synopsis:</font>
<a name="line1076">1076: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line1077">1077: </a><font color="#B22222"> return_type <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a>(return_type retexpr, ...)</font>
<a name="line1079">1079: </a><font color="#B22222"> Input Parameters:</font>
<a name="line1080">1080: </a><font color="#B22222">+ retexpr - The value or expression that the macro should return</font>
<a name="line1081">1081: </a><font color="#B22222">- __VA_ARGS__ - The body of the macro</font>
<a name="line1083">1083: </a><font color="#B22222"> Level: intermediate</font>
<a name="line1085">1085: </a><font color="#B22222"> Notes:</font>
<a name="line1086">1086: </a><font color="#B22222"> Due to limitations of the C-preprocessor retexpr cannot depend on symbols declared in the</font>
<a name="line1087">1087: </a><font color="#B22222"> body of the macro and should not depend on values produced as a result of the expression. The</font>
<a name="line1088">1088: </a><font color="#B22222"> user should not assume that the result of this macro is equivalent to a single logical source</font>
<a name="line1089">1089: </a><font color="#B22222"> line. It is not portable to use macros defined using this one in conditional or loop bodies</font>
<a name="line1090">1090: </a><font color="#B22222"> without enclosing them in curly braces\:</font>
<a name="line1092">1092: </a><font color="#B22222">.vb</font>
<a name="line1093">1093: </a><font color="#B22222"> #define FOO(arg1) <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a>(0,arg1+=10) // returns 0</font>
<a name="line1095">1095: </a><font color="#B22222"> int err,x = 10;</font>
<a name="line1097">1097: </a><font color="#B22222"> if (...) err = FOO(x); // ERROR, body of FOO() executed outside the if statement</font>
<a name="line1098">1098: </a><font color="#B22222"> if (...) { err = FOO(x); } // OK</font>
<a name="line1100">1100: </a><font color="#B22222"> for (...) err = FOO(x); // ERROR, body of FOO() executed outside the loop</font>
<a name="line1101">1101: </a><font color="#B22222"> for (...) { err = FOO(x); } // OK</font>
<a name="line1102">1102: </a><font color="#B22222">.ve</font>
<a name="line1104">1104: </a><font color="#B22222"> It is also not portable to use this macro directly inside function call, conditional, loop,</font>
<a name="line1105">1105: </a><font color="#B22222"> or switch statements\:</font>
<a name="line1107">1107: </a><font color="#B22222">.vb</font>
<a name="line1108">1108: </a><font color="#B22222"> extern void bar(int);</font>
<a name="line1110">1110: </a><font color="#B22222"> int ret = FOO(x);</font>
<a name="line1112">1112: </a><font color="#B22222"> bar(FOO(x)); // ERROR, may not compile</font>
<a name="line1113">1113: </a><font color="#B22222"> bar(ret); // OK</font>
<a name="line1115">1115: </a><font color="#B22222"> if (FOO(x)) // ERROR, may not compile</font>
<a name="line1116">1116: </a><font color="#B22222"> if (ret) // OK</font>
<a name="line1117">1117: </a><font color="#B22222">.ve</font>
<a name="line1119">1119: </a><font color="#B22222"> Example usage:</font>
<a name="line1120">1120: </a><font color="#B22222">.vb</font>
<a name="line1121">1121: </a><font color="#B22222"> #define MY_SIMPLE_RETURNING_MACRO(arg1) <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a>(0,arg1+=10)</font>
<a name="line1123">1123: </a><font color="#B22222"> int x = 10;</font>
<a name="line1124">1124: </a><font color="#B22222"> int err = MY_SIMPLE_RETURNING_MACRO(x); // err = 0, x = 20</font>
<a name="line1126">1126: </a><font color="#B22222"> // multiline macros allowed, but must declare with line continuation as usual</font>
<a name="line1127">1127: </a><font color="#B22222"> #define MY_COMPLEX_RETURNING_MACRO(arg1) <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a>(0, \</font>
<a name="line1128">1128: </a><font color="#B22222"> if (arg1 > 10) { \</font>
<a name="line1129">1129: </a><font color="#B22222"> puts("big int!"); \</font>
<a name="line1130">1130: </a><font color="#B22222"> } else { \</font>
<a name="line1131">1131: </a><font color="#B22222"> return 7355608; \</font>
<a name="line1132">1132: </a><font color="#B22222"> } \</font>
<a name="line1133">1133: </a><font color="#B22222"> )</font>
<a name="line1135">1135: </a><font color="#B22222"> // if retexpr contains commas, must enclose it with braces</font>
<a name="line1136">1136: </a><font color="#B22222"> #define MY_COMPLEX_RETEXPR_MACRO_1() <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a>(x+=10,0,body...)</font>
<a name="line1137">1137: </a><font color="#B22222"> #define MY_COMPLEX_RETEXPR_MACRO_2() <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a>((x+=10,0),body...)</font>
<a name="line1139">1139: </a><font color="#B22222"> int x = 10;</font>
<a name="line1140">1140: </a><font color="#B22222"> int y = MY_COMPLEX_RETEXPR_MACRO_1(); // ERROR, y = x = 20 not 0</font>
<a name="line1141">1141: </a><font color="#B22222"> int z = MY_COMPLEX_RETEXPR_MACRO_2(); // OK, y = 0, x = 20</font>
<a name="line1142">1142: </a><font color="#B22222">.ve</font>
<a name="line1144">1144: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscExpand.html">PetscExpand</a>()`, `<a href="../manualpages/Sys/PetscConcat.html">PetscConcat</a>()`, `<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>()`</font>
<a name="line1145">1145: </a><font color="#B22222">M*/</font>
<a name="line1146">1146: </a><strong><font color="#228B22">#define <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a>(retexpr, ...) PetscMacroReturns_(retexpr, __VA_ARGS__)</font></strong>
<a name="line1148">1148: </a><strong><font color="#228B22">#define PetscMacroReturnStandard(...) <a href="../manualpages/Sys/PetscMacroReturns.html">PetscMacroReturns</a>(<a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>, __VA_ARGS__)</font></strong>
<a name="line1150">1150: </a><font color="#B22222">/*MC</font>
<a name="line1151">1151: </a><font color="#B22222"> <a href="../manualpages/Sys/PETSC_STATIC_ARRAY_LENGTH.html">PETSC_STATIC_ARRAY_LENGTH</a> - Return the length of a static array</font>
<a name="line1153">1153: </a><font color="#B22222"> Synopsis:</font>
<a name="line1154">1154: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line1155">1155: </a><font color="#B22222"> size_t <a href="../manualpages/Sys/PETSC_STATIC_ARRAY_LENGTH.html">PETSC_STATIC_ARRAY_LENGTH</a>(a)</font>
<a name="line1157">1157: </a><font color="#B22222"> Input Parameter:</font>
<a name="line1158">1158: </a><font color="#B22222">. a - a static array of any type</font>
<a name="line1160">1160: </a><font color="#B22222"> Output Parameter:</font>
<a name="line1161">1161: </a><font color="#B22222">. <return-value> - the length of the array</font>
<a name="line1163">1163: </a><font color="#B22222"> Example:</font>
<a name="line1164">1164: </a><font color="#B22222">.vb</font>
<a name="line1165">1165: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscInt.html">PetscInt</a> a[22];</font>
<a name="line1166">1166: </a><font color="#B22222"> size_t sa = <a href="../manualpages/Sys/PETSC_STATIC_ARRAY_LENGTH.html">PETSC_STATIC_ARRAY_LENGTH</a>(a)</font>
<a name="line1167">1167: </a><font color="#B22222">.ve</font>
<a name="line1168">1168: </a><font color="#B22222"> `sa` will have a value of 22</font>
<a name="line1170">1170: </a><font color="#B22222"> Level: intermediate</font>
<a name="line1171">1171: </a><font color="#B22222">M*/</font>
<a name="line1172">1172: </a><font color="#A020F0">#if PETSC_CPP_VERSION >= 14</font>
<a name="line1173">1173: </a><font color="#A020F0"> #include <cstddef></font>
<a name="line1174">1174: </a><font color="#A020F0"> #include <type_traits></font>
<a name="line1176">1176: </a>template <typename T>
<a name="line1177">1177: </a>static inline constexpr std::size_t <a href="../manualpages/Sys/PETSC_STATIC_ARRAY_LENGTH.html">PETSC_STATIC_ARRAY_LENGTH</a>(const T &) noexcept
<a name="line1178">1178: </a>{
<a name="line1179">1179: </a> static_assert(std::is_array<T>::value, <font color="#666666">""</font>);
<a name="line1180">1180: </a> <font color="#4169E1">return</font> std::extent<T, std::rank<T>::value - 1>::value;
<a name="line1181">1181: </a>}
<a name="line1182">1182: </a><font color="#A020F0">#else</font>
<a name="line1183">1183: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PETSC_STATIC_ARRAY_LENGTH.html">PETSC_STATIC_ARRAY_LENGTH</a>(...) (sizeof(__VA_ARGS__) / sizeof(__VA_ARGS__)[0])</font></strong>
<a name="line1184">1184: </a><font color="#A020F0">#endif</font>
<a name="line1186">1186: </a><font color="#B22222">/*</font>
<a name="line1187">1187: </a><font color="#B22222"> These macros allow extracting out the first argument or all but the first argument from a macro __VAR_ARGS__ INSIDE another macro.</font>
<a name="line1189">1189: </a><font color="#B22222"> Example usage:</font>
<a name="line1191">1191: </a><font color="#B22222"> #define mymacro(obj,...) {</font>
<a name="line1192">1192: </a><font color="#B22222"> PETSC_FIRST_ARG((__VA_ARGS__,unused));</font>
<a name="line1193">1193: </a><font color="#B22222"> f(22 PETSC_REST_ARG(__VA_ARGS__));</font>
<a name="line1194">1194: </a><font color="#B22222"> }</font>
<a name="line1196">1196: </a><font color="#B22222"> Note you add a dummy extra argument to __VA_ARGS__ and enclose them in an extra set of () for PETSC_FIRST_ARG() and PETSC_REST_ARG(__VA_ARGS__) automatically adds a leading comma only if there are additional arguments</font>
<a name="line1198">1198: </a><font color="#B22222"> Reference:</font>
<a name="line1199">1199: </a><font color="#B22222"> https://stackoverflow.com/questions/5588855/standard-alternative-to-gccs-va-args-trick</font>
<a name="line1200">1200: </a><font color="#B22222">*/</font>
<a name="line1201">1201: </a><strong><font color="#228B22">#define PETSC_FIRST_ARG_(N, ...) N</font></strong>
<a name="line1202">1202: </a><strong><font color="#228B22">#define PETSC_FIRST_ARG(args) PETSC_FIRST_ARG_ args</font></strong>
<a name="line1203">1203: </a><strong><font color="#228B22">#define PETSC_SELECT_16TH(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, ...) a16</font></strong>
<a name="line1204">1204: </a><strong><font color="#228B22">#define PETSC_NUM(...) PETSC_SELECT_16TH(__VA_ARGS__, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, ONE, throwaway)</font></strong>
<a name="line1205">1205: </a><strong><font color="#228B22">#define PETSC_REST_HELPER_TWOORMORE(first, ...) , __VA_ARGS__</font></strong>
<a name="line1206">1206: </a><strong><font color="#228B22">#define PETSC_REST_HELPER_ONE(first)</font></strong>
<a name="line1207">1207: </a><strong><font color="#228B22">#define PETSC_REST_HELPER2(qty, ...) PETSC_REST_HELPER_##qty(__VA_ARGS__)</font></strong>
<a name="line1208">1208: </a><strong><font color="#228B22">#define PETSC_REST_HELPER(qty, ...) PETSC_REST_HELPER2(qty, __VA_ARGS__)</font></strong>
<a name="line1209">1209: </a><strong><font color="#228B22">#define PETSC_REST_ARG(...) PETSC_REST_HELPER(PETSC_NUM(__VA_ARGS__), __VA_ARGS__)</font></strong>
<a name="line1211">1211: </a><strong><font color="#228B22">#define PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN_(name, ...) \</font></strong>
<a name="line1212">1212: </a><strong><font color="#228B22"> _Pragma(<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(name diagnostic push)) \</font></strong>
<a name="line1213">1213: </a><strong><font color="#228B22"> _Pragma(<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(name diagnostic ignored __VA_ARGS__))</font></strong>
<a name="line1215">1215: </a><strong><font color="#228B22">#define PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END_(name) _Pragma(<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(name diagnostic pop))</font></strong>
<a name="line1217">1217: </a><font color="#A020F0">#if defined(__clang__)</font>
<a name="line1218">1218: </a><strong><font color="#228B22"> #define PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN(...) PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN_(clang, __VA_ARGS__)</font></strong>
<a name="line1219">1219: </a><strong><font color="#228B22"> #define PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END() PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END_(clang)</font></strong>
<a name="line1220">1220: </a><font color="#A020F0">#elif defined(__GNUC__) || defined(__GNUG__)</font>
<a name="line1221">1221: </a> <font color="#B22222">// gcc >= 4.6.0</font>
<a name="line1222">1222: </a><font color="#A020F0"> #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600</font>
<a name="line1223">1223: </a><strong><font color="#228B22"> #define PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN(...) PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN_(GCC, __VA_ARGS__)</font></strong>
<a name="line1224">1224: </a><strong><font color="#228B22"> #define PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END() PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END_(GCC)</font></strong>
<a name="line1225">1225: </a><font color="#A020F0"> #endif</font>
<a name="line1226">1226: </a><font color="#A020F0">#endif</font>
<a name="line1228">1228: </a><font color="#A020F0">#ifndef PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN</font>
<a name="line1229">1229: </a><strong><font color="#228B22"> #define PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN(...)</font></strong>
<a name="line1230">1230: </a><strong><font color="#228B22"> #define PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END(...)</font></strong>
<a name="line1231">1231: </a> <font color="#B22222">// only undefine these if they are not used</font>
<a name="line1232">1232: </a><strong><font color="#228B22"> #undef PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN_</font></strong>
<a name="line1233">1233: </a><strong><font color="#228B22"> #undef PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END_</font></strong>
<a name="line1234">1234: </a><font color="#A020F0">#endif</font>
<a name="line1236">1236: </a><font color="#B22222">/*MC</font>
<a name="line1237">1237: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscPragmaOMP.html">PetscPragmaOMP</a> - Sets an OpenMP pragma to affect the next block of code</font>
<a name="line1239">1239: </a><font color="#B22222"> Synopsis:</font>
<a name="line1240">1240: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line1241">1241: </a><font color="#B22222"> int <a href="../manualpages/Sys/PetscPragmaOMP.html">PetscPragmaOMP</a>(name)</font>
<a name="line1243">1243: </a><font color="#B22222"> No Fortran Support</font>
<a name="line1245">1245: </a><font color="#B22222"> Input Parameter:</font>
<a name="line1246">1246: </a><font color="#B22222">. name - the OpenMP pragma, for example, `critical` or `parallel for`</font>
<a name="line1248">1248: </a><font color="#B22222"> Level: intermediate</font>
<a name="line1250">1250: </a><font color="#B22222"> Note:</font>
<a name="line1251">1251: </a><font color="#B22222"> The pragma takes effect when PETSc was configured with `--with-openmp`. See `<a href="../manualpages/Sys/PetscPragmaUseOMPKernels.html">PetscPragmaUseOMPKernels</a>()`</font>
<a name="line1252">1252: </a><font color="#B22222"> for when PETSc was configured to use OpenMP in some of its numerical kernels.</font>
<a name="line1254">1254: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscPragmaUseOMPKernels.html">PetscPragmaUseOMPKernels</a>()`, `<a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>()`, `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()`, `<a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>()`, `<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>()`,</font>
<a name="line1255">1255: </a><font color="#B22222">`<a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a>`, `<a href="../manualpages/Sys/PETSC_ATTRIBUTE_MAY_ALIAS.html">PETSC_ATTRIBUTE_MAY_ALIAS</a>`</font>
<a name="line1256">1256: </a><font color="#B22222">M*/</font>
<a name="line1257">1257: </a><font color="#A020F0">#if defined(_OPENMP)</font>
<a name="line1258">1258: </a><font color="#A020F0"> #if defined(_MSC_VER)</font>
<a name="line1259">1259: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscPragmaOMP.html">PetscPragmaOMP</a>(...) __pragma(__VA_ARGS__)</font></strong>
<a name="line1260">1260: </a><font color="#A020F0"> #else</font>
<a name="line1261">1261: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscPragmaOMP.html">PetscPragmaOMP</a>(...) _Pragma(<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(omp __VA_ARGS__))</font></strong>
<a name="line1262">1262: </a><font color="#A020F0"> #endif</font>
<a name="line1263">1263: </a><font color="#A020F0">#else</font>
<a name="line1264">1264: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscPragmaOMP.html">PetscPragmaOMP</a>(...)</font></strong>
<a name="line1265">1265: </a><font color="#A020F0">#endif</font>
<a name="line1267">1267: </a><font color="#B22222">/*MC</font>
<a name="line1268">1268: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscPragmaUseOMPKernels.html">PetscPragmaUseOMPKernels</a> - Sets an OpenMP pragma to affect the next block of code</font>
<a name="line1270">1270: </a><font color="#B22222"> Synopsis:</font>
<a name="line1271">1271: </a>#include <A href="../include/petscmacros.h.html"><petscmacros.h></A>
<a name="line1272">1272: </a><font color="#B22222"> int <a href="../manualpages/Sys/PetscPragmaUseOMPKernels.html">PetscPragmaUseOMPKernels</a>(name)</font>
<a name="line1274">1274: </a><font color="#B22222"> No Fortran Support</font>
<a name="line1276">1276: </a><font color="#B22222"> Input Parameter:</font>
<a name="line1277">1277: </a><font color="#B22222">. name - the OpenMP pragma, for example, `critical` or `parallel for`</font>
<a name="line1279">1279: </a><font color="#B22222"> Level: intermediate</font>
<a name="line1281">1281: </a><font color="#B22222"> Note:</font>
<a name="line1282">1282: </a><font color="#B22222"> The pragma takes effect when PETSc was configured with `--with-openmp-kernels`. See `<a href="../manualpages/Sys/PetscPragmaOMP.html">PetscPragmaOMP</a>()`</font>
<a name="line1283">1283: </a><font color="#B22222"> for when PETSc was configured with OpenMP but not to use it in its numerical kernels</font>
<a name="line1285">1285: </a><font color="#B22222">.seealso: `<a href="../manualpages/Sys/PetscPragmaOMP.html">PetscPragmaOMP</a>()`, `<a href="../manualpages/Sys/PetscHasBuiltin.html">PetscHasBuiltin</a>()`, `<a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>()`, `<a href="../manualpages/Sys/PetscLikely.html">PetscLikely</a>()`, `<a href="../manualpages/Sys/PetscUnlikely.html">PetscUnlikely</a>()`,</font>
<a name="line1286">1286: </a><font color="#B22222">`<a href="../manualpages/Sys/PETSC_ATTRIBUTE_FORMAT.html">PETSC_ATTRIBUTE_FORMAT</a>`, `<a href="../manualpages/Sys/PETSC_ATTRIBUTE_MAY_ALIAS.html">PETSC_ATTRIBUTE_MAY_ALIAS</a>`</font>
<a name="line1287">1287: </a><font color="#B22222">M*/</font>
<a name="line1288">1288: </a><font color="#A020F0">#if defined(PETSC_USE_OPENMP_KERNELS)</font>
<a name="line1289">1289: </a><font color="#A020F0"> #if defined(_MSC_VER)</font>
<a name="line1290">1290: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscPragmaUseOMPKernels.html">PetscPragmaUseOMPKernels</a>(...) __pragma(__VA_ARGS__)</font></strong>
<a name="line1291">1291: </a><font color="#A020F0"> #else</font>
<a name="line1292">1292: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscPragmaUseOMPKernels.html">PetscPragmaUseOMPKernels</a>(...) _Pragma(<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(omp __VA_ARGS__))</font></strong>
<a name="line1293">1293: </a><font color="#A020F0"> #endif</font>
<a name="line1294">1294: </a><font color="#A020F0">#else</font>
<a name="line1295">1295: </a><strong><font color="#228B22"> #define <a href="../manualpages/Sys/PetscPragmaUseOMPKernels.html">PetscPragmaUseOMPKernels</a>(...)</font></strong>
<a name="line1296">1296: </a><font color="#A020F0">#endif</font>
<a name="line1298">1298: </a><font color="#B22222">/* PetscPragmaSIMD - from CeedPragmaSIMD */</font>
<a name="line1299">1299: </a><font color="#A020F0">#if defined(__NEC__)</font>
<a name="line1300">1300: </a><strong><font color="#228B22"> #define PetscPragmaSIMD _Pragma(</font><font color="#666666">"_NEC ivdep"</font><font color="#228B22">)</font></strong>
<a name="line1301">1301: </a><font color="#A020F0">#elif defined(__INTEL_COMPILER) && !defined(_WIN32)</font>
<a name="line1302">1302: </a><strong><font color="#228B22"> #define PetscPragmaSIMD _Pragma(</font><font color="#666666">"vector"</font><font color="#228B22">)</font></strong>
<a name="line1303">1303: </a><font color="#A020F0">#elif defined(__GNUC__)</font>
<a name="line1304">1304: </a><font color="#A020F0"> #if __GNUC__ >= 5 && !defined(__PGI)</font>
<a name="line1305">1305: </a><strong><font color="#228B22"> #define PetscPragmaSIMD _Pragma(</font><font color="#666666">"GCC ivdep"</font><font color="#228B22">)</font></strong>
<a name="line1306">1306: </a><font color="#A020F0"> #endif</font>
<a name="line1307">1307: </a><font color="#A020F0">#elif defined(_OPENMP) && _OPENMP >= 201307</font>
<a name="line1308">1308: </a><strong><font color="#228B22"> #define PetscPragmaSIMD <a href="../manualpages/Sys/PetscPragmaOMP.html">PetscPragmaOMP</a>(simd)</font></strong>
<a name="line1309">1309: </a><font color="#A020F0">#elif defined(PETSC_HAVE_CRAY_VECTOR)</font>
<a name="line1310">1310: </a><strong><font color="#228B22"> #define PetscPragmaSIMD _Pragma(</font><font color="#666666">"_CRI ivdep"</font><font color="#228B22">)</font></strong>
<a name="line1311">1311: </a><font color="#A020F0">#endif</font>
<a name="line1313">1313: </a><font color="#A020F0">#ifndef PetscPragmaSIMD</font>
<a name="line1314">1314: </a><strong><font color="#228B22"> #define PetscPragmaSIMD</font></strong>
<a name="line1315">1315: </a><font color="#A020F0">#endif</font>
<a name="line1317">1317: </a>#include <A href="../include/petsc/private/petscadvancedmacros.h.html"><petsc/private/petscadvancedmacros.h></A>
<a name="line1319">1319: </a><strong><font color="#228B22">#define PetscConcat6_(a, b, c, d, e, f) a##b##c##d##e##f</font></strong>
<a name="line1320">1320: </a><strong><font color="#228B22">#define PetscConcat6(a, b, c, d, e, f) PetscConcat6_(a, b, c, d, e, f)</font></strong>
<a name="line1322">1322: </a><strong><font color="#228B22">#define PETSC_DEPRECATED_IDENTIFIER_(__PETSC_DEPRECATION_MACRO__, __SILENCE_MACRO__, major, minor, subminor, replacement, ...) \</font></strong>
<a name="line1323">1323: </a><strong><font color="#228B22"> PetscIfPetscDefined(__SILENCE_MACRO__, <a href="../manualpages/Sys/PetscExpandToNothing.html">PetscExpandToNothing</a>, \</font></strong>
<a name="line1324">1324: </a><strong><font color="#228B22"> __PETSC_DEPRECATION_MACRO__)(<a href="../manualpages/Sys/PetscStringize.html">PetscStringize</a>(Use replacement (since version major.minor.subminor) instead. Silence this warning (as well as all others for this version) by defining PetscConcat_(PETSC_, __SILENCE_MACRO__). __VA_ARGS__))</font></strong>
<a name="line1326">1326: </a><strong><font color="#228B22">#define PETSC_DEPRECATED_IDENTIFIER(__PETSC_DEPRECATION_MACRO__, major, minor, subminor, ...) \</font></strong>
<a name="line1327">1327: </a><strong><font color="#228B22"> PETSC_DEPRECATED_IDENTIFIER_(__PETSC_DEPRECATION_MACRO__, PetscConcat6(SILENCE_DEPRECATION_WARNINGS_, major, _, minor, _, subminor), major, minor, subminor, __VA_ARGS__)</font></strong>
<a name="line1329">1329: </a><strong><font color="#228B22">#define PETSC_DEPRECATED_OBJECT(major, minor, subminor, replacement, ...) PETSC_DEPRECATED_IDENTIFIER(PETSC_DEPRECATED_OBJECT_BASE, major, minor, subminor, replacement, __VA_ARGS__)</font></strong>
<a name="line1330">1330: </a><strong><font color="#228B22">#define PETSC_DEPRECATED_FUNCTION(major, minor, subminor, replacement, ...) PETSC_DEPRECATED_IDENTIFIER(PETSC_DEPRECATED_FUNCTION_BASE, major, minor, subminor, replacement, __VA_ARGS__)</font></strong>
<a name="line1331">1331: </a><strong><font color="#228B22">#define PETSC_DEPRECATED_TYPEDEF(major, minor, subminor, replacement, ...) PETSC_DEPRECATED_IDENTIFIER(PETSC_DEPRECATED_TYPEDEF_BASE, major, minor, subminor, replacement, __VA_ARGS__)</font></strong>
<a name="line1332">1332: </a><strong><font color="#228B22">#define PETSC_DEPRECATED_ENUM(major, minor, subminor, replacement, ...) PETSC_DEPRECATED_IDENTIFIER(PETSC_DEPRECATED_ENUM_BASE, major, minor, subminor, replacement, __VA_ARGS__)</font></strong>
<a name="line1333">1333: </a><strong><font color="#228B22">#define PETSC_DEPRECATED_MACRO(major, minor, subminor, replacement, ...) PETSC_DEPRECATED_IDENTIFIER(PETSC_DEPRECATED_MACRO_BASE, major, minor, subminor, replacement, __VA_ARGS__)</font></strong>
</pre>
</body>
</html>
|