Integrate Your Qt Application with MPI Library

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…

1

Run your Qt Creator

If you use Windows Vista or Windows 7 please make sure you run Qt Creator as Administrator. See picture below

menu_qt
2

Create Qt Console Application

Write project name as you want.

qt_mpi1

qt_mpi2

qt_mpi3

qt_mpi4

3

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"
project-qt



4

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;
}


code-qt-mpi

5

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"
run_mpi


 

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.

thumbnail_buku

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

Tags:

C/C++ | Grid Computing

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Agus Kurniawan

Agus Kurniawan

For more detail about me click here [V]

Please entry your name into my guestbook [V]

If you want to contact me, please go here [V]

My Books

Pocket Reference: Netduino for Beginner

Pocket Reference: Basic Sensors in Windows 8 Getting Started with Matlab Simulink and Raspberry Pi

Getting Started with Arduino and Java  Pocket Reference: Raspberry Pi Programming

Getting Started with Arduino and Matlab Getting Started with Arduino and .NET

Pocket Reference: Raspberry Pi Getting Started with Arduino and Node.js

MongoDB for VB.NET Panduan Praktis Windows Azure

Network Forensics: Panduan Analisis Dan Investigasi Paket Data Jaringan Menggunakan Wireshark Object-Relational Mapping (ORM): MongoDB, Mongoosejs and Node.js By Example

Nodejs Programming by Example MongoDB for by Example

Pemrograman Parallel Dengan MPI dan C Panduan Lengkap iPad 2 Untuk Pemula

Pemrograman Jaringan Dengan Java Aplikasi Pilihan iPad Untuk Anak-Anak

Buku lainnya [V]

Agus Kurniawan is Microsoft MVP (Most Valuable Professional)

Follow Me

Follow agusk2010 on Twitter

Month List