Prev: Dhrystone
Next: Learning Ada
From: Dmitry A. Kazakov on
On Sun, 25 Jul 2010 12:28:44 -0700 (PDT), Ada novice wrote:

> Yes you're right. I only thought that imsl.ad(b,s) should be compiled
> first.

It will as needed, i.e. when used in a project that produces something.

At some point later when you decide to turn your bindings into a library
(object/static and/or shared), you could change the IMSL project so that it
would produce that library. Then it will become compilable.

> Thank you very much all of you especially Dmitry and Simon for your
> very kind help. I'll need to study the code that you provided.

You are welcome.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Simon Wright on
Ada novice <posts(a)gmx.us> writes:

> Many thanks for all your inputs. I'll give you an example. Say we want
> to compute the eigenvalues of this 3 X 3 matrix. The code in C (using
> the IMSL library) is as follows:
[...]
> What would the best way to interface this with Ada? The elements of my
> matrix will be formed in Ada, then the matrix will be passed to C to
> calculate the eigenvalues and then the latter passed back to Ada. The
> size of my matrix will be fixed say 3 x 3. As a novice in Ada, I would
> like to learn good programming practice and the best way is to use
> codes and learn from experts here in Ada.

I've encoded a general complex eigenvalues function, interfacing to the
LAPACK procedure zgeev, starting from a demo at
http://www.physics.oregonstate.edu/~rubin/nacphy/lapack/codes/eigen-c.html
& copying bits and pieces from within the GNAT implementation of
Ada.Numerics.Generic_Complex_Arrays.

Find it at http://public.me.com/simon.j.wright (folder numerics).

NB1 LAPACK is a Fortran code, hence the need to transpose the matrix.

NB2 the compilation gives warnings ..

$ gnatmake test_zgeev.adb
gcc -c test_zgeev.adb
test_zgeev.adb:9:06: warning: "Interfaces.Fortran.BLAS" is an internal GNAT unit
test_zgeev.adb:9:06: warning: use of this unit is non-portable and version-dependent
test_zgeev.adb:10:06: warning: "Interfaces.Fortran.LAPACK" is an internal GNAT unit
test_zgeev.adb:10:06: warning: use of this unit is non-portable and version-dependent
gnatbind -x test_zgeev.ali
gnatlink test_zgeev.ali
$

However, (a) one could always write ones own versions, (b) the results
are the same with GNAT GPL 2010 and GCC 4.5.0, (c) the output looks good
(from your inputs) ..

$ ./test_zgeev
2.00000000000000E+00 4.00000000000000E+00
2.00000000000000E+00 -4.00000000000000E+00
9.99999999999996E-01 2.07319734774360E-16

I get the strong impression that to know what the arguments of the BLAS
& LAPACK subprograms are you have to buy the book or read the code!


This all worked without any need for additional link-time arguments on
Mac OS X, but YMMV on Windows. If not, I *think* that if you with
Ada.Numerics.Long_Complex_Arrays (no need to use anything from it) that
would be enough to bring in the necessary libraries.
From: John B. Matthews on
In article <m2iq43rvv1.fsf(a)pushface.org>,
Simon Wright <simon(a)pushface.org> wrote:

> I've encoded a general complex eigenvalues function, interfacing to the
> LAPACK procedure zgeev, starting from a demo at
> http://www.physics.oregonstate.edu/~rubin/nacphy/lapack/codes/eigen-c.html
> & copying bits and pieces from within the GNAT implementation of
> Ada.Numerics.Generic_Complex_Arrays.
>
> Find it at http://public.me.com/simon.j.wright (folder numerics).

Exemplary!

> NB1 LAPACK is a Fortran code, hence the need to transpose the matrix.
>
> NB2 the compilation gives warnings ..
>
> $ gnatmake test_zgeev.adb
> gcc -c test_zgeev.adb
> test_zgeev.adb:9:06: warning: "Interfaces.Fortran.BLAS" is an internal GNAT unit
> test_zgeev.adb:9:06: warning: use of this unit is non-portable and version-dependent
> test_zgeev.adb:10:06: warning: "Interfaces.Fortran.LAPACK" is an internal GNAT unit
> test_zgeev.adb:10:06: warning: use of this unit is non-portable and version-dependent

For convenience, the warnings may be suppressed:

pragma Warnings("I");

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Ada novice on
On Jul 25, 10:04 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de>
wrote:

> At some point later when you decide to turn your bindings into a library
> (object/static and/or shared), you could change the IMSL project so that it
> would produce that library. Then it will become compilable.
>

Would you be kind enough to elaborate on your above comments a little
more?

Thanks
YC
From: Ada novice on
On Jul 26, 1:21 am, Simon Wright <si...(a)pushface.org> wrote:

> I've encoded a general complex eigenvalues function, interfacing to the
> LAPACK procedure zgeev, starting from a demo athttp://www.physics.oregonstate.edu/~rubin/nacphy/lapack/codes/eigen-c...
> & copying bits and pieces from within the GNAT implementation of
> Ada.Numerics.Generic_Complex_Arrays.
>
> Find it athttp://public.me.com/simon.j.wright(folder numerics).

Thank you very much for your commendable efforts. This is a very good
example to demonstrate how Ada can be binded with LAPACK.


>(b) the results
> are the same with GNAT GPL 2010 and GCC 4.5.0, (c) the output looks good
> (from your inputs) ..
>
>    $ ./test_zgeev
>     2.00000000000000E+00  4.00000000000000E+00
>     2.00000000000000E+00 -4.00000000000000E+00
>     9.99999999999996E-01  2.07319734774360E-16


I have Win XP and gcc (GCC) 4.3.6 20100603 for GNAT GPL 2010
(20100603). I get slightly different output:

1.99999999999999E+00 3.99999999999999E+00
2.00000000000000E+00 -4.00000000000000E+00
1.00000000000000E+00 -3.45920620709768E-16

Your GCC version is more recent than mine. Maybe this is causing the
discrepancies or maybe it's because of your different OS. Did you
install your GCC separately? I got mine bundled with the GNAT GPL
2010.

>I get the strong impression that to know what the arguments of the BLAS
>& LAPACK subprograms are you have to buy the book or read the code!

On a side note, there's this book:

Handbook for Automatic Computation: Volume 2: Linear Algebra
(Grundlehren der mathematischen Wissenschaften) by John H. Wilkinson,
C. Reinsch, Alston S. Householder, and Friedrich L. B

which has lots of test matrix cases to check whether algorithms are
performing correctly.


> This all worked without any need for additional link-time arguments on
> Mac OS X, but YMMV on Windows. If not, I *think* that if you with
> Ada.Numerics.Long_Complex_Arrays (no need to use anything from it) that
> would be enough to bring in the necessary libraries.

It works fine on Windows too with anything to add. And I get the same
compilation warnings.


YC
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Prev: Dhrystone
Next: Learning Ada