@@ -567,6 +567,11 @@ def group_ckNew(cls, args, onPEs):
567
567
return proxy
568
568
return group_ckNew
569
569
570
+
571
+ def group_proxy_localbranch (proxy ):
572
+ return charm .groups [proxy .gid ]
573
+
574
+
570
575
def group_proxy_contribute (proxy , contributeInfo ):
571
576
charm .CkContributeToGroup (contributeInfo , proxy .gid , proxy .elemIdx )
572
577
@@ -631,13 +636,16 @@ def __getProxyClass__(C, cls, sectionProxy=False):
631
636
M ['__eq__' ] = group_proxy__eq__
632
637
M ['__hash__' ] = group_proxy__hash__
633
638
M ['ckNew' ] = group_ckNew_gen (cls , entryMethods [0 ].epIdx )
639
+ M ['ckLocalBranch' ] = group_proxy_localbranch
634
640
M ['__getsecproxy__' ] = group_getsecproxy
635
641
if not sectionProxy :
636
- M ['ckContribute' ] = group_proxy_contribute # function called when target proxy is Group
642
+ M ['ckContribute' ] = group_proxy_contribute
643
+ # function called when target proxy is Group
637
644
M ['__getstate__' ] = group_proxy__getstate__
638
645
M ['__setstate__' ] = group_proxy__setstate__
639
646
else :
640
- M ['ckContribute' ] = groupsecproxy_contribute # function called when target proxy is Group
647
+ M ['ckContribute' ] = groupsecproxy_contribute
648
+ # function called when target proxy is Group
641
649
M ['__getstate__' ] = groupsecproxy__getstate__
642
650
M ['__setstate__' ] = groupsecproxy__setstate__
643
651
proxyCls = type (proxyClassName , (), M ) # create and return proxy class
@@ -655,14 +663,19 @@ def __init__(self):
655
663
def array_proxy_ctor (proxy , aid , ndims ):
656
664
proxy .aid = aid
657
665
proxy .ndims = ndims
658
- proxy .elemIdx = () # entry method calls will be to elemIdx array element (broadcast if empty tuple)
666
+ # entry method calls will be to elemIdx array element
667
+ # (broadcast if empty tuple)
668
+ proxy .elemIdx = ()
669
+
659
670
660
671
def array_proxy__getstate__ (proxy ):
661
672
return (proxy .aid , proxy .ndims , proxy .elemIdx )
662
673
674
+
663
675
def array_proxy__setstate__ (proxy , state ):
664
676
proxy .aid , proxy .ndims , proxy .elemIdx = state
665
677
678
+
666
679
def array_proxy__eq__ (proxy , other ):
667
680
if proxy .issec :
668
681
if hasattr (other , 'issec' ):
@@ -674,12 +687,14 @@ def array_proxy__eq__(proxy, other):
674
687
else :
675
688
return False
676
689
690
+
677
691
def array_proxy__hash__ (proxy ):
678
692
if proxy .issec :
679
693
return hash (proxy .section )
680
694
else :
681
695
return hash ((proxy .aid , proxy .elemIdx ))
682
696
697
+
683
698
def array_getsecproxy (proxy , sinfo ):
684
699
if proxy .issec :
685
700
secproxy = proxy .__class__ (proxy .aid , proxy .ndims )
@@ -688,12 +703,15 @@ def array_getsecproxy(proxy, sinfo):
688
703
secproxy .section = sinfo
689
704
return secproxy
690
705
706
+
691
707
def arraysecproxy__getstate__ (proxy ):
692
708
return (proxy .aid , proxy .ndims , proxy .elemIdx , proxy .section )
693
709
710
+
694
711
def arraysecproxy__setstate__ (proxy , state ):
695
712
proxy .aid , proxy .ndims , proxy .elemIdx , proxy .section = state
696
713
714
+
697
715
def array_proxy_elem (proxy , idx ): # array proxy [] overload method
698
716
ndims = proxy .ndims
699
717
isslice = True
@@ -703,17 +721,27 @@ def array_proxy_elem(proxy, idx): # array proxy [] overload method
703
721
isslice = False
704
722
elif idxtype == slice :
705
723
idx = (idx ,)
706
- assert len (idx ) == ndims , "Dimensions of index " + str (idx ) + " don't match array dimensions"
724
+ assert len (idx ) == ndims , \
725
+ "Dimensions of index " + str (idx ) + " don't match array dimensions"
707
726
if not isslice or not isinstance (idx [0 ], slice ):
708
727
proxy_clone = proxy .__class__ (proxy .aid , ndims )
709
728
proxy_clone .elemIdx = tuple (idx )
710
729
return proxy_clone
711
730
else :
712
731
for _slice in idx :
713
- assert _slice .start is not None and _slice .stop is not None , 'Must specify start and stop indexes for array slicing'
732
+ assert _slice .start is not None and _slice .stop is not None , \
733
+ 'Must specify start and stop indexes for array slicing'
714
734
return charm .split (proxy , 1 , slicing = idx )[0 ]
715
735
716
- def array_proxy_method_gen (ep , argcount , argnames , defaults ): # decorator, generates proxy entry methods
736
+
737
+ def array_proxy_delete (proxy ):
738
+ assert proxy .elemIdx != - 1 , \
739
+ "ckDestroy can only be called on an array element"
740
+ charm .arrayElemDelete (proxy .aid , proxy .elemIdx )
741
+
742
+
743
+ def array_proxy_method_gen (ep , argcount , argnames , defaults ):
744
+ # decorator, generates proxy entry methods
717
745
def proxy_entry_method (proxy , * args , ** kwargs ):
718
746
num_args = len (args )
719
747
if num_args < argcount and len (kwargs ) > 0 :
@@ -726,7 +754,8 @@ def proxy_entry_method(proxy, *args, **kwargs):
726
754
else :
727
755
# if not there, see if there is a default value
728
756
def_idx = i - argcount + len (defaults )
729
- assert def_idx >= 0 , 'Value not found for parameter \' ' + argname + '\' of entry method'
757
+ assert def_idx >= 0 , 'Value not found for parameter \' ' + \
758
+ argname + '\' of entry method'
730
759
args .append (defaults [def_idx ])
731
760
732
761
header = {}
@@ -753,16 +782,20 @@ def proxy_entry_method(proxy, *args, **kwargs):
753
782
root , sid = proxy .section
754
783
header [b'sid' ] = sid
755
784
if Options .local_msg_optim and root == charm ._myPe :
756
- charm .sectionMgr .thisProxy [root ].sendToSectionLocal (sid , ep , header , * args )
785
+ charm .sectionMgr .thisProxy [root ].sendToSectionLocal (
786
+ sid , ep , header , * args )
757
787
else :
758
- charm .sectionMgr .thisProxy [root ].sendToSection (sid , ep , header , * args )
788
+ charm .sectionMgr .thisProxy [root ].sendToSection (
789
+ sid , ep , header , * args )
759
790
return blockFuture
760
791
proxy_entry_method .ep = ep
761
792
return proxy_entry_method
762
793
794
+
763
795
def array_ckNew_gen (C , epIdx ):
764
796
@classmethod # make ckNew a class (not instance) method of proxy
765
- def array_ckNew (cls , dims = None , ndims = - 1 , args = [], map = None , useAtSync = False ):
797
+ def array_ckNew (cls , dims = None , ndims = - 1 , args = [], map = None ,
798
+ useAtSync = False ):
766
799
# if charm.myPe() == 0: print("calling array ckNew for class " + C.__name__ + " cIdx=" + str(C.idx[ARRAY]))
767
800
if type (dims ) == int : dims = (dims ,)
768
801
@@ -789,17 +822,22 @@ def array_ckNew(cls, dims=None, ndims=-1, args=[], map=None, useAtSync=False):
789
822
header [b'creation' ] = True
790
823
791
824
msg = charm .packMsg (None , args , header )
792
- aid = charm .lib .CkCreateArray (C .idx [ARRAY ], dims , epIdx , msg , map_gid , useAtSync )
825
+ aid = charm .lib .CkCreateArray (
826
+ C .idx [ARRAY ], dims , epIdx , msg , map_gid , useAtSync )
793
827
proxy = cls (aid , len (dims ))
794
828
if creation_future is not None :
795
829
proxy .creation_future = creation_future
796
830
return proxy
797
831
return array_ckNew
798
832
833
+
799
834
def array_ckInsert_gen (epIdx ):
800
- def array_ckInsert (proxy , index , args = [], onPE = - 1 , useAtSync = False , single = False ):
801
- if type (index ) == int : index = (index ,)
802
- assert len (index ) == proxy .ndims , 'Invalid index dimensions passed to ckInsert'
835
+ def array_ckInsert (proxy , index , args = [], onPE = - 1 , useAtSync = False ,
836
+ single = False ):
837
+ if type (index ) == int :
838
+ index = (index ,)
839
+ assert len (index ) == proxy .ndims , \
840
+ 'Invalid index dimensions passed to ckInsert'
803
841
header = {}
804
842
if single :
805
843
header [b'single' ] = True
@@ -812,11 +850,15 @@ def array_ckInsert(proxy, index, args=[], onPE=-1, useAtSync=False, single=False
812
850
charm .lib .CkInsert (proxy .aid , index , epIdx , onPE , msg , useAtSync )
813
851
return array_ckInsert
814
852
853
+
815
854
def array_proxy_contribute (proxy , contributeInfo ):
816
855
charm .CkContributeToArray (contributeInfo , proxy .aid , proxy .elemIdx )
817
856
857
+
818
858
def arraysecproxy_contribute (proxy , contributeInfo ):
819
- charm .CkContributeToSection (contributeInfo , proxy .section [1 ], proxy .section [0 ])
859
+ charm .CkContributeToSection (contributeInfo , proxy .section [1 ],
860
+ proxy .section [0 ])
861
+
820
862
821
863
def array_proxy_doneInserting (proxy ):
822
864
charm .lib .CkDoneInserting (proxy .aid )
@@ -826,30 +868,38 @@ class Array(object):
826
868
827
869
type_id = ARRAY
828
870
829
- def __new__ (cls , C , dims = None , ndims = - 1 , args = [], map = None , useAtSync = False ):
871
+ def __new__ (cls , C , dims = None , ndims = - 1 , args = [], map = None ,
872
+ useAtSync = False ):
830
873
if (not hasattr (C , 'mro' )) or (Chare not in C .mro ()):
831
- raise Charm4PyError ('Only subclasses of Chare can be member of Array' )
874
+ raise Charm4PyError ('Only subclasses of Chare can '
875
+ 'be member of Array' )
832
876
if C not in charm .proxyClasses [ARRAY ]:
833
877
raise Charm4PyError (str (C ) + ' not registered for use in Arrays' )
834
- return charm .proxyClasses [ARRAY ][C ].ckNew (dims , ndims , args , map , useAtSync )
878
+ return charm .proxyClasses [ARRAY ][C ].ckNew (dims , ndims , args , map ,
879
+ useAtSync )
835
880
836
881
@classmethod
837
882
def initMember (cls , obj , aid , index , single = False ):
838
883
obj .thisIndex = index
839
884
if single :
840
- proxy = charm .proxyClasses [ARRAY ][obj .__class__ ](aid , len (obj .thisIndex ))
885
+ proxy = charm .proxyClasses [ARRAY ][obj .__class__ ](
886
+ aid , len (obj .thisIndex ))
841
887
obj .thisProxy = proxy [index ]
842
888
else :
843
- obj .thisProxy = charm .proxyClasses [ARRAY ][obj .__class__ ](aid , len (obj .thisIndex ))
844
- obj ._contributeInfo = charm .lib .initContributeInfo (aid , obj .thisIndex , CONTRIBUTOR_TYPE_ARRAY )
889
+ obj .thisProxy = charm .proxyClasses [ARRAY ][obj .__class__ ](
890
+ aid , len (obj .thisIndex ))
891
+ obj ._contributeInfo = charm .lib .initContributeInfo (
892
+ aid , obj .thisIndex , CONTRIBUTOR_TYPE_ARRAY )
845
893
obj .migratable = True
846
894
847
895
@classmethod
848
896
def __baseEntryMethods__ (cls ):
849
897
# 2nd method is used for 2 purposes:
850
- # - to register the migration constructor on Charm++ side (note that this migration constructor does nothing)
898
+ # - to register the migration constructor on Charm++ side
899
+ # (note that this migration constructor does nothing)
851
900
# - Chare.migrated() is called whenever a chare has completed migration.
852
- # The EntryMethod object with this name is used to profile Chare.migrated() calls.
901
+ # The EntryMethod object with this name is used to profile
902
+ # Chare.migrated() calls.
853
903
return ['__init__' , 'migrated' , 'AtSync' ]
854
904
855
905
@classmethod
@@ -868,9 +918,11 @@ def __getProxyClass__(C, cls, sectionProxy=False):
868
918
continue
869
919
argcount , argnames , defaults = getEntryMethodInfo (m .C , m .name )
870
920
if Options .profiling :
871
- f = profile_send_function (array_proxy_method_gen (m .epIdx , argcount , argnames , defaults ))
921
+ f = profile_send_function (array_proxy_method_gen (
922
+ m .epIdx , argcount , argnames , defaults ))
872
923
else :
873
- f = array_proxy_method_gen (m .epIdx , argcount , argnames , defaults )
924
+ f = array_proxy_method_gen (
925
+ m .epIdx , argcount , argnames , defaults )
874
926
f .__qualname__ = proxyClassName + '.' + m .name
875
927
f .__name__ = m .name
876
928
M [m .name ] = f
@@ -882,12 +934,15 @@ def __getProxyClass__(C, cls, sectionProxy=False):
882
934
M ['__getsecproxy__' ] = array_getsecproxy
883
935
M ['ckInsert' ] = array_ckInsert_gen (entryMethods [0 ].epIdx )
884
936
M ['ckDoneInserting' ] = array_proxy_doneInserting
937
+ M ['ckDestroy' ] = array_proxy_delete
885
938
if not sectionProxy :
886
- M ['ckContribute' ] = array_proxy_contribute # function called when target proxy is Array
939
+ M ['ckContribute' ] = array_proxy_contribute
940
+ # function called when target proxy is Array
887
941
M ['__getstate__' ] = array_proxy__getstate__
888
942
M ['__setstate__' ] = array_proxy__setstate__
889
943
else :
890
- M ['ckContribute' ] = arraysecproxy_contribute # function called when target proxy is Array
944
+ M ['ckContribute' ] = arraysecproxy_contribute
945
+ # function called when target proxy is Array
891
946
M ['__getstate__' ] = arraysecproxy__getstate__
892
947
M ['__setstate__' ] = arraysecproxy__setstate__
893
948
proxyCls = type (proxyClassName , (), M ) # create and return proxy class
@@ -896,6 +951,7 @@ def __getProxyClass__(C, cls, sectionProxy=False):
896
951
897
952
# ---------------------------------------------------
898
953
954
+
899
955
charm_type_id_to_class = [None ] * len (CHARM_TYPES )
900
956
for i in CHARM_TYPES :
901
957
if i == MAINCHARE :
@@ -907,7 +963,8 @@ def __getProxyClass__(C, cls, sectionProxy=False):
907
963
908
964
909
965
def charmStarting ():
910
- global charm , Options , Reducer , Charm4PyError , CharmRemote , profile_send_function
966
+ global charm , Options , Reducer , Charm4PyError , CharmRemote , \
967
+ profile_send_function
911
968
from .charm import charm , Charm4PyError , CharmRemote , profile_send_function
912
969
Options = charm .options
913
970
Reducer = charm .reducers
0 commit comments