comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: GNAT vs Matlab - operation on   multidimensional complex matrices
Date: Tue, 31 Mar 2020 10:25:19 -0700 (PDT)
Date: 2020-03-31T10:25:19-07:00	[thread overview]
Message-ID: <cc95457e-b41c-422f-8972-a108af2204fa@googlegroups.com> (raw)
In-Reply-To: <6c2c0e35-af07-4169-8be5-464ec7fd0fd5@googlegroups.com>

On Monday, March 23, 2020 at 5:16:20 PM UTC-6, darek wrote:
> Hi Everyone, 
>  I am working on radar signal processing algorithms that use multidimensional complex arrays. 

Ok then; the following should have convention Fortran IIRC:

type tCubeReal is array (1..NumChannels, 1..NumAngles, 1..NumRanges) of mReal
  with Convention => Fortran;

That doesn't matter much, for a speed-test, but given that you mention RADAR data it's probably best to mention it now, before you frustrate yourself by accidentally mixing up column- and row-major formats.

> 
> To my surprise, the performance of some Matlab functions is much better than compiled Ada code. 
> 
>    procedure SpeedSumRealCube (NumIteration : Integer; Mtx : in  tCubeReal;  S: out mReal) is

Don't read from S, it's an OUT parameter, and it's best to treat it that way.
(I'm not sure that it would get in the way of optimization, but could.)

>       for k in 1..NumIteration loop
>          for m  in Mtx'Range(1) loop
>             for n in   Mtx'Range(2) loop
>                for p in   Mtx'Range(3) loop
>                   S := S + Mtx(m, n, p);
>                end loop;
>             end loop;
>          end loop;
>       end loop;

The above could be replaced, in Ada2012 with:

Function Summation( Input : in  tCubeReal ) return Complex is
Begin
  Return Result : Complex := (0.0 + i*0.0) do
    For Element of Input loop
      Result:= Result + Element;
    End loop;
  End return;
End Summation;

If you turn it into a generic, you could use it for both Complex and mReal; plus it more accurately mirrors your Matlab code.
-------------------------------------------------------------------------

Is there a reason for the access-types?
If not, I would recommend getting rid of them.


>
> 1. Compiled with:  gcc version 9.2.0 (tdm64-1) ( and gnat community edition 2019), with the -O2 optimisation level. 
> 2. CPU: AMD64 Family 23 Model 24 Stepping 1  CPU0      2300           AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx
> 3. Win10 64bit 
> 
> 
> The results of the program execution:
> 
> Computation time: 0.616710300
> Computation time per iteration: 6.16710300000000E-04
> Sum is: 7.68000000000000E+08
> Complex cube
> Complex type size is: 128
> 
> Computation time: 3.707091000
> Computation time per iteration: 3.70709100000000E-03
> Sum is:( 7.68000000000000E+08, 7.68000000000000E+08)
> 
> 
> The executable produced by the gcc provide with the gnat community edition gave very similar results.
> 
> More interesting part - the Matlab code.
> The results of the program execution:
> 
> TExe:0.260718, sum real=768000000.000000
> TExe:0.789778, sum complex= <768000000.000000,768000000.000000> 
> Complex operations are 3.029242 times slower
> 
> 
> What is wrong with my code? Is it the Ada compiler doing bad job here?
> It seems that Matlab is performing really well here ...

IIRC Matlab has a *LOT* of optimization for Complex numbers/operations, but you're right in that these are surprising.

  parent reply	other threads:[~2020-03-31 17:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23 23:16 GNAT vs Matlab - operation on multidimensional complex matrices darek
2020-03-24  2:07 ` johnscpg
2020-03-24  6:40 ` J-P. Rosen
2020-03-24  9:37 ` Jeffrey R. Carter
2020-03-24 14:55   ` darek
2020-03-24 15:44 ` johnscpg
2020-03-31 17:25 ` Shark8 [this message]
2020-03-31 19:20   ` Simon Wright
2020-03-31 19:54     ` Shark8
2020-04-29 21:08     ` vincent.diemunsch
2020-04-01 11:01   ` darek
2020-04-01 15:01     ` J-P. Rosen
2020-04-01 16:39       ` darek
2020-04-01 17:15         ` J-P. Rosen
2020-03-31 20:05 ` Shark8
2020-03-31 20:51   ` Jeffrey R. Carter
2020-06-08 17:42 ` Shark8
replies disabled

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