Skip to content

Commit 9be76b8

Browse files
committed
Refactoring of chare registration functions
1 parent dd4acae commit 9be76b8

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

charmpy/charm.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def packMsg(self, destObj, msgArgs, header):
312312
return (msg, direct_copy_buffers)
313313

314314
# register class C in Charm
315-
def registerInCharm(self, C, charm_type, libRegisterFunc):
315+
def registerInCharmAs(self, C, charm_type, libRegisterFunc):
316316
charm_type_id = charm_type.type_id
317317
entryMethods = self.classEntryMethods[charm_type_id][C]
318318
# if self.myPe() == 0: print("CharmPy:: Registering class " + C.__name__ + " in Charm with " + str(len(entryMethods)) + " entry methods " + str([e.name for e in entryMethods]))
@@ -328,6 +328,19 @@ def registerInCharm(self, C, charm_type, libRegisterFunc):
328328
setattr(self, proxyClass.__name__, proxyClass) # save new class in my namespace
329329
setattr(chare, proxyClass.__name__, proxyClass) # save in module namespace (needed to pickle the proxy)
330330

331+
def registerInCharm(self, C):
332+
C.idx = [None] * len(CHARM_TYPES)
333+
charm_types = self.registered[C]
334+
if Mainchare in charm_types:
335+
self.registerInCharmAs(C, Mainchare, self.lib.CkRegisterMainchare)
336+
if Group in charm_types:
337+
if ArrayMap in C.mro():
338+
self.registerInCharmAs(C, Group, self.lib.CkRegisterArrayMap)
339+
else:
340+
self.registerInCharmAs(C, Group, self.lib.CkRegisterGroup)
341+
if Array in charm_types:
342+
self.registerInCharmAs(C, Array, self.lib.CkRegisterArray)
343+
331344
# first callback from Charm++ shared library
332345
# this method registers classes with the shared library
333346
def registerMainModule(self):
@@ -356,17 +369,7 @@ def registerMainModule(self):
356369
print(out_msg)
357370

358371
for C in self.register_order:
359-
C.idx = [None] * len(CHARM_TYPES)
360-
charm_types = self.registered[C]
361-
if Mainchare in charm_types:
362-
self.registerInCharm(C, Mainchare, self.lib.CkRegisterMainchare)
363-
if Group in charm_types:
364-
if ArrayMap in C.mro():
365-
self.registerInCharm(C, Group, self.lib.CkRegisterArrayMap)
366-
else:
367-
self.registerInCharm(C, Group, self.lib.CkRegisterGroup)
368-
if Array in charm_types:
369-
self.registerInCharm(C, Array, self.lib.CkRegisterArray)
372+
self.registerInCharm(C)
370373

371374
def registerAs(self, C, charm_type_id):
372375
if charm_type_id == MAINCHARE:

0 commit comments

Comments
 (0)