@@ -567,6 +567,11 @@ def group_ckNew(cls, args, onPEs):
567567 return proxy
568568 return group_ckNew
569569
570+
571+ def group_proxy_localbranch (proxy ):
572+ return charm .groups [proxy .gid ]
573+
574+
570575def group_proxy_contribute (proxy , contributeInfo ):
571576 charm .CkContributeToGroup (contributeInfo , proxy .gid , proxy .elemIdx )
572577
@@ -631,13 +636,16 @@ def __getProxyClass__(C, cls, sectionProxy=False):
631636 M ['__eq__' ] = group_proxy__eq__
632637 M ['__hash__' ] = group_proxy__hash__
633638 M ['ckNew' ] = group_ckNew_gen (cls , entryMethods [0 ].epIdx )
639+ M ['ckLocalBranch' ] = group_proxy_localbranch
634640 M ['__getsecproxy__' ] = group_getsecproxy
635641 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
637644 M ['__getstate__' ] = group_proxy__getstate__
638645 M ['__setstate__' ] = group_proxy__setstate__
639646 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
641649 M ['__getstate__' ] = groupsecproxy__getstate__
642650 M ['__setstate__' ] = groupsecproxy__setstate__
643651 proxyCls = type (proxyClassName , (), M ) # create and return proxy class
@@ -655,14 +663,19 @@ def __init__(self):
655663def array_proxy_ctor (proxy , aid , ndims ):
656664 proxy .aid = aid
657665 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+
659670
660671def array_proxy__getstate__ (proxy ):
661672 return (proxy .aid , proxy .ndims , proxy .elemIdx )
662673
674+
663675def array_proxy__setstate__ (proxy , state ):
664676 proxy .aid , proxy .ndims , proxy .elemIdx = state
665677
678+
666679def array_proxy__eq__ (proxy , other ):
667680 if proxy .issec :
668681 if hasattr (other , 'issec' ):
@@ -674,12 +687,14 @@ def array_proxy__eq__(proxy, other):
674687 else :
675688 return False
676689
690+
677691def array_proxy__hash__ (proxy ):
678692 if proxy .issec :
679693 return hash (proxy .section )
680694 else :
681695 return hash ((proxy .aid , proxy .elemIdx ))
682696
697+
683698def array_getsecproxy (proxy , sinfo ):
684699 if proxy .issec :
685700 secproxy = proxy .__class__ (proxy .aid , proxy .ndims )
@@ -688,12 +703,15 @@ def array_getsecproxy(proxy, sinfo):
688703 secproxy .section = sinfo
689704 return secproxy
690705
706+
691707def arraysecproxy__getstate__ (proxy ):
692708 return (proxy .aid , proxy .ndims , proxy .elemIdx , proxy .section )
693709
710+
694711def arraysecproxy__setstate__ (proxy , state ):
695712 proxy .aid , proxy .ndims , proxy .elemIdx , proxy .section = state
696713
714+
697715def array_proxy_elem (proxy , idx ): # array proxy [] overload method
698716 ndims = proxy .ndims
699717 isslice = True
@@ -703,17 +721,27 @@ def array_proxy_elem(proxy, idx): # array proxy [] overload method
703721 isslice = False
704722 elif idxtype == slice :
705723 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"
707726 if not isslice or not isinstance (idx [0 ], slice ):
708727 proxy_clone = proxy .__class__ (proxy .aid , ndims )
709728 proxy_clone .elemIdx = tuple (idx )
710729 return proxy_clone
711730 else :
712731 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'
714734 return charm .split (proxy , 1 , slicing = idx )[0 ]
715735
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
717745 def proxy_entry_method (proxy , * args , ** kwargs ):
718746 num_args = len (args )
719747 if num_args < argcount and len (kwargs ) > 0 :
@@ -726,7 +754,8 @@ def proxy_entry_method(proxy, *args, **kwargs):
726754 else :
727755 # if not there, see if there is a default value
728756 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'
730759 args .append (defaults [def_idx ])
731760
732761 header = {}
@@ -753,16 +782,20 @@ def proxy_entry_method(proxy, *args, **kwargs):
753782 root , sid = proxy .section
754783 header [b'sid' ] = sid
755784 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 )
757787 else :
758- charm .sectionMgr .thisProxy [root ].sendToSection (sid , ep , header , * args )
788+ charm .sectionMgr .thisProxy [root ].sendToSection (
789+ sid , ep , header , * args )
759790 return blockFuture
760791 proxy_entry_method .ep = ep
761792 return proxy_entry_method
762793
794+
763795def array_ckNew_gen (C , epIdx ):
764796 @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 ):
766799 # if charm.myPe() == 0: print("calling array ckNew for class " + C.__name__ + " cIdx=" + str(C.idx[ARRAY]))
767800 if type (dims ) == int : dims = (dims ,)
768801
@@ -789,17 +822,22 @@ def array_ckNew(cls, dims=None, ndims=-1, args=[], map=None, useAtSync=False):
789822 header [b'creation' ] = True
790823
791824 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 )
793827 proxy = cls (aid , len (dims ))
794828 if creation_future is not None :
795829 proxy .creation_future = creation_future
796830 return proxy
797831 return array_ckNew
798832
833+
799834def 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'
803841 header = {}
804842 if single :
805843 header [b'single' ] = True
@@ -812,11 +850,15 @@ def array_ckInsert(proxy, index, args=[], onPE=-1, useAtSync=False, single=False
812850 charm .lib .CkInsert (proxy .aid , index , epIdx , onPE , msg , useAtSync )
813851 return array_ckInsert
814852
853+
815854def array_proxy_contribute (proxy , contributeInfo ):
816855 charm .CkContributeToArray (contributeInfo , proxy .aid , proxy .elemIdx )
817856
857+
818858def 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+
820862
821863def array_proxy_doneInserting (proxy ):
822864 charm .lib .CkDoneInserting (proxy .aid )
@@ -826,30 +868,38 @@ class Array(object):
826868
827869 type_id = ARRAY
828870
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 ):
830873 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' )
832876 if C not in charm .proxyClasses [ARRAY ]:
833877 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 )
835880
836881 @classmethod
837882 def initMember (cls , obj , aid , index , single = False ):
838883 obj .thisIndex = index
839884 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 ))
841887 obj .thisProxy = proxy [index ]
842888 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 )
845893 obj .migratable = True
846894
847895 @classmethod
848896 def __baseEntryMethods__ (cls ):
849897 # 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)
851900 # - 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.
853903 return ['__init__' , 'migrated' , 'AtSync' ]
854904
855905 @classmethod
@@ -868,9 +918,11 @@ def __getProxyClass__(C, cls, sectionProxy=False):
868918 continue
869919 argcount , argnames , defaults = getEntryMethodInfo (m .C , m .name )
870920 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 ))
872923 else :
873- f = array_proxy_method_gen (m .epIdx , argcount , argnames , defaults )
924+ f = array_proxy_method_gen (
925+ m .epIdx , argcount , argnames , defaults )
874926 f .__qualname__ = proxyClassName + '.' + m .name
875927 f .__name__ = m .name
876928 M [m .name ] = f
@@ -882,12 +934,15 @@ def __getProxyClass__(C, cls, sectionProxy=False):
882934 M ['__getsecproxy__' ] = array_getsecproxy
883935 M ['ckInsert' ] = array_ckInsert_gen (entryMethods [0 ].epIdx )
884936 M ['ckDoneInserting' ] = array_proxy_doneInserting
937+ M ['ckDestroy' ] = array_proxy_delete
885938 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
887941 M ['__getstate__' ] = array_proxy__getstate__
888942 M ['__setstate__' ] = array_proxy__setstate__
889943 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
891946 M ['__getstate__' ] = arraysecproxy__getstate__
892947 M ['__setstate__' ] = arraysecproxy__setstate__
893948 proxyCls = type (proxyClassName , (), M ) # create and return proxy class
@@ -896,6 +951,7 @@ def __getProxyClass__(C, cls, sectionProxy=False):
896951
897952# ---------------------------------------------------
898953
954+
899955charm_type_id_to_class = [None ] * len (CHARM_TYPES )
900956for i in CHARM_TYPES :
901957 if i == MAINCHARE :
@@ -907,7 +963,8 @@ def __getProxyClass__(C, cls, sectionProxy=False):
907963
908964
909965def charmStarting ():
910- global charm , Options , Reducer , Charm4PyError , CharmRemote , profile_send_function
966+ global charm , Options , Reducer , Charm4PyError , CharmRemote , \
967+ profile_send_function
911968 from .charm import charm , Charm4PyError , CharmRemote , profile_send_function
912969 Options = charm .options
913970 Reducer = charm .reducers
0 commit comments