Setting Up Qt Creator for MPIC++
-
I am trying to configure Qt Creator to use the mpic++ wrapper compiler, but I am experiencing linking issues...
Starting from what does work: I have created a standard HelloWorld example with the following .pro file
QMAKE_CC = mpicc QMAKE_CXX = mpicxx QMAKE_CFLAGS = $$system(mpicc --showme:compile) QMAKE_CXXFLAGS = $$system(mpic++ --showme:compile) QMAKE_LFLAGS = $$system(mpic++ --showme:link) SOURCES += \ main.cpp HEADERS +=
where main.cpp contains the HelloWorld code
#include <mpi.h> #include <stdio.h> int main(int, char **) { int Rank, Size, Length; char Name[MPI_MAX_PROCESSOR_NAME]; MPI::Init(); MPI_Get_processor_name(Name, &Length); MPI_Comm_size(MPI_COMM_WORLD, &Size); MPI_Comm_rank(MPI_COMM_WORLD, &Rank); printf("Hello world from processor %s, rank %d out of %d processors\n", Name, Rank, Size); MPI::Finalize(); }
I managed to get qmake work on my little Ubuntu-based Beowulf cluster (which has the openmpi-bin and libopenmpi-dev packages installed) by simply installing qt5-default package and using qmake (which correctly uses the mpic++ wrapper compiler). This works perfectly and allows me to properly deploy my eventual MPI program. Great :)
Now, I would like to develop my MPI program on my Ubuntu workstation. So, I have installed the openmpi-bin and libopenmpi-dev packages there. Hence, the mpic++ wrapper compiler and mpirun command are appropriately available on my Ubuntu workstation, meaning that I can compile and run the HelloWorld example by using direct command line execution of the mpic++ wrapper compiler (and subsequently mpirun to execute the program). Also this works perfectly.
However, using the qmake executable (from the command line) that came with the Qt Creator installation on my Ubuntu workstation gives a bunch of linking errors, which basically state 'undefined reference' for all MPI code. What am I missing?
I also would like to compile and run my MPI program from the Qt Creator GUI. Apart from the linking errors, I also get the warning that qmake uses the mpic++ wrapper compiler, while the 'kit' is configured to g++. How to fix this warning? I have tried to add a kit by first attempting to auto-detect the mpic++ compiler, but it is not detected. Any ideas on this?
-
Ok, diving a bit more into it. This is strange:
mpic++ --showme:link
returns
-pthread -L/usr//lib -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi_cxx -lmpi
on my Ubuntu workstation. If I add
LIBS += -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi_cxx -lmpi
to my .pro file, then it all works. However, I want to avoid adding this to the .pro file as the link flags are different on my Beowulf cluster. So, what is wrong with my original .pro file in the following line?
QMAKE_LFLAGS = $$system(mpic++ --showme:link)
-
@ModelTech in your pro file use similar settings like the following
win32: {
}
unix: {
LIBS += -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi_cxx -lmpi
}you can even define some env variables for different platforms and use them in your pro file.
-
Ok, that is a good idea.
What I find strange however is that the g++ linker command on my workstation now actually shows two times "-L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi_cxx -lmpi" and I do not see why that is needed. This is the shown message:
g++ -pthread -L/usr//lib -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi_cxx -lmpi -Wl,-rpath,/home/user/Qt/5.12.5/gcc_64/lib -o mpi main.o -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi_cxx -lmpi /home/user/Qt/5.12.5/gcc_64/lib/libQt5Gui.so /home/user/Qt/5.12.5/gcc_64/lib/libQt5Core.so -lGL -lpthread