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
|
# Communicator Comparisons
# ------------------------
IDENT = MPI_IDENT #: Groups are identical, communicator contexts are de same
CONGRUENT = MPI_CONGRUENT #: Groups are identical, contexts are different
SIMILAR = MPI_SIMILAR #: Groups are similar, rank order differs
UNEQUAL = MPI_UNEQUAL #: Groups are different
# Communicator Topologies
# -----------------------
CART = MPI_CART #: Cartesian topology
GRAPH = MPI_GRAPH #: Graph topology
cdef class Comm:
"""
Communicator
"""
def __cinit__(self):
self.ob_mpi = MPI_COMM_NULL
def __dealloc__(self):
if not (self.flags & PyMPI_OWNED): return
CHKERR( _del_Comm(&self.ob_mpi) )
def __richcmp__(self, other, int op):
if not isinstance(self, Comm): return NotImplemented
if not isinstance(other, Comm): return NotImplemented
cdef Comm s = self, o = other
if op == 2: return (s.ob_mpi == o.ob_mpi)
elif op == 3: return (s.ob_mpi != o.ob_mpi)
else: raise TypeError(mpistr("only '==' and '!='"))
def __nonzero__(self):
return self.ob_mpi != MPI_COMM_NULL
# Group
# -----
def Get_group(self):
"""
Access the group associated with a communicator
"""
cdef Group group = Group()
CHKERR( MPI_Comm_group(self.ob_mpi, &group.ob_mpi) )
return group
property group:
"""communicator group"""
def __get__(self):
return self.Get_group()
# Communicator Accessors
# ----------------------
def Get_size(self):
"""
Return the size of a communicator
"""
cdef int size = -1
CHKERR( MPI_Comm_size(self.ob_mpi, &size) )
return size
property size:
"""number of processes in communicator"""
def __get__(self):
return self.Get_size()
def Get_rank(self):
"""
Return the rank of this process in a communicator
"""
cdef int rank = MPI_PROC_NULL
CHKERR( MPI_Comm_rank(self.ob_mpi, &rank) )
return rank
property rank:
"""rank of this process in communicator"""
def __get__(self):
return self.Get_rank()
@classmethod
def Compare(cls, Comm comm1 not None, Comm comm2 not None):
"""
Compare two communicators
"""
cdef int flag = MPI_UNEQUAL
CHKERR( MPI_Comm_compare(comm1.ob_mpi, comm2.ob_mpi, &flag) )
return flag
# Communicator Constructors
# -------------------------
def Clone(self):
"""
Clone an existing communicator
"""
cdef Comm comm = type(self)()
with nogil: CHKERR( MPI_Comm_dup(self.ob_mpi, &comm.ob_mpi) )
return comm
# Communicator Destructor
# -----------------------
def Free(self):
"""
Free a communicator
"""
with nogil: CHKERR( MPI_Comm_free(&self.ob_mpi) )
# Point to Point communication
# ----------------------------
# Blocking Send and Receive Operations
# ------------------------------------
def Send(self, buf, int dest=0, int tag=0):
"""
Blocking send
.. note:: This function may block until the message is
received. Whether or not `Send` blocks depends on
several factors and is implementation dependent
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
with nogil: CHKERR( MPI_Send(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi) )
def Recv(self, buf, int source=0, int tag=0, Status status=None):
"""
Blocking receive
.. note:: This function blocks until the message is received
"""
cdef _p_msg_p2p rmsg = message_p2p_recv(buf, source)
cdef MPI_Status *statusp = _arg_Status(status)
with nogil: CHKERR( MPI_Recv(
rmsg.buf, rmsg.count, rmsg.dtype,
source, tag, self.ob_mpi, statusp) )
# Send-Receive
# ------------
def Sendrecv(self, sendbuf, int dest=0, int sendtag=0,
recvbuf=None, int source=0, int recvtag=0,
Status status=None):
"""
Send and receive a message
.. note:: This function is guaranteed not to deadlock in
situations where pairs of blocking sends and receives may
deadlock.
.. caution:: A common mistake when using this function is to
mismatch the tags with the source and destination ranks,
which can result in deadlock.
"""
cdef _p_msg_p2p smsg = message_p2p_send(sendbuf, dest)
cdef _p_msg_p2p rmsg = message_p2p_recv(recvbuf, source)
cdef MPI_Status *statusp = _arg_Status(status)
with nogil: CHKERR( MPI_Sendrecv(
smsg.buf, smsg.count, smsg.dtype, dest, sendtag,
rmsg.buf, rmsg.count, rmsg.dtype, source, recvtag,
self.ob_mpi, statusp) )
def Sendrecv_replace(self, buf,
int dest=0, int sendtag=0,
int source=0, int recvtag=0,
Status status=None):
"""
Send and receive a message
.. note:: This function is guaranteed not to deadlock in
situations where pairs of blocking sends and receives may
deadlock.
.. caution:: A common mistake when using this function is to
mismatch the tags with the source and destination ranks,
which can result in deadlock.
"""
cdef int rank = MPI_PROC_NULL
if dest != MPI_PROC_NULL: rank = dest
if source != MPI_PROC_NULL: rank = source
cdef _p_msg_p2p rmsg = message_p2p_recv(buf, rank)
cdef MPI_Status *statusp = _arg_Status(status)
with nogil: CHKERR( MPI_Sendrecv_replace(
rmsg.buf, rmsg.count, rmsg.dtype,
dest, sendtag, source, recvtag,
self.ob_mpi, statusp) )
# Nonblocking Communications
# --------------------------
def Isend(self, buf, int dest=0, int tag=0):
"""
Nonblocking send
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
cdef Request request = Request()
with nogil: CHKERR( MPI_Isend(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi, &request.ob_mpi) )
return request
def Irecv(self, buf, int source=0, int tag=0):
"""
Nonblocking receive
"""
cdef _p_msg_p2p rmsg = message_p2p_recv(buf, source)
cdef Request request = Request()
with nogil: CHKERR( MPI_Irecv(
rmsg.buf, rmsg.count, rmsg.dtype,
source, tag, self.ob_mpi, &request.ob_mpi) )
return request
# Probe
# -----
def Probe(self, int source=0, int tag=0, Status status=None):
"""
Blocking test for a message
.. note:: This function blocks until the message arrives.
"""
cdef MPI_Status *statusp = _arg_Status(status)
with nogil: CHKERR( MPI_Probe(
source, tag, self.ob_mpi, statusp) )
def Iprobe(self, source=0, tag=0, Status status=None):
"""
Nonblocking test for a message
"""
cdef bint flag = 0
cdef MPI_Status *statusp = _arg_Status(status)
with nogil: CHKERR( MPI_Iprobe(
source, tag, self.ob_mpi, &flag, statusp) )
return flag
# Persistent Communication
# ------------------------
def Send_init(self, buf, int dest=0, int tag=0):
"""
Create a persistent request for a standard send
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
cdef Prequest request = Prequest()
with nogil: CHKERR( MPI_Send_init(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi, &request.ob_mpi) )
return request
def Recv_init(self, buf, int source=0, int tag=0):
"""
Create a persistent request for a receive
"""
cdef _p_msg_p2p rmsg = message_p2p_recv(buf, source)
cdef Prequest request = Prequest()
with nogil: CHKERR( MPI_Recv_init(
rmsg.buf, rmsg.count, rmsg.dtype,
source, tag, self.ob_mpi, &request.ob_mpi) )
return request
# Communication Modes
# -------------------
# Blocking calls
def Bsend(self, buf, int dest=0, int tag=0):
"""
Blocking send in buffered mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
with nogil: CHKERR( MPI_Bsend(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi) )
def Ssend(self, buf, dest=0, tag=0):
"""
Blocking send in synchronous mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
with nogil: CHKERR( MPI_Ssend(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi) )
def Rsend(self, buf, int dest=0, int tag=0):
"""
Blocking send in ready mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
with nogil: CHKERR( MPI_Rsend(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi) )
# Nonblocking calls
def Ibsend(self, buf, int dest=0, int tag=0):
"""
Nonblocking send in buffered mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
cdef Request request = Request()
with nogil: CHKERR( MPI_Ibsend(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi, &request.ob_mpi) )
return request
def Issend(self, buf, int dest=0, int tag=0):
"""
Nonblocking send in synchronous mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
cdef Request request = Request()
with nogil: CHKERR( MPI_Issend(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi, &request.ob_mpi) )
return request
def Irsend(self, buf, int dest=0, int tag=0):
"""
Nonblocking send in ready mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
cdef Request request = Request()
with nogil: CHKERR( MPI_Irsend(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi, &request.ob_mpi) )
return request
# Persistent Requests
def Bsend_init(self, buf, int dest=0, int tag=0):
"""
Persistent request for a send in buffered mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
cdef Prequest request = Prequest()
with nogil: CHKERR( MPI_Bsend_init(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi, &request.ob_mpi) )
return request
def Ssend_init(self, buf, int dest=0, int tag=0):
"""
Persistent request for a send in synchronous mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
cdef Prequest request = Prequest()
with nogil: CHKERR( MPI_Ssend_init(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi, &request.ob_mpi) )
return request
def Rsend_init(self, buf, int dest=0, int tag=0):
"""
Persistent request for a send in ready mode
"""
cdef _p_msg_p2p smsg = message_p2p_send(buf, dest)
cdef Prequest request = Prequest()
with nogil: CHKERR( MPI_Rsend_init(
smsg.buf, smsg.count, smsg.dtype,
dest, tag, self.ob_mpi, &request.ob_mpi) )
return request
# Collective Communications
# -------------------------
# Barrier Synchronization
# -----------------------
def Barrier(self):
"""
Barrier synchronization
"""
with nogil: CHKERR( MPI_Barrier(self.ob_mpi) )
# Global Communication Functions
# ------------------------------
def Bcast(self, buf, int root=0):
"""
Broadcast a message from one process
to all other processes in a group
"""
cdef _p_msg_cco m = message_cco()
m.for_bcast(buf, root, self.ob_mpi)
with nogil: CHKERR( MPI_Bcast(
m.sbuf, m.scount, m.stype,
root, self.ob_mpi) )
def Gather(self, sendbuf, recvbuf, int root=0):
"""
Gather together values from a group of processes
"""
cdef _p_msg_cco m = message_cco()
m.for_gather(0, sendbuf, recvbuf, root, self.ob_mpi)
with nogil: CHKERR( MPI_Gather(
m.sbuf, m.scount, m.stype,
m.rbuf, m.rcount, m.rtype,
root, self.ob_mpi) )
def Gatherv(self, sendbuf, recvbuf, int root=0):
"""
Gather Vector, gather data to one process from all other
processes in a group providing different amount of data and
displacements at the receiving sides
"""
cdef _p_msg_cco m = message_cco()
m.for_gather(1, sendbuf, recvbuf, root, self.ob_mpi)
with nogil: CHKERR( MPI_Gatherv(
m.sbuf, m.scount, m.stype,
m.rbuf, m.rcounts, m.rdispls, m.rtype,
root, self.ob_mpi) )
def Scatter(self, sendbuf, recvbuf, int root=0):
"""
Scatter Vector, scatter data from one process
to all other processes in a group
"""
cdef _p_msg_cco m = message_cco()
m.for_scatter(0, sendbuf, recvbuf, root, self.ob_mpi)
with nogil: CHKERR( MPI_Scatter(
m.sbuf, m.scount, m.stype,
m.rbuf, m.rcount, m.rtype,
root, self.ob_mpi) )
def Scatterv(self, sendbuf, recvbuf, int root=0):
"""
Scatter data from one process to all other processes in a
group providing different amount of data and displacements at
the sending side
"""
cdef _p_msg_cco m = message_cco()
m.for_scatter(1, sendbuf, recvbuf, root, self.ob_mpi)
with nogil: CHKERR( MPI_Scatterv(
m.sbuf, m.scounts, m.sdispls, m.stype,
m.rbuf, m.rcount, m.rtype,
root, self.ob_mpi) )
def Allgather(self, sendbuf, recvbuf):
"""
Gather to All, gather data from all processes and
distribute it to all other processes in a group
"""
cdef _p_msg_cco m = message_cco()
m.for_allgather(0, sendbuf, recvbuf, self.ob_mpi)
with nogil: CHKERR( MPI_Allgather(
m.sbuf, m.scount, m.stype,
m.rbuf, m.rcount, m.rtype,
self.ob_mpi) )
def Allgatherv(self, sendbuf, recvbuf):
"""
Gather to All Vector, gather data from all processes and
distribute it to all other processes in a group providing
different amount of data and displacements
"""
cdef _p_msg_cco m = message_cco()
m.for_allgather(1, sendbuf, recvbuf, self.ob_mpi)
with nogil: CHKERR( MPI_Allgatherv(
m.sbuf, m.scount, m.stype,
m.rbuf, m.rcounts, m.rdispls, m.rtype,
self.ob_mpi) )
def Alltoall(self, sendbuf, recvbuf):
"""
All to All Scatter/Gather, send data from all to all
processes in a group
"""
cdef _p_msg_cco m = message_cco()
m.for_alltoall(0, sendbuf, recvbuf, self.ob_mpi)
with nogil: CHKERR( MPI_Alltoall(
m.sbuf, m.scount, m.stype,
m.rbuf, m.rcount, m.rtype,
self.ob_mpi) )
def Alltoallv(self, sendbuf, recvbuf):
"""
All to All Scatter/Gather Vector, send data from all to all
processes in a group providing different amount of data and
displacements
"""
cdef _p_msg_cco m = message_cco()
m.for_alltoall(1, sendbuf, recvbuf, self.ob_mpi)
with nogil: CHKERR( MPI_Alltoallv(
m.sbuf, m.scounts, m.sdispls, m.stype,
m.rbuf, m.rcounts, m.rdispls, m.rtype,
self.ob_mpi) )
def Alltoallw(self, sendbuf, recvbuf):
"""
Generalized All-to-All communication allowing different
counts, displacements and datatypes for each partner
"""
raise NotImplementedError # XXX implement!
cdef void *sbuf = NULL, *rbuf = NULL
cdef int *scounts = NULL, *rcounts = NULL
cdef int *sdispls = NULL, *rdispls = NULL
cdef MPI_Datatype *stypes = NULL, *rtypes = NULL
with nogil: CHKERR( MPI_Alltoallw(
sbuf, scounts, sdispls, stypes,
rbuf, rcounts, rdispls, rtypes,
self.ob_mpi) )
# Global Reduction Operations
# ---------------------------
def Reduce(self, sendbuf, recvbuf, Op op not None=SUM, int root=0):
"""
Reduce
"""
cdef _p_msg_cco m = message_cco()
m.for_reduce(sendbuf, recvbuf, root, self.ob_mpi)
with nogil: CHKERR( MPI_Reduce(
m.sbuf, m.rbuf, m.rcount, m.rtype,
op.ob_mpi, root, self.ob_mpi) )
def Allreduce(self, sendbuf, recvbuf, Op op not None=SUM):
"""
All Reduce
"""
cdef _p_msg_cco m = message_cco()
m.for_allreduce(sendbuf, recvbuf, self.ob_mpi)
with nogil: CHKERR( MPI_Allreduce(
m.sbuf, m.rbuf, m.rcount, m.rtype,
op.ob_mpi, self.ob_mpi) )
def Reduce_scatter(self, sendbuf, recvbuf, Op op not None=SUM):
"""
Reduce-Scatter
"""
raise NotImplementedError # XXX implement!
cdef void *sbuf = NULL
cdef void *rbuf = NULL
cdef int *rcounts = NULL
cdef MPI_Datatype rtype = MPI_DATATYPE_NULL
with nogil: CHKERR( MPI_Reduce_scatter(
sbuf, rbuf, rcounts, rtype,
op.ob_mpi, self.ob_mpi) )
# Tests
# -----
def Is_inter(self):
"""
Test to see if a comm is an intercommunicator
"""
cdef bint flag = 0
CHKERR( MPI_Comm_test_inter(self.ob_mpi, &flag) )
return flag
property is_inter:
"""is intercommunicator"""
def __get__(self):
return self.Is_inter()
def Is_intra(self):
"""
Test to see if a comm is an intracommunicator
"""
return not self.Is_inter()
property is_intra:
"""is intracommunicator"""
def __get__(self):
return self.Is_intra()
def Get_topology(self):
"""
Determine the type of topology (if any)
associated with a communicator
"""
cdef int topo = MPI_UNDEFINED
CHKERR( MPI_Topo_test(self.ob_mpi, &topo) )
return topo
property topology:
"""communicator topology type"""
def __get__(self):
return self.Get_topology()
# Process Creation and Management
# -------------------------------
@classmethod
def Get_parent(cls):
"""
Return the parent intercommunicator for this process
"""
cdef MPI_Comm comm = MPI_COMM_NULL
with nogil: CHKERR( MPI_Comm_get_parent(&comm) )
global __COMM_PARENT__
cdef Intercomm parent = __COMM_PARENT__
parent.ob_mpi = comm
return parent
def Disconnect(self):
"""
Disconnect from a communicator
"""
with nogil: CHKERR( MPI_Comm_disconnect(
&self.ob_mpi) )
@classmethod
def Join(cls, int fd):
"""
Create a intercommunicator by joining
two processes connected by a socket
"""
cdef Intercomm comm = Intercomm()
with nogil: CHKERR( MPI_Comm_join(
fd, &comm.ob_mpi) )
return comm
# Attributes
# ----------
def Get_attr(self, int keyval):
"""
Retrieve attribute value by key
"""
cdef void *attrval = NULL
cdef int flag = 0
CHKERR(MPI_Comm_get_attr(self.ob_mpi, keyval, &attrval, &flag) )
if not flag: return None
if not attrval: return 0
# MPI-1 predefined attribute keyvals
if ((keyval == <int>MPI_TAG_UB) or
(keyval == <int>MPI_HOST) or
(keyval == <int>MPI_IO) or
(keyval == <int>MPI_WTIME_IS_GLOBAL)):
return (<int*>attrval)[0]
# MPI-2 predefined attribute keyvals
elif ((keyval == <int>MPI_UNIVERSE_SIZE) or
(keyval == <int>MPI_APPNUM) or
(keyval == <int>MPI_LASTUSEDCODE)):
return (<int*>attrval)[0]
# user-defined attribute keyval
else:
return PyLong_FromVoidPtr(attrval)
# Error handling
# --------------
def Get_errhandler(self):
"""
Get the error handler for a communicator
"""
cdef Errhandler errhandler = Errhandler()
CHKERR( MPI_Comm_get_errhandler(self.ob_mpi, &errhandler.ob_mpi) )
return errhandler
def Set_errhandler(self, Errhandler errhandler not None):
"""
Set the error handler for a communicator
"""
CHKERR( MPI_Comm_set_errhandler(self.ob_mpi, errhandler.ob_mpi) )
def Call_errhandler(self, int errorcode):
"""
Call the error handler installed on a communicator
"""
CHKERR( MPI_Comm_call_errhandler(self.ob_mpi, errorcode) )
def Abort(self, int errorcode=0):
"""
Terminate MPI execution environment
.. warning:: This is a direct call, use it with care!!!.
"""
CHKERR( MPI_Abort(self.ob_mpi, errorcode) )
# Naming Objects
# --------------
def Get_name(self):
"""
Get the print name for this communicator
"""
cdef char name[MPI_MAX_OBJECT_NAME+1]
cdef int nlen = 0
CHKERR( MPI_Comm_get_name(self.ob_mpi, name, &nlen) )
return tompistr(name, nlen)
def Set_name(self, name):
"""
Set the print name for this communicator
"""
cdef char *cname = NULL
name = asmpistr(name, &cname, NULL)
CHKERR( MPI_Comm_set_name(self.ob_mpi, cname) )
property name:
"""communicator name"""
def __get__(self):
return self.Get_name()
def __set__(self, value):
self.Set_name(value)
# Fortran Handle
# --------------
def py2f(self):
"""
"""
return MPI_Comm_c2f(self.ob_mpi)
@classmethod
def f2py(cls, arg):
"""
"""
cdef Comm comm = cls()
comm.ob_mpi = MPI_Comm_f2c(arg)
return comm
# Python Communication
# --------------------
#
def send(self, obj=None, int dest=0, int tag=0):
"""Send"""
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_send(obj, dest, tag, comm)
#
def recv(self, obj=None, int source=0, int tag=0, Status status=None):
"""Receive"""
cdef MPI_Comm comm = self.ob_mpi
cdef MPI_Status *statusp = _arg_Status(status)
return PyMPI_recv(obj, source, tag, comm, statusp)
#
def sendrecv(self,
sendobj=None, int dest=0, int sendtag=0,
recvobj=None, int source=0, int recvtag=0,
Status status=None):
"""Send and Receive"""
cdef MPI_Comm comm = self.ob_mpi
cdef MPI_Status *statusp = _arg_Status(status)
return PyMPI_sendrecv(sendobj, dest, sendtag,
recvobj, source, recvtag,
comm, statusp)
#
def barrier(self):
"Barrier"
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_barrier(comm)
#
def bcast(self, obj=None, int root=0):
"""Broadcast"""
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_bcast(obj, root, comm)
#
def gather(self, sendobj=None, recvobj=None, int root=0):
"""Gather"""
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_gather(sendobj, recvobj, root, comm)
#
def scatter(self, sendobj=None, recvobj=None, int root=0):
"""Scatter"""
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_scatter(sendobj, recvobj, root, comm)
#
def allgather(self, sendobj=None, recvobj=None):
"""Gather to All"""
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_allgather(sendobj, recvobj, comm)
#
def alltoall(self, sendobj=None, recvobj=None):
"""All to All Scatter/Gather"""
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_alltoall(sendobj, recvobj, comm)
#
def reduce(self, sendobj=None, recvobj=None, op=SUM, int root=0):
"""Reduce"""
if op is None: op = SUM
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_reduce(sendobj, recvobj, op, root, comm)
#
def allreduce(self, sendobj=None, recvobj=None, op=SUM):
"""Reduce to All"""
if op is None: op = SUM
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_allreduce(sendobj, recvobj, op, comm)
cdef class Intracomm(Comm):
"""
Intracommunicator
"""
# Communicator Constructors
# -------------------------
def Dup(self):
"""
Duplicate an existing intracommunicator
"""
cdef Intracomm comm = type(self)()
with nogil: CHKERR( MPI_Comm_dup(self.ob_mpi, &comm.ob_mpi) )
return comm
def Create(self, Group group not None):
"""
Create intracommunicator from group
"""
cdef Intracomm comm = type(self)()
with nogil: CHKERR( MPI_Comm_create(self.ob_mpi, group.ob_mpi, &comm.ob_mpi) )
return comm
def Split(self, int color=0, int key=0):
"""
Split intracommunicator by color and key
"""
cdef Intracomm comm = type(self)()
with nogil: CHKERR( MPI_Comm_split(self.ob_mpi, color, key, &comm.ob_mpi) )
return comm
def Create_cart(self, dims, periods=None, bint reorder=False):
"""
Create cartesian communicator
"""
cdef int ndims = len(dims)
cdef int *idims = NULL
cdef tmp1 = asarray_int(dims, &idims, ndims)
if periods is None: periods = [False] * ndims
cdef int *iperiods = NULL
cdef tmp2 = asarray_int(periods, &iperiods, ndims)
#
cdef Cartcomm comm = Cartcomm()
with nogil: CHKERR( MPI_Cart_create(self.ob_mpi, ndims, idims, iperiods, reorder, &comm.ob_mpi) )
return comm
def Create_graph(self, index, edges, bint reorder=False):
"""
Create graph communicator
"""
cdef int nnodes = len(index)
cdef int *iindex = NULL
cdef tmp1 = asarray_int(index, &iindex, nnodes)
cdef int nedges = len(edges)
cdef int *iedges = NULL
cdef tmp2 = asarray_int(edges, &iedges, nedges)
# extension: 'standard' adjacency arrays
if iindex[0]==0 and iindex[nnodes-1]==nedges:
nnodes -= 1; iindex += 1;
#
cdef Graphcomm comm = Graphcomm()
with nogil: CHKERR( MPI_Graph_create(self.ob_mpi, nnodes, iindex, iedges, reorder, &comm.ob_mpi) )
return comm
def Create_intercomm(self,
int local_leader,
Intracomm peer_comm not None,
int remote_leader,
int tag=0):
"""
Create intercommunicator
"""
cdef Intercomm comm = Intercomm()
with nogil: CHKERR( MPI_Intercomm_create(
self.ob_mpi, local_leader,
peer_comm.ob_mpi, remote_leader,
tag, &comm.ob_mpi) )
return comm
# Global Reduction Operations
# ---------------------------
# Inclusive Scan
def Scan(self, sendbuf, recvbuf, Op op not None=SUM):
"""
Inclusive Scan
"""
cdef _p_msg_cco m = message_cco()
m.for_scan(sendbuf, recvbuf, self.ob_mpi)
with nogil: CHKERR( MPI_Scan(
m.sbuf, m.rbuf, m.rcount, m.rtype,
op.ob_mpi, self.ob_mpi) )
# Exclusive Scan
def Exscan(self, sendbuf, recvbuf, Op op not None=SUM):
"""
Exclusive Scan
"""
cdef _p_msg_cco m = message_cco()
m.for_exscan(sendbuf, recvbuf, self.ob_mpi)
with nogil: CHKERR( MPI_Exscan(
m.sbuf, m.rbuf, m.rcount, m.rtype,
op.ob_mpi, self.ob_mpi) )
# Python Communication
#
def scan(self, sendobj=None, recvobj=None, op=SUM):
"""Inclusive Scan"""
if op is None: op = SUM
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_scan(sendobj, recvobj, op, comm)
#
def exscan(self, sendobj=None, recvobj=None, op=SUM):
"""Exclusive Scan"""
if op is None: op = SUM
cdef MPI_Comm comm = self.ob_mpi
return PyMPI_exscan(sendobj, recvobj, op, comm)
# Establishing Communication
# --------------------------
# Starting Processes
def Spawn(self, command, args, int maxprocs=1,
Info info=INFO_NULL, int root=0, errcodes=None):
"""
Spawn instances of a single MPI application
"""
cdef char *cmd = NULL
cdef char **argv = MPI_ARGV_NULL
cdef MPI_Info cinfo = _arg_Info(info)
cdef int *ierrcodes = MPI_ERRCODES_IGNORE
#
cdef int rank = MPI_UNDEFINED
CHKERR( MPI_Comm_rank(self.ob_mpi, &rank) )
cdef object tmp1 = None, tmp2 = None
if root == rank:
command = asmpistr(command, &cmd, NULL)
if args is not None:
tmp1 = asarray_argv(args, &argv)
if errcodes is not None:
tmp2 = newarray_int(maxprocs, &ierrcodes)
#
cdef Intercomm comm = Intercomm()
with nogil: CHKERR( MPI_Comm_spawn(
cmd, argv, maxprocs, cinfo, root,
self.ob_mpi, &comm.ob_mpi,
ierrcodes) )
#
cdef int i = 0
if root == rank and (errcodes is not None):
errcodes[:] = [ierrcodes[i] for i from 0<=i<maxprocs]
#
return comm
# Server Routines
def Accept(self, port_name, Info info=INFO_NULL, int root=0):
"""
Accept a request to form a new intercommunicator
"""
cdef char *cportname = NULL
port_name = asmpistr(port_name, &cportname, NULL)
cdef MPI_Info cinfo = _arg_Info(info)
cdef Intercomm comm = Intercomm()
with nogil: CHKERR( MPI_Comm_accept(
cportname, cinfo, root,
self.ob_mpi, &comm.ob_mpi) )
return comm
# Client Routines
def Connect(self, port_name, Info info=INFO_NULL, int root=0):
"""
Make a request to form a new intercommunicator
"""
cdef char *cportname = NULL
port_name = asmpistr(port_name, &cportname, NULL)
cdef MPI_Info cinfo = _arg_Info(info)
cdef Intercomm comm = Intercomm()
with nogil: CHKERR( MPI_Comm_connect(
cportname, cinfo, root,
self.ob_mpi, &comm.ob_mpi) )
return comm
cdef class Cartcomm(Intracomm):
"""
Cartesian topology intracommunicator
"""
# Communicator Constructors
# -------------------------
def Dup(self):
"""
Duplicate an existing communicator
"""
cdef Intracomm comm = type(self)()
with nogil: CHKERR( MPI_Comm_dup(self.ob_mpi, &comm.ob_mpi) )
return comm
# Cartesian Inquiry Functions
# ---------------------------
def Get_dim(self):
"""
Return number of dimensions
"""
cdef int dim = 0
CHKERR( MPI_Cartdim_get(self.ob_mpi, &dim) )
return dim
property dim:
"""number of dimensions"""
def __get__(self):
return self.Get_dim()
property ndim:
"""number of dimensions"""
def __get__(self):
return self.Get_dim()
def Get_topo(self):
"""
Return information on the cartesian topology
"""
cdef int ndim = 0
CHKERR( MPI_Cartdim_get(self.ob_mpi, &ndim) )
cdef int *idims = NULL
cdef tmp1 = newarray_int(ndim, &idims)
cdef int *iperiods = NULL
cdef tmp2 = newarray_int(ndim, &iperiods)
cdef int *icoords = NULL
cdef tmp3 = newarray_int(ndim, &icoords)
CHKERR( MPI_Cart_get(self.ob_mpi, ndim, idims, iperiods, icoords) )
cdef int i = 0
dims = [idims[i] for i from 0 <= i < ndim]
periods = [iperiods[i] for i from 0 <= i < ndim]
coords = [icoords[i] for i from 0 <= i < ndim]
return (dims, periods, coords)
property topo:
"""topology information"""
def __get__(self):
return self.Get_topo()
property dims:
"""dimensions"""
def __get__(self):
return self.Get_topo()[0]
property periods:
"""periodicity"""
def __get__(self):
return self.Get_topo()[1]
property coords:
"""coordinates"""
def __get__(self):
return self.Get_topo()[2]
# Cartesian Translator Functions
# ------------------------------
def Get_cart_rank(self, coords):
"""
Translate logical coordinates to ranks
"""
cdef int ndim = 0
CHKERR( MPI_Cartdim_get( self.ob_mpi, &ndim) )
#
cdef int *icoords = NULL
cdef tmp = asarray_int(coords, &icoords, ndim)
cdef int rank = MPI_PROC_NULL
CHKERR( MPI_Cart_rank(self.ob_mpi, icoords, &rank) )
return rank
def Get_coords(self, int rank):
"""
Translate ranks to logical coordinates
"""
cdef int ndim = 0
CHKERR( MPI_Cartdim_get(self.ob_mpi, &ndim) )
cdef int *icoords = NULL
cdef tmp = newarray_int(ndim, &icoords)
CHKERR( MPI_Cart_coords(self.ob_mpi, rank, ndim, icoords) )
cdef int i = 0
coords = [icoords[i] for i from 0 <= i < ndim]
return coords
# Cartesian Shift Function
# ------------------------
def Shift(self, int direction, int disp):
"""
Return a tuple (source,dest) of process ranks
for data shifting with Comm.Sendrecv()
"""
cdef int source = MPI_PROC_NULL, dest = MPI_PROC_NULL
CHKERR( MPI_Cart_shift(self.ob_mpi, direction, disp, &source, &dest) )
return (source, dest)
# Cartesian Partition Function
# ----------------------------
def Sub(self, remain_dims):
"""
Return cartesian communicators
that form lower-dimensional subgrids
"""
cdef int ndim = 0
CHKERR( MPI_Cartdim_get(self.ob_mpi, &ndim) )
cdef int *iremdims = NULL
cdef tmp = asarray_int(remain_dims, &iremdims, ndim)
cdef Cartcomm comm = Cartcomm()
with nogil: CHKERR( MPI_Cart_sub(self.ob_mpi, iremdims, &comm.ob_mpi) )
return comm
# Cartesian Low-Level Functions
# -----------------------------
def Map(self, dims, periods=None):
"""
Return an optimal placement for the
calling process on the physical machine
"""
cdef int ndims = len(dims)
cdef int *idims = NULL
cdef tmp1 = asarray_int(dims, &idims, ndims)
if periods is None: periods = [False] * ndims
cdef int *iperiods = NULL
cdef tmp2 = asarray_int(periods, &iperiods, ndims)
cdef int rank = MPI_PROC_NULL
CHKERR( MPI_Cart_map(self.ob_mpi, ndims, idims, iperiods, &rank) )
return rank
# Cartesian Convenience Function
def Compute_dims(int nnodes, dims):
"""
Return a balanced distribution of
processes per coordinate direction
"""
cdef int ndims, *idims = NULL
try: ndims = len(dims)
except: ndims = dims; dims = [0] * ndims
cdef tmp = asarray_int(dims, &idims, ndims)
CHKERR( MPI_Dims_create(nnodes, ndims, idims) )
cdef int i = 0
return [idims[i] for i from 0 <= i < ndims]
cdef class Graphcomm(Intracomm):
"""
Graph topology intracommunicator
"""
# Communicator Constructors
# -------------------------
def Dup(self):
"""
Duplicate an existing communicator
"""
cdef Intracomm comm = type(self)()
with nogil: CHKERR( MPI_Comm_dup(
self.ob_mpi, &comm.ob_mpi) )
return comm
# Graph Inquiry Functions
# -----------------------
def Get_dims(self):
"""
Return the number of nodes and edges
"""
cdef int nnodes = 0, nedges = 0
CHKERR( MPI_Graphdims_get(self.ob_mpi, &nnodes, &nedges) )
return (nnodes, nedges)
property dims:
"""number of nodes and edges"""
def __get__(self):
return self.Get_topo()
property nnodes:
"""number of nodes"""
def __get__(self):
return self.Get_topo()[0]
property nedges:
"""number of edges"""
def __get__(self):
return self.Get_topo()[1]
def Get_topo(self):
"""
Return index and edges
"""
cdef int nindex = 0, nedges = 0
CHKERR( MPI_Graphdims_get( self.ob_mpi, &nindex, &nedges) )
cdef int *iindex = NULL
cdef tmp1 = newarray_int(nindex, &iindex)
cdef int *iedges = NULL
cdef tmp2 = newarray_int(nedges, &iedges)
CHKERR( MPI_Graph_get(self.ob_mpi, nindex, nedges, iindex, iedges) )
cdef int i = 0
index = [iindex[i] for i from 0 <= i < nindex]
edges = [iedges[i] for i from 0 <= i < nedges]
return (index, edges)
property topo:
"""topology information"""
def __get__(self):
return self.Get_topo()
property index:
"""index"""
def __get__(self):
return self.Get_topo()[0]
property edges:
"""edges"""
def __get__(self):
return self.Get_topo()
# Graph Information Functions
# ---------------------------
def Get_neighbors_count(self, int rank):
"""
Return number of neighbors of a process
"""
cdef int nneighbors = 0
CHKERR( MPI_Graph_neighbors_count(self.ob_mpi, rank, &nneighbors) )
return nneighbors
property nneighbors:
"""number of neighbors"""
def __get__(self):
cdef int rank = self.Get_rank()
return self.Get_neighbors_count(rank)
def Get_neighbors(self, int rank):
"""
Return list of neighbors of a process
"""
cdef int nneighbors = 0
with nogil: CHKERR( MPI_Graph_neighbors_count(
self.ob_mpi, rank, &nneighbors) )
cdef int *ineighbors = NULL
cdef tmp = newarray_int(nneighbors, &ineighbors)
CHKERR( MPI_Graph_neighbors(self.ob_mpi, rank, nneighbors, ineighbors) )
cdef int i = 0
neighbors = [ineighbors[i] for i from 0 <= i < nneighbors]
return neighbors
property neighbors:
"""neighbors"""
def __get__(self):
cdef int rank = self.Get_rank()
return self.Get_neighbors(rank)
# Graph Low-Level Functions
# -------------------------
def Map(self, index, edges):
"""
Return an optimal placement for the
calling process on the physical machine
"""
cdef int nnodes = len(index)
cdef int *iindex = NULL
cdef tmp1 = asarray_int(index, &iindex, nnodes)
cdef int nedges = len(edges)
cdef int *iedges = NULL
cdef tmp2 = asarray_int(edges, &iedges, nedges)
# extension: accept more 'standard' adjacency arrays
if iindex[0]==0 and iindex[nnodes-1]==nedges:
nnodes -= 1; iindex += 1;
cdef int rank = MPI_PROC_NULL
CHKERR( MPI_Graph_map(self.ob_mpi, nnodes, iindex, iedges, &rank) )
return rank
cdef class Intercomm(Comm):
"""
Intercommunicator
"""
# Intercommunicator Accessors
# ---------------------------
def Get_remote_group(self):
"""
Access the remote group associated
with the inter-communicator
"""
cdef Group group = Group()
CHKERR( MPI_Comm_remote_group(self.ob_mpi, &group.ob_mpi) )
return group
property remote_group:
"""remote group"""
def __get__(self):
return self.Get_remote_group()
def Get_remote_size(self):
"""
Intercommunicator remote size
"""
cdef int size = -1
CHKERR( MPI_Comm_remote_size(self.ob_mpi, &size) )
return size
property remote_size:
"""number of remote processes"""
def __get__(self):
return self.Get_remote_size()
# Communicator Constructors
# -------------------------
def Dup(self):
"""
Duplicate an existing intercommunicator
"""
cdef Intercomm comm = type(self)()
with nogil: CHKERR( MPI_Comm_dup(self.ob_mpi, &comm.ob_mpi) )
return comm
def Create(self, Group group not None):
"""
Create intercommunicator from group
"""
cdef Intercomm comm = type(self)()
with nogil: CHKERR( MPI_Comm_create(self.ob_mpi, group.ob_mpi, &comm.ob_mpi) )
return comm
def Split(self, int color=0, int key=0):
"""
Split intercommunicator by color and key
"""
cdef Intercomm comm = type(self)()
with nogil: CHKERR( MPI_Comm_split(self.ob_mpi, color, key, &comm.ob_mpi) )
return comm
def Merge(self, bint high=False):
"""
Merge intercommunicator
"""
cdef Intracomm comm = Intracomm()
with nogil: CHKERR( MPI_Intercomm_merge(self.ob_mpi, high, &comm.ob_mpi) )
return comm
cdef Comm __COMM_NULL__ = _new_Comm ( MPI_COMM_NULL )
cdef Intracomm __COMM_SELF__ = _new_Intracomm ( MPI_COMM_SELF )
cdef Intracomm __COMM_WORLD__ = _new_Intracomm ( MPI_COMM_WORLD )
cdef Intercomm __COMM_PARENT__ = _new_Intercomm ( MPI_COMM_NULL )
# Predefined communicators
# ------------------------
COMM_NULL = __COMM_NULL__ #: Null communicator handle
COMM_SELF = __COMM_SELF__ #: Self communicator handle
COMM_WORLD = __COMM_WORLD__ #: World communicator handle
# Buffer Allocation and Usage
# ---------------------------
BSEND_OVERHEAD = MPI_BSEND_OVERHEAD
#: Upper bound of memory overhead for sending in buffered mode
def Attach_buffer(memory):
"""
Attach a user-provided buffer for
sending in buffered mode
"""
cdef void *base = NULL
cdef MPI_Aint size = 0
asmemory(memory, &base, &size)
with nogil: CHKERR( MPI_Buffer_attach(base, <int>size) )
def Detach_buffer():
"""
Remove an existing attached buffer
"""
cdef void *base = NULL
cdef int size = 0
with nogil: CHKERR( MPI_Buffer_detach(&base, &size) )
return tomemory(base, <MPI_Aint>size)
# --------------------------------------------------------------------
# [5] Process Creation and Management
# --------------------------------------------------------------------
# [5.4.2] Server Routines
# -----------------------
def Open_port(Info info=INFO_NULL):
"""
Return an address that can be used to establish
connections between groups of MPI processes
"""
cdef MPI_Info cinfo = _arg_Info(info)
cdef char cportname[MPI_MAX_PORT_NAME+1]
with nogil: CHKERR( MPI_Open_port(cinfo, cportname) )
return mpistr(cportname)
def Close_port(port_name, Info info=INFO_NULL):
"""
Close a port
"""
cdef char *cportname = NULL
port_name = asmpistr(port_name, &cportname, NULL)
cdef MPI_Info cinfo = _arg_Info(info)
with nogil: CHKERR( MPI_Close_port(cportname) )
# [5.4.4] Name Publishing
# -----------------------
def Publish_name(service_name, Info info, port_name):
"""
Publish a service name
"""
cdef char *csrvcname = NULL
service_name = asmpistr(service_name, &csrvcname, NULL)
cdef char *cportname = NULL
port_name = asmpistr(port_name, &cportname, NULL)
cdef MPI_Info cinfo = _arg_Info(info)
with nogil: CHKERR( MPI_Publish_name(csrvcname, cinfo, cportname) )
def Unpublish_name(service_name, Info info, port_name):
"""
Unpublish a service name
"""
cdef char *csrvcname = NULL
service_name = asmpistr(service_name, &csrvcname, NULL)
cdef char *cportname = NULL
port_name = asmpistr(port_name, &cportname, NULL)
cdef MPI_Info cinfo = _arg_Info(info)
with nogil: CHKERR( MPI_Unpublish_name(csrvcname, cinfo, cportname) )
def Lookup_name(service_name, Info info=INFO_NULL):
"""
Lookup a port name given a service name
"""
cdef char *csrvcname = NULL
service_name = asmpistr(service_name, &csrvcname, NULL)
cdef MPI_Info cinfo = _arg_Info(info)
cdef char cportname[MPI_MAX_PORT_NAME+1]
with nogil: CHKERR( MPI_Lookup_name(csrvcname, cinfo, cportname) )
return mpistr(cportname)
|