1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
|
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) 2017 Intel Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Contact Information:
Intel Corporation, www.intel.com
BSD LICENSE
Copyright(c) 2017 Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PSM2_MQ_H
#define PSM2_MQ_H
#include <psm2.h>
#ifdef __cplusplus
extern "C" {
#endif
/*!
* @file psm2_mq.h
* @brief PSM2 Matched Queues
*
* @page psm2_mq Matched Queues interface
*
* The Matched Queues (MQ) interface implements a queue-based communication
* model with the distinction that queue message consumers use a 3-tuple of
* metadata to match incoming messages against a list of preposted receive
* buffers. These semantics are consistent with those presented by MPI-1.2
* and all the features and side-effects of Message-Passing find their way into
* Matched Queues. There is currently a single MQ context,
* If need be, MQs may expose a function to allocate more than
* one MQ context in the future. Since an MQ is implicitly bound to a locally
* opened endpoint, handle all MQ functions use an MQ handle instead of an EP
* handle as a communication context.
*
* @section tagmatch MQ Tag Matching
*
* A successful MQ tag match requires an endpoint address (@ref psm2_epaddr_t)
* and a 3-tuple of tag objects. Two of the tag objects are provided by the
* receiver when posting a receive buffer (@ref psm2_mq_irecv) and the last is
* provided by the sender as part of every message sent (@ref psm2_mq_send and
* @ref psm2_mq_isend). Since MQ is a receiver-directed communication model,
* the tag matching done at the receiver involves matching the sent message's
* origin and send tag (@c stag) with the source endpointer address, tag (@c
* rtag), and tag selector (@c rtagsel) attached to every preposted receive
* buffer. The incoming @c stag is compared to the posted @c rtag but only for
* significant bits set to @c 1 in the @c rtagsel. The @c rtagsel can be used
* to mask off parts (or even all) of the bitwise comparison between sender and
* receiver tags. A successful match causes the message to be received into
* the buffer with which the tag is matched. If the incoming message is too
* large, it is truncated to the size of the posted receive buffer. The
* bitwise operation corresponding to a successful match and receipt of an
* expected message amounts to the following expression evaluating as true:
*
* @verbatim ((stag ^ rtag) & rtagsel) == 0 @endverbatim
*
* It is up to the user to encode (pack) into the 64-bit unsigned
* integers, including employing the @c rtagsel tag selector as a method to
* wildcart part or all of the bits significant in the tag matching operation.
* For example, MPI uses triple based on context (MPI communicator), source
* rank, send tag. The following code example shows how the triple can be
* packed into 64 bits:
*
* @code{.c}
//
// 64-bit send tag formed by packing the triple:
//
// ( context_id_16bits | source_rank_16bits | send_tag_32bits )
//
stag = ( (((context_id)&0xffffULL)<<48)| \
(((source_rank)&0xffffULL)<<32)| \
(((send_tag)&0xffffffffULL)) );
@endcode
*
* Similarly, the receiver applies the @c rtag matching bits and @c rtagsel
* masking bits against a list of send tags and returns the first successful
* match. Zero bits in the @c tagsel can be used to indicate wildcarded bits
* in the 64-bit tag which can be useful for implementing MPI's
* @c MPI_ANY_SOURCE and @c MPI_ANY_TAG. Following the example bit splicing in
* the above @c stag example:
*
* @code{.c}
// Example MPI implementation where MPI_COMM_WORLD implemented as 0x3333
// MPI_Irecv source_rank=MPI_ANY_SOURCE, tag=7, comm=MPI_COMM_WORLD
rtag = 0x3333000000000007;
rtagsel = 0xffff0000ffffffff;
// MPI_Irecv source_rank=3, tag=MPI_ANY_TAG, comm=MPI_COMM_WORLD
rtag = 0x3333000300000000;
rtagsel = 0xffffffff80000000; // can't ignore sign bit in tag
// MPI_Irecv source_rank=MPI_ANY_SOURCE, tag=MPI_ANY_TAG, comm=MPI_COMM_WORLD
rtag = 0x3333000300000000;
rtagsel = 0xffff000080000000; // can't ignore sign bit in tag
@endcode
*
*
* Applications that do not follow tag matching semantics can simply always
* pass a value of @c 0 for @c rtagsel, which will always yield a successful
* match to the first preposted buffer. If a message cannot be matched to any
* of the preposted buffers, the message is delivered as an unexpected
* message.
*
* @section mq_receive MQ Message Reception
*
* MQ messages are either received as @e expected or @e unexpected: @li The
* received message is @e expected if the incoming message tag matches the
* combination of tag and tag selector of at least one of the user-provided
* receive buffers preposted with @ref psm2_mq_irecv.
*
* @li The received message is @e unexpected if the incoming message tag @b
* doesn't match any combination of tag and tag selector from all the
* user-provided receive buffers preposted with @ref psm2_mq_irecv.
*
* Unexpected messages are messages that the MQ library buffers until the
* user provides a receive buffer that can match the unexpected message.
* With Matched Queues and MPI alike, unexpected messages can occur as a
* side-effect of the programming model, whereby the arrival of messages can be
* slightly out of step with the ordering in which the user
* provides receive buffers. Unexpected messages can also be triggered by the
* difference between the rate at which a sender produces messages and the rate
* at which a paired receiver can post buffers and hence consume the messages.
*
* In all cases, too many @e unexpected messages will negatively affect
* performance. Users can employ some of the following mechanisms to reduce
* the effect of added memory allocations and copies that result from
* unexpected messages:
* @li If and when possible, receive buffers should be posted as early as
* possible and ideally before calling into the progress engine.
* @li Use of rendezvous messaging that can be controlled with
* @ref PSM2_MQ_RNDV_HFI_SZ and @ref PSM2_MQ_RNDV_SHM_SZ options. These
* options default to values determined to make effective use of
* bandwidth and are hence not advisable for all communication message
* sizes, but rendezvous messages inherently prevent unexpected
* messages by synchronizing the sender with the receiver beforehand.
* @li The amount of memory that is allocated to handle unexpected messages
* can be bounded by adjusting the Global @ref PSM2_MQ_MAX_SYSBUF_MBYTES
* option.
* @li MQ statistics, such as the amount of received unexpected messages and
* the aggregate amount of unexpected bytes are available in the @ref
* psm2_mq_stats structure.
*
* Whenever a match occurs, whether the message is expected or unexpected, it
* is generally up to the user to ensure that the message is not truncated.
* Message truncation occurs when the size of the preposted buffer is less than
* the size of the incoming matched message. MQ will correctly handle
* message truncation by always copying the appropriate amount of bytes as to
* not overwrite any data. While it is valid to send less data than the amount
* of data that has been preposted, messages that are truncated will be marked
* @ref PSM2_MQ_TRUNCATION as part of the error code in the message status
* structure (@ref psm2_mq_status_t or @ref psm2_mq_status2_t).
*
* @section mq_completion MQ Completion Semantics
*
* Message completion in Matched Queues follows local completion semantics.
* When sending an MQ message, it is deemed complete when MQ guarantees that
* the source data has been sent and that the entire input source data memory
* location can be safely overwritten. As with standard Message-Passing,
* MQ does not make any remote completion guarantees for sends. MQ does
* however, allow a sender to synchronize with a receiver to send a synchronous
* message which sends a message only after a matching receive buffer has been
* posted by the receiver (@ref PSM2_MQ_FLAG_SENDSYNC).
*
* A receive is deemed complete after it has matched its associated receive
* buffer with an incoming send and that the data from the send has been
* completely delivered to the receive buffer.
*
* @section mq_progress MQ Progress Requirements
*
* Progress on MQs must be @e explicitly ensured by the user for correctness.
* The progress requirement holds even if certain areas of the MQ
* implementation require less network attention than others, or if progress
* may internally be guaranteed through interrupts. The main polling function,
* @ref psm2_poll, is the most general form of ensuring process on a given
* endpoint. Calling @ref psm2_poll ensures that progress is made over all the
* MQs and other components instantiated over the endpoint passed to @ref
* psm2_poll.
*
* While @ref psm2_poll is the only way to directly ensure progress, other MQ
* functions will conditionally ensure progres depending on how they are used:
*
* @li @ref psm2_mq_wait employs polling and waits until the request is
* completed. For blocking communication operations where the caller is
* waiting on a single send or receive to complete, psm2_mq_wait usually
* provides the best responsiveness in terms of latency.
*
* @li @ref psm2_mq_test can test a particular request for completion, but @b
* never directly or indirectly ensures progress as it only tests the
* completion status of a request, nothing more. See functional documentation
* in @ref psm2_mq_test for a detailed discussion.
*
* @li @ref psm2_mq_ipeek ensures progress if and only if the MQ's completion
* queue is empty and will not ensure progress as long as the completion queue
* is non-empty. Users that always aggressively process all elements of the MQ
* completion queue as part of their own progress engine will indirectly always
* ensure MQ progress. The ipeek mechanism is the preferred way for
* ensuring progress when many non-blocking requests are in flight since ipeek
* returns requests in the order in which they complete. Depending on how the
* user initiates and completes communication, this may be preferable to
* calling other progress functions on individual requests.
*/
/*! @defgroup mq PSM Matched Queues
*
* @{
*/
/** @brief Initialize the MQ component for MQ communication
*
* This function provides the Matched Queue handle necessary to perform all
* Matched Queue communication operations.
*
* @param[in] ep Endpoint over which to initialize Matched Queue
* @param[in] tag_order_mask Order mask hint to let MQ know what bits of the
* send tag are required to maintain MQ message
* order. In MPI parlance, this mask sets the bits
* that store the context (or communicator ID). The
* user can choose to pass PSM2_MQ_ORDERMASK_NONE or
* PSM2_MQ_ORDERMASK_ALL to tell MQ to respectively
* provide no ordering guarantees or to provide
* ordering over all messages by ignoring the
* contexts of the send tags.
* @param[in] opts Set of options for Matched Queue
* @param[in] numopts Number of options passed
* @param[out] mq User-supplied storage to return the Matched Queue handle
* associated to the newly created Matched Queue.
*
* @remark This function can be called many times to retrieve the MQ handle
* associated to an endpoint, but options are only considered the first
* time the function is called.
*
* @post The user obtains a handle to an instantiated Match Queue.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK A new Matched Queue has been instantiated across all the
* members of the group.
*
* @code{.c}
int try_open_endpoint_and_initialize_mq(
psm2_ep_t *ep, // endpoint handle
psm2_epid_t *epid, // unique endpoint ID
psm2_uuid_t job_uuid, // unique job uuid, for ep_open
psm2_mq_t *mq, // MQ handle initialized on endpoint 'ep'
uint64_t communicator_bits) // Where we store our communicator or
// context bits in the 64-bit tag.
{
// Simplified open, see psm2_ep_open documentation for more info
psm2_ep_open(job_uuid,
NULL, // no options
ep, epid);
// We initialize a matched queue by telling PSM the bits that are
// order-significant in the tag. Point-to-point ordering will not be
// maintained between senders where the communicator bits are not the
// same.
psm2_mq_init(ep,
communicator_bits,
NULL, // no other MQ options
0, // 0 options passed
mq); // newly initialized matched Queue
return 1;
}
@endcode
*/
psm2_error_t
psm2_mq_init(psm2_ep_t ep, uint64_t tag_order_mask,
const struct psm2_optkey *opts, int numopts, psm2_mq_t *mq);
#define PSM2_MQ_ORDERMASK_NONE 0ULL
/**< Used to initialize MQ and disable all MQ message ordering
* guarantees (this mask may prevent the use of MQ to maintain matched
* message envelope delivery required in MPI). */
#define PSM2_MQ_ORDERMASK_ALL 0xffffffffffffffffULL
/**< Used to initialize MQ with no message ordering hints, which forces
* MQ to maintain order over all messages */
/** @brief Finalize (close) an MQ handle
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK A given Matched Queue has been freed and use of the future
* use of the handle produces undefined results.
*/
psm2_error_t
psm2_mq_finalize(psm2_mq_t mq);
#define PSM2_MQ_TAG_ELEMENTS 4
/**< Represents the number of 32-bit tag elements in the psm2_mq_tag_t
* type plus one extra element to keep alignment and padding
* as 16 bytes. */
/** @struct psm2_mq_tag
** @brief MQ Message tag
*
* Extended message tag type introduced in PSM 2.0. The previous 64 bit tag
* values are replaced by a struct containing three 32 bit tag values for a
* total of 96 bits. Matching semantics are unchanged from the previous 64-bit
* matching scheme; the only difference is that 96 bits are matched instead of
* 64. For interoperability with existing PSM routines, 64 bit tags are
* extended to a 96 bit tag by setting the upper 32 bits (tag[2] or tag2) to
* zero. Other than this caveat, all of the existing routines using 64-bit
* tags are interchangeable with PSM2 routines using this psm2_mq_tag_t type.
* For example, a message sent using @ref psm2_mq_send can be received using
* @ref psm2_mq_irecv2, provided the tags match as described above.
*/
typedef
//struct psm2_mq_tag {
union psm2_mq_tag {
// union {
uint32_t tag[PSM2_MQ_TAG_ELEMENTS]; /* No longer specifying
* alignment as it makes
* code break with newer
* compilers. */
/**< 3 x 32bit array representation of @ref psm2_mq_tag */
struct {
uint32_t tag0; /**< 1 of 3 uint32_t tag values */
uint32_t tag1; /**< 2 of 3 uint32_t tag values */
uint32_t tag2; /**< 3 of 3 uint32_t tag values */
};
// };
} psm2_mq_tag_t;
/** @brief MQ Non-blocking operation status
*
* Message completion status for asynchronous communication operations.
* For wait and test functions, MQ fills in the structure upon completion.
* Upon completion, receive requests fill in every field of the status
* structure while send requests only return a valid error_code and context
* pointer.
*/
typedef
struct psm2_mq_status {
/** Sender's original message tag (receive reqs only) */
uint64_t msg_tag;
/** Sender's original message length (receive reqs only) */
uint32_t msg_length;
/** Actual number of bytes transfered (receive reqs only) */
uint32_t nbytes;
/** MQ error code for communication operation */
psm2_error_t error_code;
/**< User-associated context for send or receive */
void *context;
} psm2_mq_status_t;
/** @brief MQ Non-blocking operation status
*
* Message completion status for asynchronous communication operations. For
* wait and test functions, MQ fills in the structure upon completion. Upon
* completion, requests fill in every field of the status structure with the
* exception of the nbytes field, which is only valid for receives. Version 2
* of the status type contains an @ref psm2_mq_tag_t type to represent the tag
* instead of a 64-bit integer value and is for use with PSM v2 routines.
*/
typedef
struct psm2_mq_status2 {
/** Remote peer's epaddr */
psm2_epaddr_t msg_peer;
/** Sender's original message tag */
psm2_mq_tag_t msg_tag __attribute__ ((aligned(16)));/* Alignment added
* to preserve the
* layout as is
* expected by
* existent code */
/** Sender's original message length */
uint32_t msg_length;
/** Actual number of bytes transfered (receiver only) */
uint32_t nbytes;
/** MQ error code for communication operation */
psm2_error_t error_code;
/** User-associated context for send or receive */
void *context;
} psm2_mq_status2_t;
/** @brief PSM2 Communication handle (opaque) */
typedef struct psm2_mq_req *psm2_mq_req_t;
/** @brief MQ Request Struct
*
* Message completion request for asynchronous communication operations.
* Upon completion, requests are filled with the valid data for the
* corresponding send/recv operation that was completed. This datatype
* contains the status data and is converted into the
* mq_status structures in wait/test functions.
*/
struct psm2_mq_req_user {
/* Tag matching vars */
psm2_epaddr_t peer;
psm2_mq_tag_t tag __attribute__ ((aligned(16)));/* Alignment added
* to preserve the
* layout as is
* expected by
* existent code */
psm2_mq_tag_t tagsel; /* used for receives */
/* Buffer attached to request. May be a system buffer for unexpected
* messages or a user buffer when an expected message */
uint8_t *buf;
uint32_t buf_len;
uint32_t error_code;
uint32_t recv_msglen; /* Message length we are ready to receive */
uint32_t send_msglen; /* Message length from sender */
/* Used for request to send messages */
void *context; /* user context associated to sends or receives */
uint64_t user_reserved[4];
};
/*! @} */
/*! @ingroup mq
* @defgroup mq_options PSM Matched Queue Options
* @{
*
* MQ options can be modified at any point at runtime, unless otherwise noted.
* The following example shows how to retrieve the current message size at
* which messages are sent as synchronous.
*
* @code{.c}
uint32_t get_hfirv_size(psm2_mq_t mq)
{
uint32_t rvsize;
psm2_getopt(mq, PSM2_MQ_RNDV_HFI_SZ, &rvsize);
return rvsize;
}
@endcode
*/
/** @brief Get an MQ option (Deprecated. Use psm2_getopt with PSM2_COMPONENT_MQ)
*
* Function to retrieve the value of an MQ option.
*
* @param[in] mq Matched Queue handle
* @param[in] option Index of option to retrieve. Possible values are:
* @li @ref PSM2_MQ_RNDV_HFI_SZ
* @li @ref PSM2_MQ_RNDV_SHM_SZ
* @li @ref PSM2_MQ_MAX_SYSBUF_MBYTES
*
* @param[in] value Pointer to storage that can be used to store the value of
* the option to be set. It is up to the user to ensure that the
* pointer points to a memory location large enough to accommodate
* the value associated to the type. Each option documents the size
* associated to its value.
*
* @returns PSM2_OK if option could be retrieved.
* @returns PSM2_PARAM_ERR if the option is not a valid option number
*/
psm2_error_t psm2_mq_getopt(psm2_mq_t mq, int option, void *value);
/** @brief Set an MQ option (Deprecated. Use psm2_setopt with PSM2_COMPONENT_MQ)
*
* Function to set the value of an MQ option.
*
* @param[in] mq Matched Queue handle
* @param[in] option Index of option to retrieve. Possible values are:
* @li @ref PSM2_MQ_RNDV_HFI_SZ
* @li @ref PSM2_MQ_RNDV_SHM_SZ
* @li @ref PSM2_MQ_MAX_SYSBUF_MBYTES
*
* @param[in] value Pointer to storage that contains the value to be updated
* for the supplied option number. It is up to the user to
* ensure that the pointer points to a memory location with a
* correct size.
*
* @returns PSM2_OK if option could be retrieved.
* @returns PSM2_PARAM_ERR if the option is not a valid option number
* @returns PSM2_OPT_READONLY if the option to be set is a read-only option
* (currently no MQ options are read-only).
*/
psm2_error_t psm2_mq_setopt(psm2_mq_t mq, int option, const void *value);
/*! @} */
/*! @ingroup mq
* @{
*/
#define PSM2_MQ_FLAG_SENDSYNC 0x01
/**< MQ Send Force synchronous send */
#define PSM2_MQ_REQINVALID ((psm2_mq_req_t)(NULL))
/**< MQ request completion value */
#define PSM2_MQ_ANY_ADDR ((psm2_epaddr_t)NULL)
/**< MQ receive from any source epaddr */
/** @brief MQ fast-path operation enumeration
*
* To provide for quick enqueing of send/receives from within an AM handler
* PSM2 provdes fast path send/recv options that will enqueue those ops
* into the MQ. The supported operations to call in fast path are enumerated
* in the @ref psm2_mq_fp_op enum.
*/
enum psm2_mq_fp_op {
PSM2_MQ_ISEND_FP = 1,
PSM2_MQ_IRECV_FP,
};
/** @brief Post a fast-path isend/irecv into the MQ
*
* Function to only enqueue fast-path non-blocking sends or non-blocking recvs
* into a particular MQ. These calls only work if the process already holds
* the mq progress lock, this case traditionally only applies to calls from
* a registered AM Handler.
*
* This function helps to enable one-sided communication models from middleware
* such as OFI to provide fast >2KB message transfers for RMA operations.
*
* When posting irecvs every MQ message received on a particular MQ,
* the @c tag and @c tagsel parameters are used against the incoming
* message's send tag as described in @ref tagmatch.
*
* When posting isends the user gurantees that the source data will remain
* unmodified until the send is locally completed through a call such as
* @ref psm2_mq_wait or @ref psm2_mq_test.
*
* Progress on the operations enqueued into the MQ will may not occur until
* the next PSM2 progress API is invoked.
*
* @param[in] ep PSM2 endpoint
* @param[in] mq Matched Queue Handle
* @param[in] addr Destination EP address (used only on isends)
* @param[in] tag Send/Receive tag
* @param[in] tagsel Receive tag selector (used only on irecvs)
* @param[in] flags Send/Receive Flags
* @param[in] buf Send/Receive buffer
* @param[in] len Send/Receive buffer length
* @param[in] context User context pointer, available in @ref psm2_mq_status_t
* upon completion
* @param[in] fp_type Fast-path op requested
* @param[out] req PSM MQ Request handle created by the preposted receive, to
* be used for explicitly controlling message receive
* completion.
*
* @post The supplied buffer is given to MQ to match against incoming
* messages unless it is cancelled via @ref psm2_mq_cancel @e before any
* match occurs.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The receive buffer has successfully been posted to the MQ.
*/
psm2_error_t
psm2_mq_fp_msg(psm2_ep_t ep, psm2_mq_t mq, psm2_epaddr_t addr, psm2_mq_tag_t *tag,
psm2_mq_tag_t *tagsel, uint32_t flags, void *buf, uint32_t len,
void *context, enum psm2_mq_fp_op fp_type, psm2_mq_req_t *req);
/** @brief Post a receive to a Matched Queue with tag selection criteria
*
* Function to receive a non-blocking MQ message by providing a preposted
* buffer. For every MQ message received on a particular MQ, the @c tag and @c
* tagsel parameters are used against the incoming message's send tag as
* described in @ref tagmatch.
*
* @param[in] mq Matched Queue Handle
* @param[in] rtag Receive tag
* @param[in] rtagsel Receive tag selector
* @param[in] flags Receive flags (None currently supported)
* @param[in] buf Receive buffer
* @param[in] len Receive buffer length
* @param[in] context User context pointer, available in @ref psm2_mq_status_t
* upon completion
* @param[out] req PSM MQ Request handle created by the preposted receive, to
* be used for explicitly controlling message receive
* completion.
*
* @post The supplied receive buffer is given to MQ to match against incoming
* messages unless it is cancelled via @ref psm2_mq_cancel @e before any
* match occurs.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The receive buffer has successfully been posted to the MQ.
*/
psm2_error_t
psm2_mq_irecv(psm2_mq_t mq, uint64_t rtag, uint64_t rtagsel, uint32_t flags,
void *buf, uint32_t len, void *context, psm2_mq_req_t *req);
/** @brief Post a receive to a Matched Queue with source and tag selection
* criteria
*
* Function to receive a non-blocking MQ message by providing a preposted
* buffer. For every MQ message received on a particular MQ, the @c src, @c tag
* and @c tagsel parameters are used against the incoming message's send tag as
* described in @ref tagmatch.
*
* @param[in] mq Matched Queue Handle
* @param[in] src Source (sender's) epaddr (may be PSM2_MQ_ANY_ADDR)
* @param[in] rtag Receive tag
* @param[in] rtagsel Receive tag selector
* @param[in] flags Receive flags (None currently supported)
* @param[in] buf Receive buffer
* @param[in] len Receive buffer length
* @param[in] context User context pointer, available in @ref psm2_mq_status2_t
* upon completion
* @param[out] req PSM MQ Request handle created by the preposted receive, to
* be used for explicitly controlling message receive
* completion.
*
* @post The supplied receive buffer is given to MQ to match against incoming
* messages unless it is cancelled via @ref psm2_mq_cancel @e before any
* match occurs.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The receive buffer has successfully been posted to the MQ.
*/
psm2_error_t
psm2_mq_irecv2(psm2_mq_t mq, psm2_epaddr_t src, psm2_mq_tag_t *rtag,
psm2_mq_tag_t *rtagsel, uint32_t flags, void *buf, uint32_t len,
void *context, psm2_mq_req_t *req);
/** @brief Post a receive to a Matched Queue with matched request
*
* Function to receive a non-blocking MQ message by providing a preposted
* buffer. The provided request should already be matched using the @ref
* psm2_mq_improbe or @ref psm2_mq_improbe2 routines. It is an error to pass a
* request that has not already been matched by one of those routines.
*
* @param[in] mq Matched Queue Handle
* @param[in] flags Receive flags (None currently supported)
* @param[in] buf Receive buffer
* @param[in] len Receive buffer length
* @param[in] context User context pointer, available in @ref psm2_mq_status_t
* upon completion
* @param[inout] reqo PSM MQ Request handle matched previously by a matched
* probe routine (@ref psm2_mq_improbe or @ref
* psm2_mq_improbe2), also to be used for explicitly
* controlling message receive completion.
*
* @post The supplied receive buffer is given to MQ to deliver the matched
* message.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The receive buffer has successfully been posted to the MQ.
*/
psm2_error_t
psm2_mq_imrecv(psm2_mq_t mq, uint32_t flags, void *buf, uint32_t len,
void *context, psm2_mq_req_t *reqo);
/** @brief Send a blocking MQ message
*
* Function to send a blocking MQ message, whereby the message is locally
* complete and the source data can be modified upon return.
*
* @param[in] mq Matched Queue Handle
* @param[in] dest Destination EP address
* @param[in] flags Message flags, currently:
* @li PSM2_MQ_FLAG_SENDSYNC tells PSM to send the message
* synchronously, meaning that the message will not be sent until
* the receiver acknowledges that it has matched the send with a
* receive buffer.
* @param[in] stag Message Send Tag
* @param[in] buf Source buffer pointer
* @param[in] len Length of message starting at @c buf.
*
* @post The source buffer is reusable and the send is locally complete.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* @note This send function has been implemented to best suit MPI_Send.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The message has been successfully sent.
*/
psm2_error_t
psm2_mq_send(psm2_mq_t mq, psm2_epaddr_t dest, uint32_t flags, uint64_t stag,
const void *buf, uint32_t len);
/** @brief Send a blocking MQ message
*
* Function to send a blocking MQ message, whereby the message is locally
* complete and the source data can be modified upon return.
*
* @param[in] mq Matched Queue Handle
* @param[in] dest Destination EP address
* @param[in] flags Message flags, currently:
* @li PSM2_MQ_FLAG_SENDSYNC tells PSM to send the message
* synchronously, meaning that the message will not be sent until
* the receiver acknowledges that it has matched the send with a
* receive buffer.
* @param[in] stag Message Send Tag
* @param[in] buf Source buffer pointer
* @param[in] len Length of message starting at @c buf.
*
* @post The source buffer is reusable and the send is locally complete.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* @note This send function has been implemented to best suit MPI_Send.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The message has been successfully sent.
*/
psm2_error_t
psm2_mq_send2(psm2_mq_t mq, psm2_epaddr_t dest, uint32_t flags,
psm2_mq_tag_t *stag, const void *buf, uint32_t len);
/** @brief Send a non-blocking MQ message
*
* Function to initiate the send of a non-blocking MQ message, whereby the
* user guarantees that the source data will remain unmodified until the send
* is locally completed through a call such as @ref psm2_mq_wait or @ref
* psm2_mq_test.
*
* @param[in] mq Matched Queue Handle
* @param[in] dest Destination EP address
* @param[in] flags Message flags, currently:
* @li PSM2_MQ_FLAG_SENDSYNC tells PSM to send the message
* synchronously, meaning that the message will not be sent until
* the receiver acknowledges that it has matched the send with a
* receive buffer.
* @param[in] stag Message Send Tag
* @param[in] buf Source buffer pointer
* @param[in] len Length of message starting at @c buf.
* @param[in] context Optional user-provided pointer available in @ref
* psm2_mq_status_t when the send is locally completed.
* @param[out] req PSM MQ Request handle created by the non-blocking send, to
* be used for explicitly controlling message completion.
*
* @post The source buffer is not reusable and the send is not locally complete
* until its request is completed by either @ref psm2_mq_test or @ref
* psm2_mq_wait.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* @note This send function has been implemented to suit MPI_Isend.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The message has been successfully initiated.
*
* @code{.c}
psm2_mq_req_t
non_blocking_send(const psm2_mq_t mq, psm2_epaddr_t dest_ep,
const void *buf, uint32_t len,
int context_id, int send_tag, const my_request_t *req)
{
psm2_mq_req_t req_mq;
// Set up our send tag, assume that "my_rank" is global and represents
// the rank of this process in the job
uint64_t tag = ( ((context_id & 0xffff) << 48) |
((my_rank & 0xffff) << 32) |
((send_tag & 0xffffffff)) );
psm2_mq_isend(mq, dest_ep,
0, // no flags
tag,
buf,
len,
req, // this req is available in psm2_mq_status_t when one
// of the synchronization functions is called.
&req_mq);
return req_mq;
}
@endcode
*/
psm2_error_t
psm2_mq_isend(psm2_mq_t mq, psm2_epaddr_t dest, uint32_t flags, uint64_t stag,
const void *buf, uint32_t len, void *context, psm2_mq_req_t *req);
/** @brief Send a non-blocking MQ message
*
* Function to initiate the send of a non-blocking MQ message, whereby the
* user guarantees that the source data will remain unmodified until the send
* is locally completed through a call such as @ref psm2_mq_wait or @ref
* psm2_mq_test.
*
* @param[in] mq Matched Queue Handle
* @param[in] dest Destination EP address
* @param[in] flags Message flags, currently:
* @li PSM2_MQ_FLAG_SENDSYNC tells PSM to send the message
* synchronously, meaning that the message will not be sent until
* the receiver acknowledges that it has matched the send with a
* receive buffer.
* @param[in] stag Message Send Tag, array of three 32-bit values.
* @param[in] buf Source buffer pointer
* @param[in] len Length of message starting at @c buf.
* @param[in] context Optional user-provided pointer available in @ref
* psm2_mq_status2_t when the send is locally completed.
* @param[out] req PSM MQ Request handle created by the non-blocking send, to
* be used for explicitly controlling message completion.
*
* @post The source buffer is not reusable and the send is not locally complete
* until its request is completed by either @ref psm2_mq_test or @ref
* psm2_mq_wait.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* @note This send function has been implemented to suit MPI_Isend.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The message has been successfully initiated.
*
* @code{.c}
psm2_mq_req_t
non_blocking_send(const psm2_mq_t mq, psm2_epaddr_t dest_ep,
const void *buf, uint32_t len,
int context_id, int send_tag, const my_request_t *req)
{
psm2_mq_req_t req_mq;
// Set up our send tag, assume that "my_rank" is global and represents
// the rank of this process in the job
psm2_mq_tag_t tag;
tag.tag[0] = send_tag;
tag.tag[1] = my_rank;
tag.tag[2] = context_id;
psm2_mq_isend(mq, dest_ep,
0, // no flags
&tag,
buf,
len,
req, // this req is available in psm2_mq_status2_t when one
// of the synchronization functions is called.
&req_mq);
return req_mq;
}
@endcode
*/
psm2_error_t
psm2_mq_isend2(psm2_mq_t mq, psm2_epaddr_t dest, uint32_t flags,
psm2_mq_tag_t *stag, const void *buf, uint32_t len, void *context,
psm2_mq_req_t *req);
/** @brief Try to Probe if a message is received matching tag selection
* criteria
*
* Function to verify if a message matching the supplied tag and tag selectors
* has been received. The message is not fully matched until the user
* provides a buffer with the successfully matching tag selection criteria
* through @ref psm2_mq_irecv.
* Probing for messages may be useful if the size of the
* message to be received is unknown, in which case its size will be
* available in the @c msg_length member of the returned @c status.
*
* Function ensures progress if matching request wasn’t found
* after the first attempt.
*
* @param[in] mq Matched Queue Handle
* @param[in] rtag Message receive tag
* @param[in] rtagsel Message receive tag selector
* @param[out] status Upon return, @c status is filled with information
* regarding the matching send.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error codes are returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The iprobe is successful and status is updated if non-NULL.
* @retval PSM2_MQ_NO_COMPLETIONS The iprobe is unsuccessful and status is
* unchanged.
*/
psm2_error_t
psm2_mq_iprobe(psm2_mq_t mq, uint64_t rtag, uint64_t rtagsel,
psm2_mq_status_t *status);
/** @brief Try to Probe if a message is received matching source and tag
* selection criteria
*
* Function to verify if a message matching the supplied source, tag, and tag
* selectors has been received. The message is not fully matched until the
* user provides a buffer with the successfully matching tag selection criteria
* through @ref psm2_mq_irecv. Probing for messages may be useful if the size
* of the message to be received is unknown, in which case its size will be
* available in the @c msg_length member of the returned @c status.
*
* Function ensures progress if matching request wasn’t found
* after the first attempt.
*
* @param[in] mq Matched Queue Handle
* @param[in] src Source (sender's) epaddr (may be PSM2_MQ_ANY_ADDR)
* @param[in] rtag Message receive tag
* @param[in] rtagsel Message receive tag selector
* @param[out] status Upon return, @c status is filled with information
* regarding the matching send.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error codes are returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The iprobe is successful and status is updated if non-NULL.
* @retval PSM2_MQ_NO_COMPLETIONS The iprobe is unsuccessful and status is
* unchanged.
*/
psm2_error_t
psm2_mq_iprobe2(psm2_mq_t mq, psm2_epaddr_t src, psm2_mq_tag_t *rtag,
psm2_mq_tag_t *rtagsel, psm2_mq_status2_t *status);
/** @brief Try to Probe if a message is received matching tag selection
* criteria
*
* Function to verify if a message matching the supplied source, tag, and tag
* selectors has been received. If a match is successful, the message is
* removed from the matching queue and returned as a request object. The
* message can be received using @ref psm2_mq_imrecv. It is erroneous to use
* the request object returned by @ref psm2_mq_improbe for any purpose other
* than passing to @ref psm2_mq_imrecv. Probing for messages may be useful if
* the size of the message to be received is unknown, in which case its size
* will be available in the @c msg_length member of the returned @c status.
*
* Function ensures progress if matching request wasn’t found
* after the first attempt.
*
* @param[in] mq Matched Queue Handle
* @param[in] rtag Message receive tag
* @param[in] rtagsel Message receive tag selector
* @param[out] req PSM MQ Request handle, to be used for receiving the matched
* message.
* @param[out] status Upon return, @c status is filled with information
* regarding the matching send.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error codes are returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The iprobe is successful and status is updated if non-NULL.
* @retval PSM2_MQ_NO_COMPLETIONS The iprobe is unsuccessful and status is unchanged.
*/
psm2_error_t
psm2_mq_improbe(psm2_mq_t mq, uint64_t rtag, uint64_t rtagsel, psm2_mq_req_t *req,
psm2_mq_status_t *status);
/** @brief Try to Probe if a message is received matching source and tag
* selection criteria
*
* Function to verify if a message matching the supplied tag and tag selectors
* has been received. If a match is successful, the message is removed from
* the matching queue and returned as a request object. The message can be
* received using @ref psm2_mq_imrecv. It is erroneous to use the request
* object returned by @ref psm2_mq_improbe for any purpose other than passing to
* @ref psm2_mq_imrecv. Probing for messages may be useful if the size of the
* message to be received is unknown, in which case its size will be available
* in the @c msg_length member of the returned @c status.
*
* Function ensures progress if matching request wasn’t found
* after the first attempt.
*
* @param[in] mq Matched Queue Handle
* @param[in] src Source (sender's) epaddr (may be PSM2_MQ_ANY_ADDR)
* @param[in] rtag Message receive tag
* @param[in] rtagsel Message receive tag selector
* @param[out] reqo PSM MQ Request handle, to be used for receiving the matched
* message.
* @param[out] status Upon return, @c status is filled with information
* regarding the matching send.
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error codes are returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The iprobe is successful and status is updated if non-NULL.
* @retval PSM2_MQ_NO_COMPLETIONS The iprobe is unsuccessful and status is unchanged.
*/
psm2_error_t
psm2_mq_improbe2(psm2_mq_t mq, psm2_epaddr_t src, psm2_mq_tag_t *rtag,
psm2_mq_tag_t *rtagsel, psm2_mq_req_t *reqo,
psm2_mq_status2_t *status);
/** @brief Query for non-blocking requests ready for completion.
*
* Function to query a particular MQ for non-blocking requests that are ready
* for completion. Requests "ready for completion" are not actually considered
* complete by MQ until they are returned to the MQ library through @ref
* psm2_mq_wait or @ref psm2_mq_test.
*
* If the user can deal with consuming request completions in the order in
* which they complete, this function can be used both for completions and for
* ensuring progress. The latter requirement is satisfied when the user
* peeks an empty completion queue as a side effect of always aggressively
* peeking and completing all an MQ's requests ready for completion.
*
*
* @param[in] mq Matched Queue Handle
* @param[in,out] req MQ non-blocking request
* @param[in] status Optional MQ status, can be NULL.
*
* @post The user has ensured progress if the function returns @ref
* PSM2_MQ_NO_COMPLETIONS
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error codes are returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The peek is successful and @c req is updated with a request
* ready for completion. If @c status is non-NULL, it is also
* updated.
*
* @retval PSM2_MQ_NO_COMPLETIONS The peek is not successful, meaning that there
* are no further requests ready for completion.
* The contents of @c req and @c status remain
* unchanged.
* @code{.c}
// Example that uses ipeek_mq_ipeek to make progress instead of psm2_poll
// We return the amount of non-blocking requests that we've completed
int main_progress_loop(psm2_mq_t mq)
{
int num_completed = 0;
psm2_mq_req_t req;
psm2_mq_status_t status;
psm2_error_t err;
my_request_t *myreq;
do {
err = psm2_mq_ipeek(mq, &req,
NULL); // No need for status in ipeek here
if (err == PSM2_MQ_NO_COMPLETIONS)
return num_completed;
else if (err != PSM2_OK)
goto errh;
num_completed++;
// We obtained 'req' at the head of the completion queue. We can
// now free the request with PSM and obtain our original reques
// from the status' context
err = psm2_mq_test(&req, // will be marked as invalid
&status); // we need the status
myreq = (my_request_t *) status.context;
// handle the completion for myreq whether myreq is a posted receive
// or a non-blocking send.
}
while (1);
}
@endcode
*/
psm2_error_t
psm2_mq_ipeek(psm2_mq_t mq, psm2_mq_req_t *req, psm2_mq_status_t *status);
/** @brief Query for non-blocking requests ready for completion.
*
* Function to query a particular MQ for non-blocking requests that are ready
* for completion. Requests "ready for completion" are not actually considered
* complete by MQ until they are returned to the MQ library through @ref
* psm2_mq_wait or @ref psm2_mq_test.
*
* If the user can deal with consuming request completions in the order in
* which they complete, this function can be used both for completions and for
* ensuring progress. The latter requirement is satisfied when the user
* peeks an empty completion queue as a side effect of always aggressively
* peeking and completing all an MQ's requests ready for completion.
*
*
* @param[in] mq Matched Queue Handle
* @param[in,out] req MQ non-blocking request
* @param[in] status Optional MQ status, can be NULL.
*
* @post The user has ensured progress if the function returns @ref
* PSM2_MQ_NO_COMPLETIONS
*
* @remark This function may be called simultaneously from multiple threads
* as long as different MQ arguments are used in each of the calls.
*
* The following error codes are returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The peek is successful and @c req is updated with a request
* ready for completion. If @c status is non-NULL, it is also
* updated.
*
* @retval PSM2_MQ_NO_COMPLETIONS The peek is not successful, meaning that there
* are no further requests ready for completion.
* The contents of @c req and @c status remain
* unchanged.
* @code{.c}
// Example that uses ipeek_mq_ipeek to make progress instead of psm2_poll
// We return the amount of non-blocking requests that we've completed
int main_progress_loop(psm2_mq_t mq)
{
int num_completed = 0;
psm2_mq_req_t req;
psm2_mq_status2_t status;
psm2_error_t err;
my_request_t *myreq;
do {
err = psm2_mq_ipeek2(mq, &req,
NULL); // No need for status in ipeek here
if (err == PSM2_MQ_NO_COMPLETIONS)
return num_completed;
else if (err != PSM2_OK)
goto errh;
num_completed++;
// We obtained 'req' at the head of the completion queue. We can
// now free the request with PSM and obtain our original reques
// from the status' context
err = psm2_mq_test2(&req, // will be marked as invalid
&status); // we need the status
myreq = (my_request_t *) status.context;
// handle the completion for myreq whether myreq is a posted receive
// or a non-blocking send.
}
while (1);
}
@endcode
*/
psm2_error_t
psm2_mq_ipeek2(psm2_mq_t mq, psm2_mq_req_t *req, psm2_mq_status2_t *status);
/** @brief User defined Callback function handling copy of MQ request into user datatype
*
* Callback function used to convert an MQ request into a user's desired
* status structure. The user's callback function converts the MQ request into
* the provided status_array at the specified index.
*
* @param[in] req MQ External non-blocking Request structure
* @param[in] status_array Array of User defined status datatypes
* @param[in] entry_index Index in array where the converted request will be
* stored if successful
*
* The following error codes are returned.
*
* @retval < 0 The MQ conversion failed with a user defined error.
*
* @retval 0 The MQ was successfully processed, but was not saved
* in the provided @c status_array.
*
* @retval 1 The MQ was successfully processed and was saved in the
* @c status_array at the specified index.
*
* @retval >1 The MQ was successfully processed and was saved in the
* @c status_array at the specified index. This should
* be the last MQ converted in the batch, even if there
* are still spaces in @c status_array.
*/
typedef int (*psmi_mq_status_copy_user_t) (struct psm2_mq_req_user *req,
void *status_array, int entry_index);
/** @brief Check and dequeue MQ requests into a user's status array using a callback.
*
* Function to atomically check and dequeue MQ entries from the completed
* queue and copy the MQ requests into a user's status datatype through a
* status_copy callback function.
*
* Once the MQ request has been successfully converted by the callback, the
* MQ request is freed and the next entry is processed making the supplied
* Request pointer invalid.
*
* The variable "count" passed in will only be increased if the MQ request was
* successfully stored into the user's passed in array. Otherwise the count
* variable is unchanged.
*
* NOTE: a count of 0 passed into psm2_mq_ipeek_dequeue_multi will result in
* no MQ elements being processed.
*
* @param[in] mq Matched Queue Handle
* @param[in] status_array Array of User defined status datatypes
* @param[in] status_copy Callback function pointer to convert
* MQ to caller datatype
* @param[in/out] count [in]Size of status_array, [out]number of elements
* populated into status_array or user's error return code
*
* The following error codes are returned.
*
* @retval PSM2_OK The dequeue operation was successful and populated the
* full @c status_array up to @c count entries. The parameter
* @c count is equal to the count passed in by the user.
*
* @retval PSM2_MQ_NO_COMPLETIONS The dequeue operation was not able to read
* @c count entries into the @c status_array. The number
* of entries that were successfully written to the
* @c status_array is set in the @c count for the user.
*
* @retval PSM2_INTERNAL_ERR The @c status_copy failed to successfully
* copy the status entry into the user's datatype.
* @c count is set to the return code from the
* @c status_copy.
*/
psm2_error_t
psm2_mq_ipeek_dequeue_multi(psm2_mq_t mq, void *status_array,
psmi_mq_status_copy_user_t status_copy, int *count);
/** @brief Check and dequeue the first request entry from the completed queue.
*
* Function to atomically check and dequeue the first entry from the completed
* queue. It must be paired with function psm2_mq_req_free, which returns the
* request to PSM2 library.
*
* @param[in] mq Matched Queue Handle
* @param[out] req PSM MQ Request handle, to be used for receiving the matched
* message.
*
* The following error codes are returned.
*
* @retval PSM2_OK The dequeue operation was successful and @c req is updated
* with a request ready for completion.
*
* @retval PSM2_MQ_NO_COMPLETIONS The dequeue operation was not successful,
* meaning that there are no further requests ready
* for completion. The contents of @c req remain
* unchanged.
*/
psm2_error_t
psm2_mq_ipeek_dequeue(psm2_mq_t mq, psm2_mq_req_t *req);
/** @brief Return the request to PSM2 library.
*
* Function returns the request previously obtained via psm2_mq_ipeek_dequeue
* to the PSM2 library.
*
* @param[in] mq Matched Queue Handle
* @param[in] req PSM MQ Request handle to be returned to PSM2 library.
If @p req is NULL, no operation is performed.
*
* The following error codes are returned.
*
* @retval PSM2_OK Return of an object to PSM2 library pool was successful.
*/
psm2_error_t
psm2_mq_req_free(psm2_mq_t mq, psm2_mq_req_t req);
/** @brief Wait until a non-blocking request completes
*
* Function to wait on requests created from either preposted receive buffers
* or non-blocking sends. This is the only blocking function in the MQ
* interface and will poll until the request is complete as per the progress
* semantics explained in @ref mq_progress.
*
* @param[in,out] request MQ non-blocking request
* @param[out] status Updated if non-NULL when request successfully completes
*
* @pre The user has obtained a valid MQ request by calling @ref psm2_mq_isend
* or @ref psm2_mq_irecv and passes a pointer to enough storage to write
* the output of a @ref psm2_mq_status_t or NULL if status is to be
* ignored.
*
* @pre Since MQ will internally ensure progress while the user is
* suspended, the user need not ensure that progress is made prior to
* calling this function.
*
* @post The request is assigned the value @ref PSM2_MQ_REQINVALID and all
* associated MQ request storage is released back to the MQ library.
*
* @remark This function may be called simultaneously from multiple threads
* as long as the requests that are used in each of the calls are
* associated with different MQs.
*
* @remarks
* @li This function ensures progress on the endpoint as long as the request
* is incomplete.
* @li @c status can be NULL, in which case no status is written upon
* completion.
* @li If @c request is @ref PSM2_MQ_REQINVALID, the function returns
* immediately.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The request is complete or the value of @c was
* @ref PSM2_MQ_REQINVALID.
*
*/
psm2_error_t
psm2_mq_wait(psm2_mq_req_t *request, psm2_mq_status_t *status);
/** @brief Wait until a non-blocking request completes
*
* Function to wait on requests created from either preposted receive buffers
* or non-blocking sends. This is the only blocking function in the MQ
* interface and will poll until the request is complete as per the progress
* semantics explained in @ref mq_progress.
*
* @param[in,out] request MQ non-blocking request
* @param[out] status Updated if non-NULL when request successfully completes
*
* @pre The user has obtained a valid MQ request by calling @ref psm2_mq_isend
* or @ref psm2_mq_irecv and passes a pointer to enough storage to write
* the output of a @ref psm2_mq_status2_t or NULL if status is to be
* ignored.
*
* @pre Since MQ will internally ensure progress while the user is
* suspended, the user need not ensure that progress is made prior to
* calling this function.
*
* @post The request is assigned the value @ref PSM2_MQ_REQINVALID and all
* associated MQ request storage is released back to the MQ library.
*
* @remark This function may be called simultaneously from multiple threads
* as long as the requests that are used in each of the calls are
* associated with different MQs.
*
* @remarks
* @li This function ensures progress on the endpoint as long as the request
* is incomplete.
* @li @c status can be NULL, in which case no status is written upon
* completion.
* @li If @c request is @ref PSM2_MQ_REQINVALID, the function returns
* immediately.
*
* The following error code is returned. Other errors are handled by the PSM
* error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The request is complete or the value of @c was
* @ref PSM2_MQ_REQINVALID.
*
*/
psm2_error_t
psm2_mq_wait2(psm2_mq_req_t *request, psm2_mq_status2_t *status);
/** @brief Test if a non-blocking request is complete
*
* Function to test requests created from either preposted receive buffers or
* non-blocking sends for completion. Unlike @ref psm2_mq_wait, this function
* tests @c request for completion and @e never ensures progress directly or
* indirectly. It is up to the user to employ some of the progress functions
* described in @ref mq_progress to ensure progress if the user chooses to
* exclusively test requests for completion.
*
* Testing a request for completion @e never internally ensure progress in
* order to be useful to construct higher-level completion tests over arrays to
* test some, all or any request that has completed. For testing arrays of
* requests, it is preferable for performance reasons to only ensure progress
* once before testing a set of requests for completion.
*
* @param[in,out] request MQ non-blocking request
* @param[out] status Updated if non-NULL and the request successfully
* completes
*
* @pre The user has obtained a valid MQ request by calling @ref psm2_mq_isend
* or @ref psm2_mq_irecv and passes a pointer to enough storage to write
* the output of a @ref psm2_mq_status_t or NULL if status is to be
* ignored.
*
* @pre The user has ensured progress on the Matched Queue if @ref
* psm2_mq_test is exclusively used for guaranteeing request completions.
*
* @post If the request is complete, the request is assigned the value @ref
* PSM2_MQ_REQINVALID and all associated MQ request storage is released
* back to the MQ library. If the request is incomplete, the contents of
* @c request is unchanged.
*
* @post The user will ensure progress on the Matched Queue if @ref
* psm2_mq_test is exclusively used for guaranteeing request completions.
*
* @remark This function may be called simultaneously from multiple threads
* as long as the requests that are used in each of the calls are
* associated with different MQs.
*
* The following two errors are always returned. Other errors are handled by
* the PSM error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The request is complete and @c request is set to @ref
* PSM2_MQ_REQINVALID or the value of @c was PSM2_MQ_REQINVALID
*
* @retval PSM2_MQ_NO_COMPLETIONS The request is not complete and @c request is
* unchanged.
*
* @code{.c}
// Function that returns the first completed request in an array
// of requests.
void *
user_testany(psm2_ep_t ep, psm2_mq_req_t *allreqs, int nreqs)
{
int i;
void *context = NULL;
// Ensure progress only once
psm2_poll(ep);
// Test for at least one completion and return it's context
psm2_mq_status_t stat;
for (i = 0; i < nreqs; i++) {
if (psm2_mq_test(&allreqs[i], &stat) == PSM2_OK) {
context = stat.context;
break;
}
}
return context;
}
@endcode
*/
psm2_error_t
psm2_mq_test(psm2_mq_req_t *request, psm2_mq_status_t *status);
/** @brief Test if a non-blocking request is complete
*
* Function to test requests created from either preposted receive buffers or
* non-blocking sends for completion. Unlike @ref psm2_mq_wait, this function
* tests @c request for completion and @e never ensures progress directly or
* indirectly. It is up to the user to employ some of the progress functions
* described in @ref mq_progress to ensure progress if the user chooses to
* exclusively test requests for completion.
*
* Testing a request for completion @e never internally ensure progress in
* order to be useful to construct higher-level completion tests over arrays to
* test some, all or any request that has completed. For testing arrays of
* requests, it is preferable for performance reasons to only ensure progress
* once before testing a set of requests for completion.
*
* @param[in,out] request MQ non-blocking request
* @param[out] status Updated if non-NULL and the request successfully
* completes
*
* @pre The user has obtained a valid MQ request by calling @ref psm2_mq_isend
* or @ref psm2_mq_irecv and passes a pointer to enough storage to write
* the output of a @ref psm2_mq_status2_t or NULL if status is to be
* ignored.
*
* @pre The user has ensured progress on the Matched Queue if @ref
* psm2_mq_test is exclusively used for guaranteeing request completions.
*
* @post If the request is complete, the request is assigned the value @ref
* PSM2_MQ_REQINVALID and all associated MQ request storage is released
* back to the MQ library. If the request is incomplete, the contents of
* @c request is unchanged.
*
* @post The user will ensure progress on the Matched Queue if @ref
* psm2_mq_test is exclusively used for guaranteeing request completions.
*
* @remark This function may be called simultaneously from multiple threads
* as long as the requests that are used in each of the calls are
* associated with different MQs.
*
* The following two errors are always returned. Other errors are handled by
* the PSM error handler (@ref psm2_error_register_handler).
*
* @retval PSM2_OK The request is complete and @c request is set to @ref
* PSM2_MQ_REQINVALID or the value of @c was PSM2_MQ_REQINVALID
*
* @retval PSM2_MQ_NO_COMPLETIONS The request is not complete and @c request is
* unchanged.
*
* @code{.c}
// Function that returns the first completed request in an array
// of requests.
void *
user_testany(psm2_ep_t ep, psm2_mq_req_t *allreqs, int nreqs)
{
int i;
void *context = NULL;
// Ensure progress only once
psm2_poll(ep);
// Test for at least one completion and return it's context
psm2_mq_status2_t stat;
for (i = 0; i < nreqs; i++) {
if (psm2_mq_test2(&allreqs[i], &stat) == PSM2_OK) {
context = stat.context;
break;
}
}
return context;
}
@endcode
*/
psm2_error_t
psm2_mq_test2(psm2_mq_req_t *request, psm2_mq_status2_t *status);
/** @brief Cancel a preposted request
*
* Function to cancel a preposted receive request returned by @ref
* psm2_mq_irecv. It is currently illegal to cancel a send request initiated
* with @ref psm2_mq_isend.
*
* @pre The user has obtained a valid MQ request by calling @ref psm2_mq_isend.
*
* @post Whether the cancel is successful or not, the user returns the
* request to the library by way of @ref psm2_mq_test or @ref
* psm2_mq_wait.
*
* @remark This function may be called simultaneously from multiple threads
* as long as the requests that are used in each of the calls are
* associated with different MQs.
*
* Only the two following errors can be returned directly, without being
* handled by the error handler (@ref psm2_error_register_handler):
*
* @retval PSM2_OK The request could be successfully cancelled such that the
* preposted receive buffer could be removed from the preposted
* receive queue before a match occurred. The associated @c
* request remains unchanged and the user must still return
* the storage to the MQ library.
*
* @retval PSM2_MQ_NO_COMPLETIONS The request could not be successfully cancelled
* since the preposted receive buffer has already
* matched an incoming message. The @c request
* remains unchanged.
*
*/
psm2_error_t psm2_mq_cancel(psm2_mq_req_t *req);
/*! @brief MQ statistics structure */
struct psm2_mq_stats {
/** Bytes received into a matched user buffer */
uint64_t rx_user_bytes;
/** Messages received into a matched user buffer */
uint64_t rx_user_num;
/** Bytes received into an unmatched system buffer */
uint64_t rx_sys_bytes;
/** Messages received into an unmatched system buffer */
uint64_t rx_sys_num;
/** Total Messages transmitted (shm and hfi) */
uint64_t tx_num;
/** Messages transmitted eagerly */
uint64_t tx_eager_num;
/** Bytes transmitted eagerly */
uint64_t tx_eager_bytes;
/** Messages transmitted using expected TID mechanism */
uint64_t tx_rndv_num;
/** Bytes transmitted using expected TID mechanism */
uint64_t tx_rndv_bytes;
/** Messages transmitted (shm only) */
uint64_t tx_shm_num;
/** Messages received through shm */
uint64_t rx_shm_num;
/** Number of system buffers allocated */
uint64_t rx_sysbuf_num;
/** Bytes allcoated for system buffers */
uint64_t rx_sysbuf_bytes;
/** Internally reserved for future use */
uint64_t _reserved[16];
};
#define PSM2_MQ_NUM_STATS 13 /**< How many stats are currently used in @ref psm2_mq_stats */
/*! @see psm2_mq_stats */
typedef struct psm2_mq_stats psm2_mq_stats_t;
/** @brief Retrieve statistics from an instantiated MQ */
void
psm2_mq_get_stats(psm2_mq_t mq, psm2_mq_stats_t *stats);
/*! @} */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
|