multiscale / muscle3

The third major version of the MUltiScale Coupling Library and Environment
Apache License 2.0
25 stars 13 forks source link

Program SEGFAULTS when linking against both libmuscle_mpi and libmuscle #182

Closed maarten-ic closed 1 year ago

maarten-ic commented 1 year ago

When a C++ or Fortran program is targeting the mpi version of libmuscle, but links against both the mpi and regular shared library, SEGFAULTS or other undefined behaviour may happen.

When linking with -lmuscle -lmuscle_mpi (in that order!), the following happens:

Suggested solution:

maarten-ic commented 1 year ago

Note: documentation https://muscle3.readthedocs.io/en/latest/installing.html should also be updated to include a note or warning against combining libmuscle and libmuscle_mpi

LourensVeen commented 1 year ago

I think I would prefer having different symbol names, so that this fails at link time rather than at runtime. If it doesn't get linked correctly, then anything can happen at runtime and that's a little too shaky.

For C++, we could rename the libmuscle::impl namespace to libmuscle::impl_mpi for the MPI version of the library, that should give an error message that hints at what's wrong. This will still leave the symbols outside of Instance duplicated (e.g. Message and Data), so that linking against both libraries could still get them confused, but they don't use MPI so they're identical and that should hopefully work anyway. I don't think there's much else we can do at link time.

For Fortran, we could achieve a similar result by changing the names of the exported C functions; those names are hidden from the user so it won't change the API, but they are what gets linked against, so you get an error about LIBMUSCLE_MPI_Instance_create_ not being found and that should give a hint.