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
|
#!/usr/bin/env python3
##################################################
## DEPENDENCIES
import sys
import os
import os.path
try:
import builtins as builtin
except ImportError:
import __builtin__ as builtin
from os.path import getmtime, exists
import time
import types
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import *
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
from Cheetah.compat import unicode
from xpdeint.SimulationDrivers._DistributedMPIDriver import _DistributedMPIDriver
##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '3.2.3'
__CHEETAH_versionTuple__ = (3, 2, 3, 'final', 0)
__CHEETAH_genTime__ = 1558054970.3001595
__CHEETAH_genTimestamp__ = 'Fri May 17 11:02:50 2019'
__CHEETAH_src__ = '/home/mattias/xmds-2.2.3/admin/staging/xmds-3.0.0/xpdeint/SimulationDrivers/DistributedMPIDriver.tmpl'
__CHEETAH_srcLastModified__ = 'Thu Apr 4 16:29:24 2019'
__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
raise AssertionError(
'This template was compiled with Cheetah version'
' %s. Templates compiled before version %s must be recompiled.'%(
__CHEETAH_version__, RequiredCheetahVersion))
##################################################
## CLASSES
class DistributedMPIDriver(_DistributedMPIDriver):
##################################################
## CHEETAH GENERATED METHODS
def __init__(self, *args, **KWs):
super(DistributedMPIDriver, self).__init__(*args, **KWs)
if not self._CHEETAH__instanceInitialized:
cheetahKWArgs = {}
allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
for k,v in KWs.items():
if k in allowedKWs: cheetahKWArgs[k] = v
self._initCheetahInstance(**cheetahKWArgs)
def description(self, **KWS):
## Generated from @def description: Distributed MPI Simulation Driver at line 26, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
write('''Distributed MPI Simulation Driver''')
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def preAllocation(self, dict, **KWS):
## CHEETAH: generated from @def preAllocation($dict) at line 28, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
write(''' ''')
_v = VFFSL(SL,"distributedTransform.setLocalLatticeAndOffsetVariables",True) # '${distributedTransform.setLocalLatticeAndOffsetVariables, autoIndent=True}' on line 30, col 3
if _v is not None: write(_filter(_v, autoIndent=True, rawExpr='${distributedTransform.setLocalLatticeAndOffsetVariables, autoIndent=True}')) # from line 30, col 3.
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def mainRoutine(self, **KWS):
## CHEETAH: generated from @def mainRoutine at line 34, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
write('''int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &_size);
MPI_Comm_rank(MPI_COMM_WORLD, &_rank);
''')
_v = VFFSL(SL,"mainRoutineInnerContent",True) # '${mainRoutineInnerContent, autoIndent=True}' on line 42, col 3
if _v is not None: write(_filter(_v, autoIndent=True, rawExpr='${mainRoutineInnerContent, autoIndent=True}')) # from line 42, col 3.
write('''
MPI_Finalize();
return 0;
}
''')
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def setVectorAllocSizes(self, vectors, **KWS):
## CHEETAH: generated from @def setVectorAllocSizes($vectors) at line 51, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
_v = super(DistributedMPIDriver, self).setVectorAllocSizes(vectors)
if _v is not None: write(_filter(_v))
#
_v = VFN(VFFSL(SL,"distributedTransform",True),"setVectorAllocSizes",False)(vectors) # '${distributedTransform.setVectorAllocSizes(vectors)}' on line 55, col 1
if _v is not None: write(_filter(_v, rawExpr='${distributedTransform.setVectorAllocSizes(vectors)}')) # from line 55, col 1.
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def loopOverFieldInBasisWithVectorsAndInnerContentEnd(self, dict, **KWS):
## CHEETAH: generated from @def loopOverFieldInBasisWithVectorsAndInnerContentEnd($dict) at line 59, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
vectorOverrides = dict['vectorOverrides']
indexOverrides = dict['indexOverrides']
field = dict['field']
basis = dict['basis']
#
for vector in VFFSL(SL,"vectorOverrides",True): # generated from line 66, col 3
if not (field.isDistributed and not vector.field.isDistributed): # generated from line 67, col 5
# If we aren't integrating over an MPI dimension, then everything is as usual.
continue
# We did integrate over the MPI dimension, so we need to run MPI_Allreduce to combine the results.
arrayName = ''.join(['_active_',str(VFFSL(SL,"vector.id",True))])
size = VFN(VFFSL(SL,"vector",True),"sizeInBasisInReals",False)(basis)
#
# If we have any dimension overrides, then we don't want to add up the entire field
for dimRepName in indexOverrides.keys(): # generated from line 76, col 5
if vector.field in indexOverrides[dimRepName]: # generated from line 77, col 7
dimReps = [dimRep for dimRep in vector.field.inBasis(basis) if dimRep.canonicalName == dimRepName]
if not dimReps: # generated from line 79, col 9
continue
assert len(dimReps) == 1
vectorDimRep = dimReps[0]
indexOverride = indexOverrides[dimRepName][vector.field]
arrayName = ''.join([str(VFFSL(SL,"arrayName",True)),' + ',str(VFFSL(SL,"indexOverride",True)),' * ',str(VFN(VFFSL(SL,"vector.field",True),"localPointsInDimensionsAfterDimRepInBasis",False)(vectorDimRep, basis)),' * _',str(VFFSL(SL,"vector.id",True)),'_ncomponents'])
size = size + ' / ' + vectorDimRep.localLattice
write('''MPI_Allreduce(MPI_IN_PLACE, ''')
_v = VFFSL(SL,"arrayName",True) # '$arrayName' on line 89, col 29
if _v is not None: write(_filter(_v, rawExpr='$arrayName')) # from line 89, col 29.
write(''', ''')
_v = VFFSL(SL,"size",True) # '$size' on line 89, col 41
if _v is not None: write(_filter(_v, rawExpr='$size')) # from line 89, col 41.
write(''',
MPI_REAL, MPI_SUM, MPI_COMM_WORLD);
''')
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def findMax(self, dict, **KWS):
## CHEETAH: generated from @def findMax($dict) at line 95, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
variable = dict['variable']
count = dict['count']
type = dict.get('type', 'real').upper()
op = dict.get('op', 'max').upper()
write('''MPI_Allreduce(MPI_IN_PLACE, ''')
_v = VFFSL(SL,"variable",True) # '$variable' on line 101, col 29
if _v is not None: write(_filter(_v, rawExpr='$variable')) # from line 101, col 29.
write(''', ''')
_v = VFFSL(SL,"count",True) # '$count' on line 101, col 40
if _v is not None: write(_filter(_v, rawExpr='$count')) # from line 101, col 40.
write(''', MPI_''')
_v = VFFSL(SL,"type",True) # '${type}' on line 101, col 52
if _v is not None: write(_filter(_v, rawExpr='${type}')) # from line 101, col 52.
write(''', MPI_''')
_v = VFFSL(SL,"op",True) # '${op}' on line 101, col 65
if _v is not None: write(_filter(_v, rawExpr='${op}')) # from line 101, col 65.
write(''', MPI_COMM_WORLD);
''')
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def binaryWriteOutBegin(self, dict, **KWS):
## CHEETAH: generated from @def binaryWriteOutBegin($dict) at line 106, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
write('''// Only write to file if we are rank 0, as we cannot assume
// that the nodes have equal access to the filesystem
if (_rank == 0) {
''')
dict['extraIndent'] += 2
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def binaryWriteOutEnd(self, dict, **KWS):
## CHEETAH: generated from @def binaryWriteOutEnd($dict) at line 115, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
field = dict['field']
basis = dict['basis']
dependentVariables = dict['dependentVariables']
#
dict['extraIndent'] -= 2
#
write('''}
''')
if not all([field.hasDimensionName(dimName) for dimName in VFFSL(SL,"distributedDimensionNames",True)]): # generated from line 124, col 3
# If we don't have all the MPI dimensions, then the data will be local.
return _dummyTrans and trans.response().getvalue() or ""
write("""else {
// We are some other rank that isn't 0, so we need to send our data to rank 0.
ptrdiff_t _sending_var;
""")
for shadowVariable in VFFSL(SL,"shadowedVariablesForField",False)(field): # generated from line 132, col 3
write(''' _sending_var = ''')
_v = VFFSL(SL,"shadowVariable",True) # '$shadowVariable' on line 133, col 18
if _v is not None: write(_filter(_v, rawExpr='$shadowVariable')) # from line 133, col 18.
write(''';
MPI_Ssend(&_sending_var, sizeof(ptrdiff_t), MPI_BYTE, 0, 0, MPI_COMM_WORLD);
''')
write('''
''')
# Note that a variable corresponds to an array with given component names
for variable in VFFSL(SL,"dependentVariables",True): # generated from line 138, col 3
write(''' _sending_var = ''')
_v = VFN(VFFSL(SL,"variable.vector",True),"sizeInBasisInReals",False)(basis) # '${variable.vector.sizeInBasisInReals(basis)}' on line 139, col 18
if _v is not None: write(_filter(_v, rawExpr='${variable.vector.sizeInBasisInReals(basis)}')) # from line 139, col 18.
write(''';
MPI_Ssend(&_sending_var, sizeof(ptrdiff_t), MPI_BYTE, 0, 0, MPI_COMM_WORLD);
if (_sending_var == 0)
goto _BINARY_WRITE_OUT_END;
MPI_Ssend(''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 143, col 13
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 143, col 13.
write(''', ''')
_v = VFN(VFFSL(SL,"variable.vector",True),"sizeInBasisInReals",False)(basis) # '${variable.vector.sizeInBasisInReals(basis)}' on line 143, col 36
if _v is not None: write(_filter(_v, rawExpr='${variable.vector.sizeInBasisInReals(basis)}')) # from line 143, col 36.
write(''', MPI_REAL, 0, 0, MPI_COMM_WORLD);
''')
write('''_BINARY_WRITE_OUT_END:;
}
MPI_Barrier(MPI_COMM_WORLD);
''')
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def binaryWriteOutWriteDataBegin(self, dict, **KWS):
## CHEETAH: generated from @def binaryWriteOutWriteDataBegin($dict) at line 153, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
field = dict['field']
dependentVariables = dict['dependentVariables']
#
if not all([field.hasDimensionName(dimName) for dimName in VFFSL(SL,"distributedDimensionNames",True)]): # generated from line 158, col 3
# If we don't have all the MPI dimensions, then the data will be local.
return
#
for shadowVariable in VFFSL(SL,"shadowedVariablesForField",False)(field): # generated from line 163, col 3
write('''ptrdiff_t _my''')
_v = VFFSL(SL,"shadowVariable",True) # '${shadowVariable}' on line 164, col 14
if _v is not None: write(_filter(_v, rawExpr='${shadowVariable}')) # from line 164, col 14.
write(''' = ''')
_v = VFFSL(SL,"shadowVariable",True) # '${shadowVariable}' on line 164, col 34
if _v is not None: write(_filter(_v, rawExpr='${shadowVariable}')) # from line 164, col 34.
write(''';
''')
#
write('''
''')
for variable in VFFSL(SL,"dependentVariables",True): # generated from line 168, col 3
_v = VFFSL(SL,"variable.vector.type",True) # '${variable.vector.type}' on line 169, col 1
if _v is not None: write(_filter(_v, rawExpr='${variable.vector.type}')) # from line 169, col 1.
write('''* _local''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 169, col 32
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 169, col 32.
write(''';
''')
_v = VFFSL(SL,"variable.vector.type",True) # '${variable.vector.type}' on line 170, col 1
if _v is not None: write(_filter(_v, rawExpr='${variable.vector.type}')) # from line 170, col 1.
write('''* _backup''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 170, col 33
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 170, col 33.
write(''' = ''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 170, col 57
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 170, col 57.
write(''';
''')
write('''
for (long _dataForRank = 0; _dataForRank < _size; _dataForRank++) {
''')
for shadowVariable in VFFSL(SL,"shadowedVariablesForField",False)(field): # generated from line 174, col 3
write(''' ptrdiff_t ''')
_v = VFFSL(SL,"shadowVariable",True) # '${shadowVariable}' on line 175, col 13
if _v is not None: write(_filter(_v, rawExpr='${shadowVariable}')) # from line 175, col 13.
write(''';
''')
write(''' ptrdiff_t _local_vector_size;
if (_dataForRank == 0) {
''')
for shadowVariable in VFFSL(SL,"shadowedVariablesForField",False)(field): # generated from line 180, col 3
write(''' ''')
_v = VFFSL(SL,"shadowVariable",True) # '${shadowVariable}' on line 181, col 5
if _v is not None: write(_filter(_v, rawExpr='${shadowVariable}')) # from line 181, col 5.
write(''' = _my''')
_v = VFFSL(SL,"shadowVariable",True) # '${shadowVariable}' on line 181, col 28
if _v is not None: write(_filter(_v, rawExpr='${shadowVariable}')) # from line 181, col 28.
write(''';
''')
write('''
} else {
MPI_Status status;
''')
for shadowVariable in VFFSL(SL,"shadowedVariablesForField",False)(field): # generated from line 186, col 3
write(''' MPI_Recv(&''')
_v = VFFSL(SL,"shadowVariable",True) # '${shadowVariable}' on line 187, col 15
if _v is not None: write(_filter(_v, rawExpr='${shadowVariable}')) # from line 187, col 15.
write(''', sizeof(ptrdiff_t), MPI_BYTE, _dataForRank, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
''')
write('''
// Now allocate the space needed locally, and receive the entire buffer
''')
for variable in VFFSL(SL,"dependentVariables",True): # generated from line 191, col 3
write(''' MPI_Recv(&_local_vector_size, sizeof(ptrdiff_t), MPI_BYTE, _dataForRank, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
if (_local_vector_size == 0)
continue;
_local''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 196, col 11
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 196, col 11.
write(''' = (''')
_v = VFFSL(SL,"variable.vector.type",True) # '${variable.vector.type}' on line 196, col 36
if _v is not None: write(_filter(_v, rawExpr='${variable.vector.type}')) # from line 196, col 36.
write('''*) xmds_malloc(sizeof(real) * _local_vector_size);
MPI_Recv(_local''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 197, col 20
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 197, col 20.
write(''', _local_vector_size,
MPI_REAL, _dataForRank, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 199, col 5
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 199, col 5.
write(''' = _local''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 199, col 35
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 199, col 35.
write(''';
''')
write(''' }
''')
dict['extraIndent'] += 2
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def binaryWriteOutWriteDataEnd(self, dict, **KWS):
## CHEETAH: generated from @def binaryWriteOutWriteDataEnd($dict) at line 207, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
field = dict['field']
dict['extraIndent'] -= 2
dependentVariables = dict['dependentVariables']
#
if not all([field.hasDimensionName(dimName) for dimName in VFFSL(SL,"distributedDimensionNames",True)]): # generated from line 213, col 3
# If we don't have all the MPI dimensions, then the data will be local.
return
#
write('''
if (_dataForRank != 0) {
''')
for variable in VFFSL(SL,"dependentVariables",True): # generated from line 220, col 3
write(''' xmds_free(_local''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 221, col 21
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 221, col 21.
write(''');
''')
write(''' }
} // End looping over ranks
''')
for variable in VFFSL(SL,"dependentVariables",True): # generated from line 225, col 3
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 226, col 1
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 226, col 1.
write(''' = _backup''')
_v = VFFSL(SL,"variable.arrayName",True) # '${variable.arrayName}' on line 226, col 32
if _v is not None: write(_filter(_v, rawExpr='${variable.arrayName}')) # from line 226, col 32.
write(''';
''')
write('''
''')
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def writeDataHDF5ModifyLoopContents(self, dict, **KWS):
## CHEETAH: generated from @def writeDataHDF5ModifyLoopContents($dict) at line 232, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
dimRepOrdering = dict['dimRepOrdering']
# We only care about elements that are reordered
dimRepOrdering = [(fileDimIndex, memDimIndex, dimRep) for fileDimIndex, memDimIndex, dimRep in dimRepOrdering if fileDimIndex != memDimIndex]
# If dimRepOrdering is empty, we have nothing to do
if not dimRepOrdering: # generated from line 239, col 3
return
#
writeLoopContents = dict['writeLoopContents']
## START CAPTURE REGION: _51622807 newWriteLoopContents at line 244, col 3 in the source.
_orig_trans_51622807 = trans
_wasBuffering_51622807 = self._CHEETAH__isBuffering
self._CHEETAH__isBuffering = True
trans = _captureCollector_51622807 = DummyTransaction()
write = _captureCollector_51622807.response().write
for fileDimIndex, memDimIndex, dimRep in dimRepOrdering: # generated from line 245, col 5
write('''hsize_t file_start_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 246, col 20
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 246, col 20.
write(''' = file_start[''')
_v = VFFSL(SL,"fileDimIndex",True) # '$fileDimIndex' on line 246, col 48
if _v is not None: write(_filter(_v, rawExpr='$fileDimIndex')) # from line 246, col 48.
write('''];
hsize_t mem_start_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 247, col 19
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 247, col 19.
write(''' = mem_start[''')
_v = VFFSL(SL,"memDimIndex",True) # '$memDimIndex' on line 247, col 46
if _v is not None: write(_filter(_v, rawExpr='$memDimIndex')) # from line 247, col 46.
write('''];
hsize_t count_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 248, col 15
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 248, col 15.
write(''' = mem_count[''')
_v = VFFSL(SL,"memDimIndex",True) # '$memDimIndex' on line 248, col 42
if _v is not None: write(_filter(_v, rawExpr='$memDimIndex')) # from line 248, col 42.
write('''];
mem_count[''')
_v = VFFSL(SL,"memDimIndex",True) # '$memDimIndex' on line 249, col 11
if _v is not None: write(_filter(_v, rawExpr='$memDimIndex')) # from line 249, col 11.
write('''] = 1;
''')
#
_v = VFFSL(SL,"hdf5DataCopyLoops",False)(dimRepOrdering[:], writeLoopContents) # '${hdf5DataCopyLoops(dimRepOrdering[:], writeLoopContents)}' on line 253, col 1
if _v is not None: write(_filter(_v, rawExpr='${hdf5DataCopyLoops(dimRepOrdering[:], writeLoopContents)}')) # from line 253, col 1.
for fileDimIndex, memDimIndex, dimRep in dimRepOrdering: # generated from line 254, col 5
write('''
file_start[''')
_v = VFFSL(SL,"fileDimIndex",True) # '$fileDimIndex' on line 256, col 12
if _v is not None: write(_filter(_v, rawExpr='$fileDimIndex')) # from line 256, col 12.
write('''] = file_start_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 256, col 40
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 256, col 40.
write(''';
mem_start[''')
_v = VFFSL(SL,"memDimIndex",True) # '$memDimIndex' on line 257, col 11
if _v is not None: write(_filter(_v, rawExpr='$memDimIndex')) # from line 257, col 11.
write('''] = mem_start_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 257, col 37
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 257, col 37.
write(''';
mem_count[''')
_v = VFFSL(SL,"memDimIndex",True) # '$memDimIndex' on line 258, col 11
if _v is not None: write(_filter(_v, rawExpr='$memDimIndex')) # from line 258, col 11.
write('''] = count_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 258, col 33
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 258, col 33.
write(''';
''')
trans = _orig_trans_51622807
write = trans.response().write
self._CHEETAH__isBuffering = _wasBuffering_51622807
newWriteLoopContents = _captureCollector_51622807.response().getvalue()
del _orig_trans_51622807
del _captureCollector_51622807
del _wasBuffering_51622807
#
dict['writeLoopContents'] = newWriteLoopContents
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def hdf5DataCopyLoops(self, remainingDimReps, writeLoopContents, **KWS):
## CHEETAH: generated from @def hdf5DataCopyLoops(remainingDimReps, writeLoopContents) at line 266, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
if not remainingDimReps: # generated from line 267, col 3
_v = VFFSL(SL,"writeLoopContents",True) # '${writeLoopContents}' on line 268, col 1
if _v is not None: write(_filter(_v, rawExpr='${writeLoopContents}')) # from line 268, col 1.
else: # generated from line 269, col 3
fileDimIndex, memDimIndex, dimRep = remainingDimReps.pop(0)
write('''for (hsize_t _i''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 271, col 16
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 271, col 16.
write(''' = 0; _i''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 271, col 38
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 271, col 38.
write(''' < count_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 271, col 61
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 271, col 61.
write('''; _i''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 271, col 79
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 271, col 79.
write('''++) {
file_start[''')
_v = VFFSL(SL,"fileDimIndex",True) # '$fileDimIndex' on line 272, col 14
if _v is not None: write(_filter(_v, rawExpr='$fileDimIndex')) # from line 272, col 14.
write('''] = file_start_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 272, col 42
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 272, col 42.
write(''' + _i''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 272, col 61
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 272, col 61.
write(''';
mem_start[''')
_v = VFFSL(SL,"memDimIndex",True) # '$memDimIndex' on line 273, col 13
if _v is not None: write(_filter(_v, rawExpr='$memDimIndex')) # from line 273, col 13.
write('''] = mem_start_''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 273, col 39
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 273, col 39.
write(''' + _i''')
_v = VFFSL(SL,"dimRep.name",True) # '${dimRep.name}' on line 273, col 58
if _v is not None: write(_filter(_v, rawExpr='${dimRep.name}')) # from line 273, col 58.
write(''';
''')
_v = VFFSL(SL,"hdf5DataCopyLoops",False)(remainingDimReps, writeLoopContents) # '${hdf5DataCopyLoops(remainingDimReps, writeLoopContents), autoIndent=True}' on line 275, col 3
if _v is not None: write(_filter(_v, autoIndent=True, rawExpr='${hdf5DataCopyLoops(remainingDimReps, writeLoopContents), autoIndent=True}')) # from line 275, col 3.
write('''}
''')
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def evaluateNoiseVectorBegin(self, dict, **KWS):
## CHEETAH: generated from @def evaluateNoiseVectorBegin($dict) at line 280, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
noiseVector = dict['caller']
#
if noiseVector.field.isDistributed: # generated from line 284, col 3
# If the field is distributed, then the noise
# will need to vary along the MPI dimension, so all is
# OK.
return
#
# This means that the noise field doesn't contain the MPI dimension.
# As a result, the noise vector should be identical
write("""if (_rank == 0) {
// This noise is for a field that isn't distributed, so we should
// make sure the noise is the same on all ranks
""")
dict['extraIndent'] += 2
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def evaluateNoiseVectorEnd(self, dict, **KWS):
## CHEETAH: generated from @def evaluateNoiseVectorEnd($dict) at line 300, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
noiseVector = dict['caller']
#
if noiseVector.field.isDistributed: # generated from line 304, col 3
# If the field is distributed, then the noise
# will need to vary along the MPI dimension, so all is
# OK.
return
#
write('''}
// Broadcast the noises to other nodes
MPI_Bcast(_active_''')
_v = VFFSL(SL,"noiseVector.id",True) # '${noiseVector.id}' on line 313, col 19
if _v is not None: write(_filter(_v, rawExpr='${noiseVector.id}')) # from line 313, col 19.
write(''', ''')
_v = VFN(VFFSL(SL,"noiseVector",True),"sizeInBasisInReals",False)(noiseVector.initialBasis) # '${noiseVector.sizeInBasisInReals(noiseVector.initialBasis)}' on line 313, col 38
if _v is not None: write(_filter(_v, rawExpr='${noiseVector.sizeInBasisInReals(noiseVector.initialBasis)}')) # from line 313, col 38.
write(''', MPI_REAL, 0, MPI_COMM_WORLD);
''')
dict['extraIndent'] -= 2
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def runtimeSeedGenerationBegin(self, dict, **KWS):
## CHEETAH: generated from @def runtimeSeedGenerationBegin($dict) at line 319, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
generator = dict['caller']
#
write('''// Only generate random seeds on the first rank, then distribute to all.
unsigned long _local_''')
_v = VFFSL(SL,"generator.generatorName",True) # '${generator.generatorName}' on line 324, col 22
if _v is not None: write(_filter(_v, rawExpr='${generator.generatorName}')) # from line 324, col 22.
write('''_seeds[''')
_v = VFFSL(SL,"generator.seedCount",True) # '${generator.seedCount}' on line 324, col 55
if _v is not None: write(_filter(_v, rawExpr='${generator.seedCount}')) # from line 324, col 55.
write('''];
if (_rank == 0) {
''')
dict['extraIndent'] += 2
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def runtimeSeedGenerationEnd(self, dict, **KWS):
## CHEETAH: generated from @def runtimeSeedGenerationEnd($dict) at line 330, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
generator = dict['caller']
dict['extraIndent'] -= 2
write(''' for (int _i0 = 0; _i0 < ''')
_v = VFFSL(SL,"generator.seedCount",True) # '${generator.seedCount}' on line 334, col 27
if _v is not None: write(_filter(_v, rawExpr='${generator.seedCount}')) # from line 334, col 27.
write('''; _i0++)
_local_''')
_v = VFFSL(SL,"generator.generatorName",True) # '${generator.generatorName}' on line 335, col 14
if _v is not None: write(_filter(_v, rawExpr='${generator.generatorName}')) # from line 335, col 14.
write('''_seeds[_i0] = (unsigned long)''')
_v = VFFSL(SL,"generator.generatorName",True) # '${generator.generatorName}' on line 335, col 69
if _v is not None: write(_filter(_v, rawExpr='${generator.generatorName}')) # from line 335, col 69.
write('''_seeds[_i0];
}
// Broadcast seeds to other nodes
MPI_Bcast(_local_''')
_v = VFFSL(SL,"generator.generatorName",True) # '${generator.generatorName}' on line 338, col 18
if _v is not None: write(_filter(_v, rawExpr='${generator.generatorName}')) # from line 338, col 18.
write('''_seeds, ''')
_v = VFFSL(SL,"generator.seedCount",True) # '${generator.seedCount}' on line 338, col 52
if _v is not None: write(_filter(_v, rawExpr='${generator.seedCount}')) # from line 338, col 52.
write(''', MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD);
// Copy to the correct array
for (int _i0 = 0; _i0 < ''')
_v = VFFSL(SL,"generator.seedCount",True) # '${generator.seedCount}' on line 340, col 25
if _v is not None: write(_filter(_v, rawExpr='${generator.seedCount}')) # from line 340, col 25.
write('''; _i0++)
''')
_v = VFFSL(SL,"generator.generatorName",True) # '${generator.generatorName}' on line 341, col 5
if _v is not None: write(_filter(_v, rawExpr='${generator.generatorName}')) # from line 341, col 5.
write('''_seeds[_i0] = (uint32_t)_local_''')
_v = VFFSL(SL,"generator.generatorName",True) # '${generator.generatorName}' on line 341, col 62
if _v is not None: write(_filter(_v, rawExpr='${generator.generatorName}')) # from line 341, col 62.
write('''_seeds[_i0];
''')
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def openXSILFile(self, dict, **KWS):
## CHEETAH: generated from @def openXSILFile($dict) at line 346, col 1.
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
#
write('''// Only let rank 0 do the writing to disk
if (_rank != 0)
return NULL;
''')
#
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
def writeBody(self, **KWS):
## CHEETAH: main method generated for this template
trans = KWS.get("trans")
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
write('''
''')
#
# DistributedMPIDriver.tmpl
#
# Created by Graham Dennis on 2008-03-28.
#
# Copyright (c) 2008-2012, Graham Dennis
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
write('''
''')
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
##################################################
## CHEETAH GENERATED ATTRIBUTES
_CHEETAH__instanceInitialized = False
_CHEETAH_version = __CHEETAH_version__
_CHEETAH_versionTuple = __CHEETAH_versionTuple__
_CHEETAH_genTime = __CHEETAH_genTime__
_CHEETAH_genTimestamp = __CHEETAH_genTimestamp__
_CHEETAH_src = __CHEETAH_src__
_CHEETAH_srcLastModified = __CHEETAH_srcLastModified__
_mainCheetahMethod_for_DistributedMPIDriver = 'writeBody'
## END CLASS DEFINITION
if not hasattr(DistributedMPIDriver, '_initCheetahAttributes'):
templateAPIClass = getattr(DistributedMPIDriver,
'_CHEETAH_templateClass',
Template)
templateAPIClass._addCheetahPlumbingCodeToClass(DistributedMPIDriver)
# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit https://cheetahtemplate.org/
##################################################
## if run from command line:
if __name__ == '__main__':
from Cheetah.TemplateCmdLineIface import CmdLineIface
CmdLineIface(templateObj=DistributedMPIDriver()).run()
|