charmplusplus / charm4py

Parallel Programming with Python and Charm++
https://charm4py.readthedocs.io
Apache License 2.0
289 stars 21 forks source link

Local message optimization breaks correctness #215

Open adityapb opened 2 years ago

adityapb commented 2 years ago

The local message optimization stores a reference to entry method arguments in the destination chare's local msg buffer if the source and destination chares lie on the same PE to avoid copying and serialization. This is an issue because if the sender chare then modifies the data being sent, the receiving chare will now be holding a reference to the modified data.

from time import time
import numpy as np
mainProxy = None

class TestCopy(Chare):
    def __init__(self):
        x = np.array([0, 0])
        mainProxy.send(x)
        x[1] = 10

class Main(Chare):
    def __init__(self, args):
        charm.thisProxy.updateGlobals({'mainProxy': self.thisProxy},
                                      '__main__', awaitable=True).get()
        Chare(TestCopy)

    def send(self, x):
        print(x)
        charm.exit()

charm.start(Main)

For example, the above code prints out [0, 10]