Le vendredi 02 mars 2007 à 13:19 +0000, Xavier Calbet a écrit :
> Hi Greg,
>
> One more question. I am now trying to implement the
> madelbrot program to use inplace. Unfortunately I cannot
> find the way to do an inplace with two (or more ) variables in the assigment.
> I have tried the solution below, but I get the same speeds when
> I comment out the inplace lines.
> How do you inplace an assigment with more than on variable?
> i.e. $a=$b+$a
$a->inplace() + $b;
or, as said by Christopher Marshall (the call to inplace is avoided),
$a += $b; # The code is in PDL::Core, I think, if you want to look at it
> or $a=$b+$c ?
Don't know what you mean here. Which variable has its inplace flag set
here ? Do you mean $a = ( $b += $c ) ($a is not necessary here) ? If you
already have the array $a you can use $b->plus($c,$a,0). See the manual
page of PDL::Ops.
> Many thanks again,
>
> Xavier
>
> **************************************************************+
> $npts=2000;
> $niter=10;
> $Re=zeroes(double,$npts)->xlinvals(-1.5,0.5);
> $Im=zeroes(double,$npts)->dummy->ylinvals(-1,1);
> @dm=dims($Im);
> print "dims Im @dm\n";
> @dm=dims($Re);
> print "dims Re @dm\n";
> $t=$Re->copy;
> $u=$Im->copy;
>
> print "Calculating Mandel\n";
> $q=$Re*$Re-$Im*$Im+$t;
> $h=2*$Re*$Im+$u;
> $Re=$q->clip(-5,5)->copy;
> $Im=$h->clip(-5,5)->copy;
> for($j=0;$j<$niter-1;$j++){
> $q->inplace;
> $q=$Re*$Re-$Im*$Im+$t;
> $h->inplace;
> $h=2*$Re*$Im+$u;
> $Re->inplace;
> $Re=$q->clip(-5,5);
> $Im->inplace;
> $Im=$h->clip(-5,5);
> }
No, you're not using 'inplace' correctly. When you call inplace on a
piddle, that sets a flag such that the next operation (not the
assignment operation, this is meaningless, no ?) will be done in place
so for example you should use :
$h->inplace->clip(-5,5);
so the "clip" happens "inplace", the array $h is modified without
creating a new array.
You can use $Im = $h->inplace->clip(-5,5), since $h is a ref this has
little cost and $h and $Im will refer to the same object.
For other operation such than addition, multiplication etc (overloadable
operators), as said by Christopher Marshall, you can use:
$Re *= $Re;
Just an example (not meant to be used):
# $h=2*$Re*$Im+$u;
# $Im=$h->clip(-5,5);
$Re *= 2; # better than $Re->inplace() * 2
$Re *= $Im;
$Re += $u;
$Im = $Re->inplace->clip(-5,5)
I have not used Perl since some times now and have completely forgotten
the binop= syntax :)
Greg
>
>
> On 3/2/07, Xavier Calbet <[EMAIL PROTECTED]> wrote:
> > Hi Greg,
> >
> > You are absolutely right I made a mistake adding the wrong numbers.
> > The results for my previous test 3 is really 32 sec NOT 55 sec
> > like I wrote before. Sys time is nearly zero for this
> > test which is what I was expecting.
> > For test 2 I get roughly twice the time of test 1.
> >
> > In any case, many thanks for the explanation,
> >
> > Xavier
> >
> > On 3/2/07, Vanuxem Grégory <[EMAIL PROTECTED]> wrote:
> > > Le vendredi 02 mars 2007 à 09:01 +0000, Xavier Calbet a écrit :
> > > > Hello,
> > > >
> > > > I am getting confused now with inplace. The detailed code and times
> > > > are shown below.
> > > > I am running three tests trying to implement inplace operations
> > > > to make the code faster. The summary is:
> > > >
> > > > Test # command time
> > > > 1: $Re=$Re+1000.; 58 sec
> > > > 2: $Re.=$Re+1000.; 109 sec
> > > > 3: $Re->inplace;$Re+1000.; 55 sec
> > >
> > > #1: a new piddle of ~30Mb is created, threading is used (threading along
> > > dimension 0 and 1 of $Re). Affectation of the new result of each
> > > addition to the elements of this new piddle.
> > >
> > > #2: same thing _+_ affectation of the _new_ 2000x2000 piddle (after
> > > calculation) to $Re, each element at a time.
> > > (I find your timing surprising)
> > >
> > > #3: threading as in #1 and #2 but no new piddle, results of additions
> > > affected to elements of $Re "inplace".
> > > (in C : Re[x,y] = Re[x,y]*1000, approximatively, since piddle are
> > > represented by a one dimensional array in a more complex structure).
> > >
> > >
> > > with 2000x2000 piddle of double (from your code below)
> > > ----------------------------------
> > > ---- #1
> > > time perl pdl.pl
> > >
> > > real 0m48.948s
> > > user 0m25.947s
> > > sys 0m22.981s
> > >
> > > ---- #3
> > > time perl pdl_i.pl
> > >
> > > real 0m23.460s
> > > user 0m23.032s
> > > sys 0m0.350s
> > > ----------------------------------
> > >
> > > 23 secondes against 48.
> > >
> > > Apparently you made a mistake, your timings above do not reflect the
> > > ones below.
> > >
> > > Greg
> > >
> > >
> > > >
> > > > I believe test 3 is doing things really inplace, but its time is
> > > > almost the
> > > > same as test 1, which is the "easy" way. Does this mean
> > > > that test 1 is really done inplace? Or maybe test 3 is not done inplace?
> > > >
> > > > I thought the .= operator performed operations inplace, and I would
> > > > have
> > > > thought test 2 was also doing things inplace like test 3. Obviously it
> > > > is
> > > > not. In fact it is taking twice the time to run probably meaning it is
> > > > doing the calculations twice. What am I missing here?
> > > >
> > > > Many thanks again,
> > > >
> > > > Xavier
> > > >
> > > >
> > > > *******************************************
> > > > Test 1
> > > > -----------------------------------------
> > > > $npts=2000;
> > > > $niter=1000;
> > > > $Re=zeroes(double,$npts,$npts)->xlinvals(-1.5,0.5);
> > > >
> > > > for($j=0;$j<$niter;$j++){
> > > > $Re=$Re+1000.;
> > > > }
> > > > ------------------------------------------------
> > > > time output:
> > > >
> > > > real 1m0.727s
> > > > user 0m22.794s
> > > > sys 0m36.667s
> > > >
> > > > ******************************************************
> > > > Test 2:
> > > > ---------------------------------------------------
> > > > $npts=2000;
> > > > $niter=1000;
> > > > $Re=zeroes(double,$npts,$npts)->xlinvals(-1.5,0.5);
> > > >
> > > > for($j=0;$j<$niter;$j++){
> > > > $Re.=$Re+1000.;
> > > > }
> > > > ------------------------------------------------------
> > > > time output:
> > > >
> > > > real 1m53.829s
> > > > user 1m11.915s
> > > > sys 0m37.040s
> > > >
> > > > *******************************************************
> > > > Test 3
> > > > -------------------------------------------------------
> > > > $npts=2000;
> > > > $niter=1000;
> > > > $Re=zeroes(double,$npts,$npts)->xlinvals(-1.5,0.5);
> > > >
> > > > for($j=0;$j<$niter;$j++){
> > > > $Re->inplace;
> > > > $Re+1000.;
> > > > }
> > > > --------------------------------------------------------
> > > > time output:
> > > >
> > > > real 0m33.181s
> > > > user 0m32.446s
> > > > sys 0m0.190s
> > >
> > >
> > >
> > >
> > >
> > >
> > > ___________________________________________________________________________
> > > Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son
> > > interface révolutionnaire.
> > > http://fr.mail.yahoo.com
> > >
> > >
> >
___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son
interface révolutionnaire.
http://fr.mail.yahoo.com
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl