Note: The OMPTL is now included in the
CVMLCPP library, but
separate releases of the OMPTL alone will still be made available here.
Parallelization of C++ applications
The University of Geneva has developed two libraries to parallelize
C++ applications in a way that is very, very easy for developers. The two
libraries, OMPTL and MPTL,
both serve the same purpose and operate by similar principles, but use
different underlying technology. The MPTL has been developed by in
'Scientific and Parallel Computing'
group and the OMPTL has been developed in the
'Stochastic Image Processing' group.
The exchange of insights, key to the success of both libraries, is a
hallmark proof of the importance of coffee-breaks during work.
In a nutshell...
With 'Dual-Core' and
processors on many desktops, and more to come, current software must be
parallelized to take advantage of the available hardware. Parallelizing
programs is a non-trival task. The technology developed here at the
University of Geneva greatly eases the task of changing existing
software to take advantage of parallel processing, even if that software
was not originally designed to run in parallel.
In more technical words...
The OMPTL and MPTL re-implement the algorithm and numeric
part of the Standard Template Library of C++. The range is partitioned,
then the computation is executed in parallel. The MPTL uses posix-threads,
the OMPTL uses OpenMP.
Imagine the following piece of code, which is serial:
This example is the parallel code with OMPTL:
This example is the parallel code with MPTL:
The MPTL requires that you link your program with pthreads, i.e.
The OMPTL requires that compile your programs with an OpenMP-capable compiler,
for example the Intel(C) compiler or GCC 4.2:
To compile OMPTL-code with a compiler that does not support OpenMP, or
if you wish to disable OpenMP for another reason, simply compile without OpenMP.
All calls to algorithms will be redirected to their std:: counterparts.
Contrarily to what one might expect, the OMPTL is not all eager to
execute tasks in parallel. The truth of the matter is that
paralellization tends to introduce overhead and a loss of efficiency. In
many cases, using a serial version of an algorithm is simply the better
choice, a testimony to the excellent quality of the Standard Template
Library. Even if parts are executed in parallel, the application will
only undergo a significant speedup if the parallelized work represents a
significant part of the computation required by your application.
Thirdly, each call to an algorithm must be on a sufficiently large
range, and not successive calls on small ranges. The fourth restrictions
is that only calls to STL's 'algorithm' and 'numeric' components are
parallelized, so if your code does not use these, it will not benefit.
And the last bad news: not all algorithms are parallelized yet, and
some never will be.
Having said all these bad things, there is no penalty for using the
OMPTL, and changing your code to use the OMPTL is extremely easy, so you
really have only to gain from using it. If your application uses
time-consuming operations on large data, such as in Image Processing, you
will definately be interested.
The OMPTL and MPTL are free, open source software, available under the
LGPL, the 'Lesser
GNU Public License'. This license is the authorative text, here follows
a non-authorative summary:
If you find a bug in the OMPTL, please send a clear report, and if
possible a patch to Fokko dot Beekhof at
unige dot ch . For bugs in the MPTL, see its official
web page, or send an email to this address. We do not have much time to work
on this, so patches are preferred.