libppl(3)
π libppl(3) β the C++ interface of the Parma Polyhedra Library π
okay bestie, welcome to the libppl(3) overview page, this is your lil orientation sesh for the C++ interface of the Parma Polyhedra Library (PPL) β¨
β¨ SYNOPSIS β¨
#include <ppl.hh>
c++ file.cc -lppl
πΈ DESCRIPTION πΈ
So this is a short lil overview on how to use the Parma Polyhedra Library (PPL) in your C++ programs on Unix-like operating systems. periodt π
ngl tho, a couple things to note up front:
- the PPL has interfaces for C, Java, OCaml and a number of Prolog systems too β so if that's your vibe, look elsewhere for docs on those π
- also this document does not describe the library functionality, its classes, or its methods and functions. for all that good stuff you want The Parma Polyhedra Library User's Manual (version 1.2) π
π INCLUDING THE HEADER FILE π
The C++ interface of the PPL has literally only one header file, and its name is ppl.hh. so your program should contain a directive of the form:
#include <ppl.hh>
Of course, you gotta make sure you installed the PPL somewhere the compiler can find it β either by itself, or with the help of a suitable -Idir command line option π«Ά (peep the file INSTALL for info on how to configure the library so it installs wherever you want it to live).
π¦ INITIALIZING AND FINALIZING THE LIBRARY π¦
The mere inclusion of ppl.hh in at least one file of your project will cause the automatic initialization and finalization of the library. iconic behaviour honestly β¨
BUT. and this is a big but π there are situations where automatic initialization and finalization is not desirable (e.g., if the application fiddles with the GMP's memory allocation functions). in those cases, every inclusion of ppl.hh must take the form:
#define PPL_NO_AUTOMATIC_INITIALIZATION
#include <ppl.hh>
when automatic initialization and finalization is disabled you must absolutely call the function void Parma_Polyhedra_Library::initialize() before using the library. no skipping this one bestie, fr fr π
It is also a good norm to call the function void Parma_Polyhedra_Library::finalize() when you are done with the library π
π USING THE LIBRARY π
Keeping in mind that there is no substitute for a careful reading of The Parma Polyhedra Library User's Manual (version 1.2) π, you can find many examples of use in the directories tests (see the README file in that directory) and demos/ppl_lcdd of the source distribution π₯
β LINKING WITH THE LIBRARY β
Linking with the C++ interface of the Parma Polyhedra Library is best done using the C++ compiler itself, so slay. usually, just specifying the -lppl command line option is enough π«Ά
In fact, if you use a shared version of the library, this automatically records the dependency from the GMP library β something the linker ought to deal with gracefully β¨ otherwise you will have to add -lgmpxx -lgmp to the command line.
Things get more complex if you installed the PPL into some nonstandard place π in this case you will have to use the -Ldir option and, if you use a shared version of the library, possibly take further steps: see the documentation of your system for more info on this subject (the Program Library HOWTO is especially valuable for GNU/Linux users π
).
π IMPLEMENTING MEMORY-GUARDED COMPUTATIONS π
One of the interesting features of the Parma Polyhedra Library is the possibility to implement memory-guarded computations. the idea is that you can limit the amount of virtual memory available to the process, launch a PPL computation, and be ready to catch an std::bad_alloc exception π
Since the library is exception-safe, you can take the appropriate corrective measures (e.g., simplify the polyhedra and/or select less precise though less complex algorithms), and restart the computation π
In order to do that, you should define alternative memory allocation functions for GMP that throw std::bad_alloc upon memory exhaustion. for instance:
#include <new>
#include <cstdlib>
extern "C" void*
cxx_malloc(size_t size) {
void* p = malloc(size);
if (p != 0 || size == 0)
return p;
throw std::bad_alloc();
}
extern "C" void*
cxx_realloc(void* q, size_t, size_t new_size) {
void* p = realloc(q, new_size);
if (p != 0 || new_size == 0)
return p;
throw std::bad_alloc();
}
extern "C" void
cxx_free(void* p, size_t) {
free(p);
}
Then you must install these functions and this can be done in two different ways:
- If your C++ compiler supports
__attribute__ ((weak))and you do not have any other special needs, then you can simply link to your application a C functionppl_set_GMP_memory_allocation_functions(void)such as:
extern "C" void
ppl_set_GMP_memory_allocation_functions(void) {
mp_set_memory_functions(cxx_malloc, cxx_realloc, cxx_free);
}
This is all that you have to do, whether or not you use the automatic initialization feature of the library (see above): in any case the initialization procedure will automatically call ppl_set_GMP_memory_allocation_functions(void) β¨
- If your C++ compiler does not support
__attribute__ ((weak))then you cannot use the automatic initialization feature of the library (see above) and should write a main program of the form:
int main() {
// The ordering of the following function calls is important.
mp_set_memory_functions(cxx_malloc, cxx_realloc, cxx_free);
Parma_Polyhedra_Library::initialize();
...
π§ USING NATIVE FLOATING POINT NUMBERS π§
At initialization time, the Parma Polyhedra Library sets the FPU rounding mode in a way that allows its floating-point-based computations to be conservative (i.e., possibly approximated but correct) and reasonably efficient. no cap π
In case your application itself uses native floating point numbers and relies on a particular rounding mode (if you are in doubt, assume that it does rely on round-to-nearest to be in effect), you should use the function
void Parma_Polyhedra_Library::restore_pre_PPL_rounding()
after the PPL initialization and before using native floating point numbers in the application π«Ά
If your application does not use any floating-point-based PPL abstraction, no further measure should be taken. otherwise, it is imperative to call the function
void Parma_Polyhedra_Library::set_rounding_for_PPL()
before invoking any PPL interface related to such abstractions π
π SEE ALSO π
Roberto Bagnara, Patricia M. Hill, and Enea Zaffanella. The Parma Polyhedra Library User's Manual (version 1.2), available (in several formats) at http://bugseng.com/products/ppl/ π
David A. Wheeler. Program Library HOWTO, available (in several formats) at http://www.dwheeler.com/program-library/ π
π AVAILABILITY π
The latest version of the Parma Polyhedra Library and all the documentation is available at http://bugseng.com/products/ppl/ π
π AUTHOR π
See the file CREDITS in the source distribution or use the command ppl-config --credits for a list of contributors π«Ά
π REPORTING BUGS π
Report bugs to <ppl-devel@cs.unipr.it> π¬
π COPYRIGHT AND NO WARRANTY π
Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
This is free software; see the file COPYING in the source distribution or use the command ppl-config --copying to obtain the copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. like, none bestie, zero, nada π
and that's the whole page!! this was PPL 1.2, dated February 2016, serving libppl(3) realness π mwah, go write some polyhedra code, you got this πβ¨
π¦ where this page comes from
- arch rolling: ppl 1.2-7 Β· GPL-3.0-or-later
- debian bookworm: libppl-dev 1:1.2-8.1+b1
- debian trixie: libppl-dev 1:1.2-8.1+b3
- epel 9: ppl-devel 1.2-24.el9 Β· GPLv3+
- fedora 43: ppl-devel 1.2-37.fc43 Β· GPL-3.0-or-later
- fedora 44: ppl-devel 1.2-39.fc44 Β· GPL-3.0-or-later
- nixos 26.05: ppl 1.2
- nixpkgs unstable: ppl 1.2
- opensuse-leap 16.0: ppl-devel 1.2-bp160.1.14 Β· GPL-3.0-or-later
- opensuse-leap 16.0: ppl-devel 1.2-bp160.1.14 Β· GPL-3.0-or-later
- opensuse-leap 16.0: ppl-devel 1.2-bp160.1.14 Β· GPL-3.0-or-later
- opensuse-leap 16.0: ppl-devel 1.2-bp160.1.14 Β· GPL-3.0-or-later
- ubuntu jammy: libppl-dev 1:1.2-8.1build1
- ubuntu noble: libppl-dev 1:1.2-8.1build5
- ubuntu resolute: libppl-dev 1:1.2-8.1+build6
- ubuntu stonking: libppl-dev 1:1.2-8.1+build6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms