Re: [Pdl-general] How do you create a set of cdouble matrices from (real, imag) values?

2022-07-06 Thread Ed .
For this I would urge the use of “transpose” to be ultra-clear about the 
intention; “mv(0,-1)” would not achieve the desired effect if there were >2 
dimensions!

Eric, great work on getting something working! I’d recommend you put it on CPAN 
(with suitable tests and test data, obviously) as PDL::IO::Touchstone (if that 
last bit is the most meaningful label).

These days in PDL we refer to “broadcasting” and “pthreading” (because the old 
terminology of “threading” was ambiguous and confusing). Luis’s steer to read 
PDL::ParallelCPU is exactly right; my hypersummary is that for things like 
multiplication (which are inherently of scalars), any higher-dimension thing 
than the inherent dimensions of the operation (even multiplying of a 
multi-element vector) will automatically do “broadcasting”. The only limitation 
is that POSIX threading (aka “pthreading”) will only take place with ndarrays 
with >1e6 elements. That is configurable; see the document for more.

Best regards,
Ed

From: Luis Mochán
Sent: 06 July 2022 13:43
To: Eric Wheeler; Luis 
Mochan
Cc: pdl-general@lists.sourceforge.net
Subject: Re: [Pdl-general] How do you create a set of cdouble matrices from 
(real, imag) values?

Hi Eric

On July 5, 2022 11:19:58 PM CDT, Eric Wheeler  wrote:
>On Fri, 1 Jul 2022, Luis Mochan wrote:
>> ...
>> my $Sm=$S->mv(0,-1) # position, filerow
>>   ->reshape(2,2, $rows); # column, row, filerow
>
>Can you explain what $S->mv(0,-1) does with respect to the -1 value?  The
>pdl docs don't cover what -1 means (or at least its not covered near the
>`mv` function).  Maybe -1 is has a standard meaning in PDL terminology?
>

'mv(0,-1)' moves the first to the last dimension.
In this case there are only two dimensions before the reshape, so you could 
also use 'mv(0,1)',  'transpose', 'xchg(0,1)'.

>I think I have it working for our dataset.  The resulting code is more
>complicated than your beautiful example because I had to handle touchstone
>edge cases (like 2-port is col-major and all others are row-major) as well
>as arbitrary matrix sizes (2x2, 4x4, etc)---but it works!

Great!

>
>Questions:
>
>Does PDL parallelize vector arithmetic somehow or do I need to do
>something further to enable threading?
>
>If so, how does it parallelize the work?
>
>Is there anything to consider when building PDL code so it scales for
>parallelization?
>

I understand that in your case, the range of your row index, the 'broadcast' 
dimension, would be split into subranges and each fed to a different core.
Look at the documentation of PDL::ParallelCPU

Regards,
Luis
--
Enviado desde mi celular; disculpe la horrografía


___
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general

___
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general


Re: [Pdl-general] How do you create a set of cdouble matrices from (real, imag) values?

2022-07-06 Thread Luis Mochán
Hi Eric

On July 5, 2022 11:19:58 PM CDT, Eric Wheeler  wrote:
>On Fri, 1 Jul 2022, Luis Mochan wrote:
>> ...
>> my $Sm=$S->mv(0,-1) # position, filerow
>>   ->reshape(2,2, $rows); # column, row, filerow
>
>Can you explain what $S->mv(0,-1) does with respect to the -1 value?  The 
>pdl docs don't cover what -1 means (or at least its not covered near the 
>`mv` function).  Maybe -1 is has a standard meaning in PDL terminology?
>

'mv(0,-1)' moves the first to the last dimension.
In this case there are only two dimensions before the reshape, so you could 
also use 'mv(0,1)',  'transpose', 'xchg(0,1)'. 

>I think I have it working for our dataset.  The resulting code is more 
>complicated than your beautiful example because I had to handle touchstone 
>edge cases (like 2-port is col-major and all others are row-major) as well 
>as arbitrary matrix sizes (2x2, 4x4, etc)---but it works!

Great!

>
>Questions:
>
>Does PDL parallelize vector arithmetic somehow or do I need to do 
>something further to enable threading?  
>
>If so, how does it parallelize the work? 
>
>Is there anything to consider when building PDL code so it scales for 
>parallelization?
>

I understand that in your case, the range of your row index, the 'broadcast' 
dimension, would be split into subranges and each fed to a different core.
Look at the documentation of PDL::ParallelCPU

Regards,
Luis
-- 
Enviado desde mi celular; disculpe la horrografía


___
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general


Re: [Pdl-general] How do you create a set of cdouble matrices from (real, imag) values?

2022-07-06 Thread Luis Mochán
By the way, I understand that the current PDL uses the total number of
processors as a default for set_autopthread_targ. Is this a good
default? The documentation says that the gain after 4 pthreads is not
much, and using more could be counterproductive. For example:

No threads:

$ perl -MTime::HiRes=time -MPDL -E '
set_autopthread_targ(shift) if @ARGV; $x = zeroes(5000,5000);
$y =5; $t=time; $z=$x+$y; say "Time: ", time-$t, "\nThreads: ",
get_autopthread_actual();
' 0
Time: 0.0815010070800781
Threads: 0

Two threads:

$ perl -MTime::HiRes=time -MPDL -E '
set_autopthread_targ(shift) if @ARGV; $x = zeroes(5000,5000);
$y =5; $t=time; $z=$x+$y; say "Time: ", time-$t, "\nThreads: ",
get_autopthread_actual();
' 2
Time: 0.0741269588470459
Threads: 2

There is a gain, but small.

Four threads:

mochan@tlahuilli:~$ perl -MTime::HiRes=time -MPDL -E '
set_autopthread_targ(shift) if @ARGV; $x = zeroes(5000,5000);
$y =5; $t=time; $z=$x+$y; say "Time: ", time-$t, "\nThreads: ",
get_autopthread_actual();
' 4
Time: 0.0751421451568604
Threads: 4

Slightly worse.

Default:

mochan@tlahuilli:~$ perl -MTime::HiRes=time -MPDL -E '
set_autopthread_targ(shift) if @ARGV; $x = zeroes(5000,5000);
$y =5; $t=time; $z=$x+$y; say "Time: ", time-$t, "\nThreads: ",
get_autopthread_actual();
'
Time: 0.0870430469512939
Threads: 48

Even worse with 48 threads.

Maybe this is a bad example to show the benefits of pthreads. Is there
a simple more convincing case?

Regards,
Luis


--

  o
W. Luis Mochán,  | tel:(52)(777)329-1734 /<(*)
Instituto de Ciencias Físicas, UNAM  | fax:(52)(777)317-5388 `>/   /\
Av. Universidad s/n CP 62210 |   (*)/\/  \
Cuernavaca, Morelos, México  | moc...@fis.unam.mx   /\_/\__/
GPG: 791EB9EB, C949 3F81 6D9B 1191 9A16  C2DF 5F0A C52B 791E B9EB


___
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general