by Agus Kurniawan
1. March 2011 09:49
Qt Framework can help you to build a native application with cross platform capability. Simulation and visualization library was provided to you to enrich your model. How about parallel model capability on Qt? Well, it’s very easy to integrate your Qt application with parallel library such as OpenMPI and MPI. On this article I would like to show you how to configure you Qt Creator with MPI library.
There are many MPI library you can use to build parallel program. On this article, I’m going to use MPICH2 as an illustration example. You can download MPICH2 on this website, http://www.mcs.anl.gov/research/projects/mpich2/.
Let’s code now…
 | Run your Qt Creator If you use Windows Vista or Windows 7 please make sure you run Qt Creator as Administrator. See picture below
|
 | Create Qt Console Application Write project name as you want.
|
 | Configure Qt project file For Windows OS: Assume you installed MPICH2 on directory C:\Program Files (x86)\MPICH2. Now you can configure your Qt project file as below QT += core
QT -= gui
TARGET = QtMpi
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "C:/Program Files (x86)/MPICH2/include"
LIBS += "C:/Program Files (x86)/MPICH2/lib/mpi.lib"
|
 |
Write your parallel program
Here is a simple parallel program for testing
#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int numberOfProcessors;
int rank;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);
printf("Hello MPI\r\n");
MPI_Comm_size(MPI_COMM_WORLD,&numberOfProcessors);
printf("Number of processor = %d\r\n", numberOfProcessors);
MPI_Get_processor_name(processor_name, &namelen);
printf("Process Name = %s\r\n", processor_name);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("Proses pada %d\r\n", rank);
MPI_Finalize();
return 0;
}
|
 |
Compile and run it
Firstly you must compile your program using Qt compiler then you can run your parallel program using mpiexec. Here is a sample script to run my parallel program. For Windows user, run Commandline and change to directory where MPICH2 installed.
mpiexec -n 3 "C:\Users\Agus Kurniawan\Documents\QT_Projects\QtMpi-build-desktop\debug\QtMpi.exe"
|
What’s Next?
Now you can use Qt Creator to develop parallel program using MPI. Next you should learn how to write parallel program. There are many resources such as article, paper, book to help you how to write parallel program. For Indonesia people, I wrote a book about parallel programming using MPI and C. Please review this book on this link. This book was published by Penerbit ANDI. You can buy it on bookstore.

I have a special offer for related to this book, please read my posted blog here.