comp.lang.ada
 help / color / mirror / Atom feed
From: "Nasser M. Abbasi" <nma@12000.org>
Subject: Re: my cheat sheet note on installation of the Ada binding to Blas and Lapack
Date: Sat, 07 Jul 2012 19:50:03 -0500
Date: 2012-07-07T19:50:03-05:00	[thread overview]
Message-ID: <jtalfv$63l$1@speranza.aioe.org> (raw)
In-Reply-To: jt6b13$plp$1@speranza.aioe.org

On 7/6/2012 4:26 AM, Nasser M. Abbasi wrote:
> fyi;
>
> I wrote a small note on the installation of the Ada binding
> to Blas and Lapack, in case they might be useful for someone.
>
> Added the note to my Ada web page below
>
> http://12000.org/my_notes/ada/index.htm
>

fyi;

This is my first program using the lapack binding!

I tried to make it as simple as I can. It solves
A x = b.   (one can do this also using Ada own solve() function
ofcourse, but with Lapack, one can do much more).

I show the Ada code, and the matlab equivalent to show they
give the same result. I'll update my cheat sheet above with
these examples later on.

----------------------------------
with Ada.Text_IO;  use  Ada.Text_IO;

with Interfaces.Fortran; use Interfaces.Fortran;
with labase; -- from LAPACK binding
with ladrv;  -- from LAPACK binding

procedure mySolve is
	
   A:   labase.Fortran_Real_Matrix ( 1..3, 1..3 );
   b:   labase.Fortran_Real_Matrix ( 1..3, 1..1  );	
   package Real_IO is new Ada.Text_IO.Float_IO( Real );
   INFO : Fortran_Integer;
   IPIV : labase.Fortran_Integer_Vector ( 1..A'Last(2)); 	

   Begin -- solve A x=b
           
	A := ((2.0,  3.0,  1.0),
               (2.0,  1.0,  1.0),
               (4.0, -1.0,  6.0));

	b := ((9.0,others=>0.0),
               (2.0,others=>0.0),
               (-2.0,others=>0.0)
               );
     
         ladrv.SGESV ( N   => A'Last(2),
                      NRHS => b'Last(2),
                      A    => A,
                      LDA  => A'Last(1),
                      IPIV => IPIV,
                      B    => b,
                      LDB  => b'Last(1),
                      INFO => INFO);

   	if ( not(INFO = 0) ) then
	   raise PROGRAM_ERROR;
	end if;

         for x of b loop  -- print solution
             real_io.PUT ( x ); new_line;
         end loop;
                     
end mySolve;
--------------------------
output is

>gnatmake -gnat2012 -I../ada  mysolve.adb
gcc -c -gnat2012 -I../ada mysolve.adb
gnatbind -I../ada -x mysolve.ali
gnatlink mysolve.ali

>./mysolve
-1.31250E+00
  3.50000E+00
  1.12500E+00
>


Matlab
--------
EDU>> A=[2 3 1;2 1 1;4 -1 6];
EDU>> b=[9;2;-2];
EDU>> A\b   -- This is Matlab API to SGESV

ans =

   -1.312500000000000
    3.500000000000000
    1.125000000000000

------------

So we see that Matlab is correct, as confirmed by Ada :)

--Nasser






  parent reply	other threads:[~2012-07-08  0:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06  9:26 my cheat sheet note on installation of the Ada binding to Blas and Lapack Nasser M. Abbasi
2012-07-06 11:29 ` shai.lesh
2012-07-06 19:55   ` Simon Wright
2012-07-08  0:50 ` Nasser M. Abbasi [this message]
2012-07-08  7:06   ` Simon Wright
2012-07-10  5:14   ` Ada novice
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox