- PDF (letter size)
- PDF (legal size)
my Ada corner
August 28, 2015 Compiled on May 23, 2020 at 8:57am
1 Original Ada web site and Ada links
My original Ada web site with links is here
2 how to call Lapack and Blas directly from Ada
Important note added June 2013:
This page is obsolete now, left here for archive and information only.
The Ada Lapack code is now housed at http://sourceforge.net/projects/ada-lapack/
I downloaded the original BLAS Ada binding written by Duncan Sands
and the LAPACK Ada binding written by Wasu Chaopanon from
And made some minor improvments to the bindings.
This page describes the minor changes made and instructions how to use these bindings from Ada
in order call LAPACK and BLAS Fortran functions.
A new tar ﬁle for LAPACK and for BLAS with all the changes can be downloaded from the link
The changes made to LAPACK binding involve streamlining the source tree structure, writing
new Makeﬁles, simplify the binding to use one package called lapack and also adding the
documentation shown below.
Changes for the BLAS binding were minimal. It involved changes to the source tree structure and
writing Makeﬁles and adding the documentation shown below.
2.2 Review of the LAPACK and BLAS Ada binding
The Ada binding to LAPACK and BLAS is an Ada package which allows one to interface to the
native lapack and blas libraries.
The native lapack and blas libraries need to be ﬁrst installed on the system (on Linux, these
libraries will normally be found in /usr/lib/liblapack.so and /usr/lib/libblas.so
To use LAPACK from Ada, one needs to install both the native LAPACK and BLAS libraries
since LAPACK depends on BLAS.
The Ada binding is a thin binding, meaning there is 1-1 mapping between the call to the Ada
routine and the corresponding Fortran routine using the same function name in the Fortran
The following diagram illustrates the use of the LAPACK binding with the needed gnatmake
command to compile and link the client Ada program.
Figure 1:high level1 lapack
And a similar diagram for the BLAS binding interface
Figure 2:high level1 blas
The source tree structure for LAPACK is described in this diagram
Figure 3:tree structure for lapack
The full content of the LAPACK tree is listed here lapack_tree_listing.txt
The source tree structure for the BLAS binding is described in this diagram
Figure 4:tree structure for blas
2.3 Installation instruction
These instructions explain how to use the Ada LAPACK and BLAS binding in the updated
snapshot tar ﬁle.
install native lapack 77 and blas libraries on your system. These will normally be
installed in /usr/lib/.
download the updated Ada binding in the zip ﬁles given in the links at the bottom
of this page. They are ada_lapack_073012.zip and ada_blas_073012.zip
Extract the zip ﬁles to some location. This will create 2 source trees as shown in the
At the top of the each source tree, there is a ﬁle called common.mk where a Makeﬁle
variable is set to point to the directory that contains the native LAPACK and BLAS
libraries. This is currently deﬁned to point to /usr/lib. Edit this line to change this
location only if the location is diﬀerent in your system.
To build the binding, just type make from the top of each tree. Make will build the
whole tree, including the bindings packages and the test programs.
To run the test program, type make testing from the top of tree for LAPACK and
Examples of clients using the bindings are found in the tests/ directory of each tree.
The binding is in the binding/ directory in each tree. This is the directory that you
need to set the -I option to point to when using gnatmake as shown in the diagrams
The following is a simple example of using the Ada LAPACK binding to solve \(Ax=b\)
mysolve.adb.txt which can also be found in the ada_lapack/tests/pilot/ directory
That is all! Have fun using Ada with LAPACK and BLAS.
2.4 source code
3 How to compile GTK Ada program
$ gnatmake -I../pragmarc mine_detector.adb `gtkada-config`
gcc-4.4 -c -I../pragmarc -I/usr/share/ada/adainclude/gtkada2 mine_detector.adb
gcc-4.4 -c -I../pragmarc -I/usr/share/ada/adainclude/gtkada2 user_if.adb
gcc-4.4 -c -I../pragmarc -I/usr/share/ada/adainclude/gtkada2 field.ads
gcc-4.4 -c -I../pragmarc -I/usr/share/ada/adainclude/gtkada2 field-operations.adb
gnatbind -I../pragmarc -aI/usr/share/ada/adainclude/gtkada2 -aO/usr/lib/ada/adalib/gtkada2 -x mine_detector.ali
gnatlink mine_detector.ali -L/usr/lib -lgtkada2 -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0
-lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lm -lcairo -lpango-1.0 -lfreetype
-lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0
4 How to make Ada generate an exception on some ﬂoating points operations?
On Thu, 20 Nov 2008 12:09:41 +0100, Markus Schoepflin wrote:
> is it possible to influence the behaviour of GNAT regarding the handling of
> NANs? (Most importantly in the special case of division by zero.)
> We need to get exceptions whenever a NAN is generated, is this possible
> somehow? (For example by setting Machine_Overflow to True and recompiling
> the compiler itself.)
You can scrap IEEE stuff in favor of Ada semantics by declaring your own
floating-point [sub]type with a range specified. The compiler will be
forced to check values:
type Safe_Float is digits 6 range -10.0E10..+10.0E10;
subtype Safe_Float is Float range Float'Range;
X : Safe_Float := 1.0;
Y : Safe_Float := 0.0;
Y := X / Y;
when Error : others => -- Should print "range check failed"
Put_Line (Exception_Message (Error));
Dmitry A. Kazakov
5 How to use Ada 2005 OO?
6 how to make simple Ada program
If gnat is not installed, install it (on linux) using something similar to
sudo apt-get install gnat-4.6
write the following code in ﬁle called hello_world.adb
gnatmake hello_world.adb gcc-4.6 -c hello_world.adb
gnatbind -x hello_world.ali
Run it using ./hello_world
7 Ada implementation of decimal representation of exp()
This is an Ada implementation of decimal representation of \(e\) based on SPIGOT algorithm for \(\pi \) by
S. Rabinowitz & S. Wagon, The American Mathematical Monthly, March 1995.
This source ﬁle is here
8 Ada implementation of getopt()
This package is an Ada implementation of getopt() as speciﬁed by the document ”The Single
UNIX Speciﬁcation, Version 2”, Copyright 1997 The Open Group
This source ﬁle is here
This is a test program of the above package. source code
9 GNAT 2012 installation log ﬁle