-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
problem linking mpi memory routines from C++ #12247
Comments
Your application is using the MPI C++ bindings that have been removed from the MPI standard more than a decade ago. The right fix is to modernize your code and stop using them. Meanwhile, you can rebuild Open MPI by passing |
Thanks - now could you please suggest a simple way to revert to using C bindings? It seems, I can't just put extern "C" { #include <mpi.h>}. Perhaps I can put extern "C" {} around each and every instance of MPI use, but I don't think so. An alternative may be to pull them all the routines I've used out of C++ code and put them into a C code file; effectively, to re-wrap them - that used to be my approach when I was only calling a small set of MPI routines. (Forgive me but that somehow doesn't seem like "modernization"!) |
This is not straight forward, but this is not rocket science either. For example, you can compare Stopping using an API that has been removed from the MPI standard more than a decade ago is indeed modernization. |
Another, perhaps simpler, option might be to just use OMPI v3.x - IIRC, the C++ bindings were still supported at that time. Unless you really need something in the 4.x series, you can probably find an older version that works for you. |
Another question occurs to me though: why don't I get the same issues when I call a more restricted set of MPI routines directly from C++? That approach seems to work fine with openmpi. I would have thought that I should get many more instances of linkage failure if the problem is related to removal of C++ bindings. |
you are probably using the |
But, a top-level instance of #include <mpi.h> is used in every C++ file I have. So how could I be using the C bindings? Maybe because testing for CXX is not uniform/consistent across openmpi include files? That seems a bit unlikely. However, I'm happy to believe you that I should be using C bindings now, and make the adjustments if I have to. |
there is only one include file, and it is For example you use the That being said, maybe the |
Oh for sure, I am just using the C bindings within my C++ code. For example
Thank you, changing the link command is a good idea. I don't have such easy direct control over link flags because I'm using macports and cmake. I will have a go though, and also feed that back to the macports maintainers. Also, I can't find ring_cxx.cc in the examples... |
Hmmmm. I should just be able to use the C bindings directly as I am doing though, right? Again, I am wondering if there is a missing extern "C" in some header file. I see a few remarks about this when I look through the headers. |
That's a Try to the example can be seen at https://github.com/open-mpi/ompi/blob/v4.1.x/examples/ring_cxx.cc |
Hmmm. No Clone, but MPI_Datatype does certainly get used. And MPI_Type_free(). All in one simple base file. Both these things come up on the errors. Perhaps I'm mis-using something, let me review that file. (Why that would have worked with mpich, I don't know...). Thanks again for your suggestions. |
Since you are not using the |
I see there's been a bunch of back-n-forth here -- let me throw in a few things to check:
|
FWIW That suggests the MPI C++ bindings are indeed available but I naively expect these undefined references would not be there if they were not used by the application, but you know, C++ does C++, so maybe I should drop my expectations. |
Ah, there it is. Ok. Then I think it would be very good to see exactly what the underlying command is for |
I have no idea why any MPI C++ bindings get invoked if I have only used the C bindings in the first place. And, why only 3 or 4 undefined symbols, when I have used quite a few MPI routines? (Pondering these issues again leads me to wonder about something buried in openmpi header files.) Below is the link command for elliptic_mp. As I suspected, (Apple/Xcode) g++ is used as the linker, not mpi_cxx. For completeness, I have first listed a compile command for one of the object files (helmholtz.o) which complains about undefined symbols. The -DMPI_EX is a definition issued by me.
and
Finally, here again are the undefined symbol messages:
Thanks again for your thoughts. |
Thanks for the feedback. The easiest workaround is probably to A slightly better one should be to understand why Or you can pass FWIW
so yeah, some undefined C++ symbols are generated even if they are not used! |
Pardon me, but I think these outcomes point to an error in the openmpi preprocessing system. As a slightly more extended example, albeit using g++, not mpicxx.
Now, what happens withj openmpi headers and g++:
I suggest that is clearly a problem. Since I didn't ask for any MPI routines, nothing MPI-related should arise. Here is what occurs with mpich headers:
Exactly what I'd expect should happen. I'm unsure about the macosx warning but think it comes from Xcode/g++ and is unrelated. |
I don't know... Unlike MPICH, Open MPI has a lot of C++ inlined subroutines/constructors that invoke the C bindings. Anyway, I strongly doubt this issue will be adressed so I suggest you use one of the described workarounds. |
(Setting the C++ compiler to mpicxx did fix some issues, but I still couldn't get everything to work, since I use C and F77 too. I had trouble getting it all up and running.) HOWEVER: I think I missed a step in my macports setup, which was to install port openmpi-default. That is meant to set all the compilers correctly/consistently. Using the equivalent cured my problems with mpich, so I can believe it will work with openmpi too. (The macports documentation could use some improvement! But, this is entirely understandable.) Thank you for your explanations and patience. |
Later ... I went back and re-installed openmpi and added macports installation for openmpi-default ("sudo port install openmpi-default +gcc12"). That did not fix the problem, which remains as I have described above. But, I found the suggested workaround, passing -DOMPI_SKIP_MPICXX to the C++ compiler, does work. Still using openmpi version 4.1.6 as installed by macports. |
Further - I found the same error occurring on Ubuntu linux (20.04) with openmpi (but not, again, with mpich). Adding the suggested workaround again overcame the problem. So, it seems more deep-rooted than something associated with a particular installation set. BTW, these errors only seemed to have arisen when I started to use Cartesian routines with MPI. (E.g. MPI_Cart_create) - I had previously (for over a decade?) used openmpi without issue. |
I am not sure of what you are expecting here. |
Thanks. I am waiting for all the port maintainers to install V5 upgrades. But - I think the surprising thing for me is that the issue seemed to be raised just by using a (very old) part of MPI that I hadn't previously accessed, whereas I started out thinking it was package-dependent (macports). It seems so general that I'm surprised other users don't seem to have reported it. On the plus side, I am finding that openmpi is quite a bit faster than mpich on my Mac Studio. The thing that caused me to revisit openmpi was finding only 80% CPU use with mpich. But execution with openmpi seems way faster than the missing 20%. |
Thank you for taking the time to submit an issue!
Background information
I am compiling an application (my own) which has C++ as the top level but also uses some C and F77 libraries. The build system is cmake on OSX via macports. The application is about 2 decades old now, and has successfully used various versions of MPI-1 for most of that time. Recently I added some new MPI memory and IO routines to do with Cartesian communicators and parallel IO, and have created a small set of linkage problems if using openmpi (they can however be linked successfully if I use mpich). The problem has persisted across two OS X versions, so I suspect the problem lies in openmpi code base. It has the flavour of a misplaced "extern" declaration in a header file.
What version of Open MPI are you using? (e.g., v4.1.6, v5.0.1, git branch name and hash, etc.)
4.1.6
Describe how Open MPI was installed (e.g., from a source/distribution tarball, from a git clone, from an operating system distribution package, etc.)
Installed via macports. (Of course this leaves open the possibility that the problem lies there...)
If you are building/installing from a git clone, please copy-n-paste the output from
git submodule status
.Please describe the system on which you are running
Details of the problem
The build fails at the linkage stage, unable to find 4 low-level (not API-level) MPI routines called from various object files. Below is a clip of the relevant messages.
These linkage errors do not occur if I use mpich instead of openmpi (but right now I have issues with mpich not working on Sonoma). As I said, this looks like it could be an issue with C++ mangling routine names as a result of a misplaced "extern" declaration in a header.
An older code version which used a smaller subset of MPI continues to compile and run fine.
The text was updated successfully, but these errors were encountered: