OMPTL

OpenMP Multi-Threaded Template Library

CUI - University of Geneva

Keywords: C++, STL, parallel, OpenMP, pthreads, OMPTL, MPTL

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 'HyperThreading' 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.

Documentation

For details, consult the documentation which is part of the CVMLCPP library. Changes can be found in CVMLCPP's Release Notes.

Download

OMPTL

Release date Changelog Download
22 April 2012
  • Bug-fix for internal bug spotted by Oleksiy Datiy.
ZIP
TAR/BZ2
03 August 2011
  • Bug-fix for internal bug spotted by Robert Rumpf.
  • Can now use <omptl/algorithm> instead of <omptl/omptl_algorithm>
  • Can now use <omptl/numeric> instead of <omptl/omptl_numeric>
ZIP
TAR/BZ2
23 February 2010
  • Bug-fix in partial_sort() by Dominic Couture-Savoie.
ZIP
TAR/BZ2
05 April 2009
  • Bug-fix in code deciding when to paralellize.
  • Fixed 32/64-bit issues.
ZIP
TAR/BZ2
06 March 2009
  • Bug-fix to sort().
    (Thanks to Bartosz Tomicki)
ZIP
TAR/BZ2
04 June 2008
  • Important bug-fixes.
    (Thanks to Dibyendu Das)
ZIP
TAR/BZ2
11 May 2008
  • Improved transparancy for compilation without OpenMP: OMPTL_OFF removed in favor of automatic detection
ZIP
TAR/BZ2
13 December 2007
  • Improved transparancy for compilation without OpenMP.
  • Stricter compliance to C++ standard required by Sun C++ Compiler
ZIP
TAR/BZ2
19 October 2007
  • Minor bugfixes, use reductions.
    (Thanks to Joel Yliluoma)
ZIP
TAR/BZ2
29 September 2007
  • Several major bugfixes.
ZIP
TAR/BZ2
4 September 2007
  • Copy-paste correction.
download
20 August 2007
  • Improved iterator handling traits.
  • Improved accumulate()
download
30 November 2006
  • Added several missing algorithms.
  • Include detection of iterator types.
download
21 November 2006
  • Initial release
download

MPTL

The official releases are on the offical MPTL website, but here goes:
Release date Changelog Link
21 November 2006
  • Fixed example
download

Using MPTL and OMPTL

Browse the source of OMPTL.

Example

Imagine the following piece of code, which is serial:
#include <vector>
#include <algorithm>

int main (int argc, char * const argv[])
{
	std::vector<int> v1(100000);

	std::sort(v1.begin(), v1.end());

	return 0;
}
	

This example is the parallel code with OMPTL:
#include <vector>

#include <omptl/omptl_algorithm>

int main (int argc, char * const argv[])
{
	// Number of threads is derived from environment
	// variable 'OMP_NUM_THREADS'

	std::vector<int> v1(100000);

	omptl::sort(v1.begin(), v1.end());

	return 0;
}
	

This example is the parallel code with MPTL:
#include <vector>

#include <mptl.h>
#include <mptl_algo.h>
#include <mptl_qsort.h>

int main (int argc, char * const argv[])
{
	mptl::setNumThreads(2);

	std::vector<int> v1(100000);

	mptl::sort(v1.begin(), v1.end());

	return 0;
}
	

Compiling

The MPTL requires that you link your program with pthreads, i.e.
  g++ -I/path/to/mptl/ -lpthread myprog.cpp

The OMPTL requires that compile your programs with an OpenMP-capable compiler, for example the Intel(C) compiler or GCC 4.2:
  icc -I/path/to/omptl/ -openmp myprog.cpp
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. For example:
  gcc -I/path/to/omptl/ myProg.cc

Effects

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.

License

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:
  • You are allowed to use the OMPTL and MPTL libraries in all your software. Your software does not need to be open-source or free.
  • If you make changes and improvements to the OMPTL or MPTL itself, you are required to make these changes available.
  • You may not claim or pretend to own the code in whole or in parts, violate the copyright, or remove the license notes.
  • Use of this software is entirely at your own risk.

Bugs

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.

http://tech.unige.ch/omptl/