# Developing MPI applications in Qt Creator

I have grown very fond of the ease and usability of Qt Creator lately, making it my main tool for developing anything in C and C++. Recently I started learning the MPI framework for doing large scale parallel programming and figured I wanted to try to make MPI play along with Qt Creator.

The first thing I noticed is that there is no problem using Qt Creator as an editor while compiling the MPI executable and running it from the command line. However, for the quick and easy testing of minor changes, running by pressing Ctrl + R in Qt Creator quickly came to a high place on my wish list.

After a quick search around the Internet, I found the necessary adjustments to make this exact thing happen. The steps are as follows:

### Make Qt Creator use mpicxx instead of g++

To change the compiler in Qt Creator, you simply have to edit the .pro file of your project. Add the following lines, and Qt Creator will call mpicxx instead of g++:

# MPI Settings
QMAKE_CXX = mpicxx
QMAKE_CXX_RELEASE = $$QMAKE_CXX QMAKE_CXX_DEBUG =$$QMAKE_CXX
QMAKE_LINK = $$QMAKE_CXX QMAKE_CC = mpicc QMAKE_CFLAGS +=$$system(mpicc --showme:compile)
QMAKE_LFLAGS += $$system(mpicxx --showme:link) QMAKE_CXXFLAGS +=$$system(mpicxx --showme:compile) -DMPICH_IGNORE_CXX_SEEK
QMAKE_CXXFLAGS_RELEASE += system(mpicxx --showme:compile) -DMPICH_IGNORE_CXX_SEEK

This also sets the correct compile and link flags in addition to changing the linker to mpicxx as well. The DMPICH_IGNORE_CXX_SEEK flag is added to avoid some errors I experienced on Red Hat Linux 5.

### Running the application with mpirun

Usually Qt Creator will simply run the generated executable after compiling, but to make use of multiple processors (which kind of is the whole point with MPI), you have to change the run settings of your project to a custom executable. This is done in the project configuration in Qt Creator under the Run tab for your project.

Add a Custom Executable run configuration and set the executable to /usr/bin/mpirun or any other path where mpirun resides on your system (run ‘which mpirun’ in a terminal to find it if you don’t know where it is). Then, set the arguments to

-n 2 yourexecutable

to run yourexecutable with 2 processors. Of course you’ll have to change yourexecutable to whatever your executable is named.