Open mdjurfeldt opened 8 years ago
@mdjurfeldt Ive made a first prototype but there are segmentation faults under certain conditions. For cont_out ports in NEST it worked fine, also for the pure pymusic message port (in pymusic/examples folder). For event ports it always crashes and I can not figure out what exactly goes wrong.
https://github.com/uahic/MUSIC/tree/multi_setups_common_structure
[kia:11695] [ 0] [0xb7799410] [kia:11695] [ 1] /usr/lib/i386-linux-gnu/libstdc++.so.6(dynamic_cast+0x23) [0xb6da88c3] [kia:11695] [ 2] /disk/no_backup/schulze/builds_32/MUSIC_1_1_15_python27/lib/libmusic.so.1(_ZN5MUSIC7Runtime16takeTickingPortsEPNS_5SetupE+0x4a) [0xb6e8f8fa] [kia:11695] [ 3] /disk/no_backup/schulze/builds_32/MUSIC_1_1_15_python27/lib/libmusic.so.1(_ZN5MUSIC7RuntimeC1EPNS_5SetupEd+0x48b) [0xb6e8ffeb] [kia:11695] [ 4] /disk/no_backup/schulze/builds_32/MUSIC_1_1_15_python27/lib/python2.7/site-packages/music/pymusic.so(+0x1ce7e) [0xb777ee7e] [kia:11695] [ 5] python() [0x8164d1e] [kia:11695] [ 6] /disk/no_backup/schulze/builds_32/MUSIC_1_1_15_python27/lib/python2.7/site-packages/music/pymusic.so(+0x115ee) [0xb77735ee] [kia:11695] [ 7] python(PyEval_EvalFrameEx+0xca7) [0x8197397] [kia:11695] [ 8] python(PyEval_EvalCode+0x122) [0x819dd92] [kia:11695] [ 9] python() [0x81f01ed] [kia:11695] [10] python(PyRun_FileExFlags+0x97) [0x80a9728] [kia:11695] [11] python(PyRun_SimpleFileExFlags+0x2e2) [0x80aa008] [kia:11695] [12] python(Py_Main+0xc60) [0x80aad65] [kia:11695] [13] python(main+0x1b) [0x80aae44] [kia:11695] [14] /lib/i386-linux-gnu/libc.so.6(libc_start_main+0xf3) [0xb75a7a83] [kia:11695] [15] python() [0x81af876]
@mdjurfeldt Would multiple setups actually work under the current code? If not, then the setup object should be a singleton anyhow.
In the proposed code (see above) I added a static pointer(1) to a struct which holds the common ports and connections. The runtime object can fetch the common data by calling any of the Setup's getter methods. The code for deleting the ports etc. within the Setup is also removed. I think the creator of this objects should be responsible for doing so (e.g. NEST or PyMusic). Same story for the setup instances: The runtime object could remove them but from a software-design perspective this is somehow fragile and unintuitive. The Runtime could simply ask the struct to clear all vectors that keep track of the pointers to ports/connections. To avoid altering the interface of connections() and ports() in Setup, the ports/connection pointer lists are flat copied (so the runtime does not have pointers to internal data of Setup instances.
*1: The MPI Intracomm must be fetchable among all instances and be unique. Without spending hours of research I was not able to find out quickly how to clone and free MPI communicators properly. In the end the pointer was necessary to allow to remove it since a static variable is probably destroyed at the very end of the program which collides with MPI::finalize() calls of Nest
Okay bug is fixed, it seems to work now but in the pymusic bindings there is a supressed exception which will be approached now
It might be desirable, within a Python script, to mix ports handled at the C++ level in a simulator with ports created through the PyMUSIC API.
One way to achieve this is to allow the MUSIC::Setup object to be created multiple times. There could be one instance in the simulator and one at the Python level. Internally, they would refer to the same datastructure(s).