From: Francogrex
Subject: ECL ignores declarations?
Date: 
Message-ID: <be70b253-e834-416c-a446-a45356c64362@b15g2000yqd.googlegroups.com>
Hi, can you tell me what the code below gives on your PC and
implementation? The reason I ask, is because ECL doesn't seem to care
whether the declarations are made or not, the time it takes to get
thru the calculation is the same (around 15 sec on my PC). Thanks
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar a (make-array '(10000 10000)
		    :element-type ' single-float
		    :initial-element 1.0s0))

(defun sum-elts (a)
  (declare (type (simple-array single-float (10000 10000))
		 a))
  (let ((sum 0.0s0))
    (declare (type single-float sum))
    (dotimes (r 10000)
      (dotimes (c 10000)
	(incf sum (aref a r c))))
    sum))

(compile 'sum-elts)

(time (sum-elts a))

(defun sum-elts2 (a)
  (let ((sum 0.0s0))
    (dotimes (r 10000)
      (dotimes (c 10000)
	(incf sum (aref a r c))))
    sum))

(compile 'sum-elts2)

(time (sum-elts2 a))

From: Rainer Joswig
Subject: Re: ECL ignores declarations?
Date: 
Message-ID: <15a7eab7-6ec7-47a7-8db6-bc8d796c2b6e@x5g2000yqk.googlegroups.com>
On 7 Jul., 18:40, Francogrex <······@grex.org> wrote:
> Hi, can you tell me what the code below gives on your PC and
> implementation? The reason I ask, is because ECL doesn't seem to care
> whether the declarations are made or not, the time it takes to get
> thru the calculation is the same (around 15 sec on my PC). Thanks
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;
> (defvar a (make-array '(10000 10000)
>                     :element-type ' single-float
>                     :initial-element 1.0s0))
>
> (defun sum-elts (a)
>   (declare (type (simple-array single-float (10000 10000))
>                  a))
>   (let ((sum 0.0s0))
>     (declare (type single-float sum))
>     (dotimes (r 10000)
>       (dotimes (c 10000)
>         (incf sum (aref a r c))))
>     sum))
>
> (compile 'sum-elts)
>
> (time (sum-elts a))
>
> (defun sum-elts2 (a)
>   (let ((sum 0.0s0))
>     (dotimes (r 10000)
>       (dotimes (c 10000)
>         (incf sum (aref a r c))))
>     sum))
>
> (compile 'sum-elts2)
>
> (time (sum-elts2 a))


What are the optimization settings for speed, safety, debug, etc.?
From: fortunatus
Subject: Re: ECL ignores declarations?
Date: 
Message-ID: <39806740-b7d3-4a92-a512-d84e19b00e16@o18g2000pra.googlegroups.com>
On Jul 7, 12:40 pm, Francogrex <······@grex.org> wrote:

> Hi, can you tell me what the code below gives on your PC and
> implementation? The reason I ask, is because ECL doesn't seem to care
> whether the declarations are made or not, the time it takes to get
> thru the calculation is the same (around 15 sec on my PC). Thanks

As already alluded, you need to make sure OPTIMIZE is used to turn off
type checking, etc, or else the declarations can make more work for
the code (in type "safety" checking), rather than reducing work:

(declare (optimize (speed 3) (safety 0)))


I recommend reading the following page - several topics are covered,
but there is a nice optimization example in the middle:

http://gigamonkeys.com/book/conclusion-whats-next.html
From: Francogrex
Subject: Re: ECL ignores declarations?
Date: 
Message-ID: <5c38cbc7-e086-4ec6-927c-0299da93abf4@y7g2000yqa.googlegroups.com>
On 7 jul, 23:11, fortunatus <··············@excite.com> wrote:
> As already alluded, you need to make sure OPTIMIZE is used to turn offtypechecking, etc, or else the declarations can make more work for
> the code (intype"safety" checking), rather than reducing work:
>
> (declare (optimize (speed 3) (safety 0)))

No even that does not help speeding it up. There must be a deficiency
at the level of the implementation possibly.
From: =?UTF-8?B?TWFya28gS29jacSH?=
Subject: Re: ECL ignores declarations?
Date: 
Message-ID: <0366e88d-ff9b-451c-ab0c-17de790641fb@c1g2000yqi.googlegroups.com>
On 8 јул, 08:57, Francogrex <······@grex.org> wrote:
> On 7 jul, 23:11, fortunatus <··············@excite.com> wrote:
>
> > As already alluded, you need to make sure OPTIMIZE is used to turn offtypechecking, etc, or else the declarations can make more work for
> > the code (intype"safety" checking), rather than reducing work:
>
> > (declare (optimize (speed 3) (safety 0)))
>
> No even that does not help speeding it up. There must be a deficiency
> at the level of the implementation possibly.

Note that declarations don't help much in this case since the problem
is memory bound, not cpu bound. When you run it you can see that cpu
load is at 5-6% max. That's why you don't see speed difference.

If you use smaller matrix, eg 1000x1000, you could measure speed
improvements of 40% by adding type declarations.

Also, use ecl-9.7.1 which has much better array handling than previous
release.

Regards,
Marko
From: Juanjo
Subject: Re: ECL ignores declarations?
Date: 
Message-ID: <5726817e-ff72-41fb-bf8b-590a36107762@a7g2000yqk.googlegroups.com>
On Jul 8, 11:46 am, Marko Kocić <···········@gmail.com> wrote:
> Also, use ecl-9.7.1 which has much better array handling than previous
> release.

Upcoming 9.7.1 or 9.7.1rc ;-) Available in git and CVS repositories,
as usual
http://ecls.sf.net/download.html

Juanjo
From: Pascal J. Bourguignon
Subject: Re: ECL ignores declarations?
Date: 
Message-ID: <87tz1ol93w.fsf@galatea.local>
Francogrex <······@grex.org> writes:

> Hi, can you tell me what the code below gives on your PC and
> implementation? The reason I ask, is because ECL doesn't seem to care
> whether the declarations are made or not, the time it takes to get
> thru the calculation is the same (around 15 sec on my PC). Thanks
>   (declare (type (simple-array single-float (10000 10000))
>     (declare (type single-float sum))

Implementations are allowed to ignore type declarations.


-- 
__Pascal Bourguignon__