[30080] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1323 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 1 14:09:39 2008

Date: Sat, 1 Mar 2008 11:09:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 1 Mar 2008     Volume: 11 Number: 1323

Today's topics:
    Re: Converting "&#x2019;" to an Apostrophe? <stoupa@practisoft.cz>
    Re: Converting "&#x2019;" to an Apostrophe? <uri@stemsystems.com>
    Re: Converting "&#x2019;" to an Apostrophe? <hjp-usenet2@hjp.at>
    Re: FAQ 4.2 Why is int() broken? <hjp-usenet2@hjp.at>
    Re: FAQ 4.4 Does Perl have a round() function?  What ab <hjp-usenet2@hjp.at>
    Re: Parsing multi-line text <hjp-usenet2@hjp.at>
    Re: Parsing multi-line text <hjp-usenet2@hjp.at>
    Re: Spreadsheet::ParseExcel - How to get certain Cells <cartercc@gmail.com>
        Tecnique and/or Modules for Perl and HTML <pgodfrin@gmail.com>
    Re: Tecnique and/or Modules for Perl and HTML <rkb@i.frys.com>
    Re: Tecnique and/or Modules for Perl and HTML <rkb@i.frys.com>
    Re: Tecnique and/or Modules for Perl and HTML <pgodfrin@gmail.com>
    Re: Threading NOT working as expected <hjp-usenet2@hjp.at>
    Re: Threading NOT working as expected <m@rtij.nl.invlalid>
    Re: Threading NOT working as expected <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 1 Mar 2008 16:49:03 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Converting "&#x2019;" to an Apostrophe?
Message-Id: <fqbube$dg7$1@ns.felk.cvut.cz>

A. Sinan Unur wrote:
> In the mean time, here in 2008, in the docs shipped with Perl 5.10
>
> perldoc perlop
>
>   s   Treat string as single line. (Make . match a newline)
>
Yes, right. But
    $string =~ s/&#x2019;/'/sg;
work in Perl 5.8, Perl 5.10 and Perl 5.6.1 too.

But
    $string =~ s/&#x2019;/'/g;
not work in Perl 5.6.1.
I don't know what Perl version my client have installed so I'm used to write 
scripts with backward compatibility. It's all.

-- 
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>



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

Date: Sat, 01 Mar 2008 16:34:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Converting "&#x2019;" to an Apostrophe?
Message-Id: <x7bq5y8ktu.fsf@mail.sysarch.com>

>>>>> "PV" == Petr Vileta <stoupa@practisoft.cz> writes:

  PV> A. Sinan Unur wrote:
  >> In the mean time, here in 2008, in the docs shipped with Perl 5.10
  >> 
  >> perldoc perlop
  >> 
  >> s   Treat string as single line. (Make . match a newline)
  >> 
  PV> Yes, right. But
  PV>     $string =~ s/&#x2019;/'/sg;
  PV> work in Perl 5.8, Perl 5.10 and Perl 5.6.1 too.

  PV> But
  PV>     $string =~ s/&#x2019;/'/g;
  PV> not work in Perl 5.6.1.

please post complete code that shows that /s is needed there.

 perl5.6.1 -le '$x= "&#x2019;foo&#x2019;" ; $x =~ s/&#x2019;/"/g; print $x'
"foo"

 perl5.8.6 -le '$x= "&#x2019;foo&#x2019;" ; $x =~ s/&#x2019;/"/g; print $x'
"foo"

looks like it works in 5.6.1 just fine without /s. that makes sense
since there is no . in the regex. i changed it to replace " to simplify
the shell quote issues.

  PV> I don't know what Perl version my client have installed so I'm used to
  PV> write scripts with backward compatibility. It's all.

/s has always done the same simple thing since it was created. the docs
for it were poor for sure as they should have only stated that /s makes
 . also match \n.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Sat, 1 Mar 2008 17:31:34 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Converting "&#x2019;" to an Apostrophe?
Message-Id: <slrnfsj176.rjj.hjp-usenet2@hrunkner.hjp.at>

On 2008-03-01 15:49, Petr Vileta <stoupa@practisoft.cz> wrote:
> A. Sinan Unur wrote:
>> In the mean time, here in 2008, in the docs shipped with Perl 5.10
>>
>> perldoc perlop
>>
>>   s   Treat string as single line. (Make . match a newline)
>>
> Yes, right. But
>     $string =~ s/&#x2019;/'/sg;
> work in Perl 5.8, Perl 5.10 and Perl 5.6.1 too.
>
> But
>     $string =~ s/&#x2019;/'/g;
> not work in Perl 5.6.1.

Works for me:

#!/usr/bin/perl
use warnings;
use strict;

my $string = 'foo &#x2019; bar';

$string =~ s/&#x2019;/'/g;

print "$string\n";
__END__

prints:

foo ' bar

This is perl, v5.6.1 built for i386-linux

Copyright 1987-2001, Larry Wall

	hp


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

Date: Sat, 1 Mar 2008 16:32:33 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 4.2 Why is int() broken?
Message-Id: <slrnfsitoh.q77.hjp-usenet2@hrunkner.hjp.at>

On 2008-02-18 02:03, PerlFAQ Server <brian@stonehenge.com> wrote:
> --------------------------------------------------------------------
>
> 4.2: Why is int() broken?
>
>     Your "int()" is most probably working just fine. It's the numbers that
>     aren't quite what you think.
>
>     First, see the answer to "Why am I getting long decimals (eg,
>     19.9499999999999) instead of the numbers I should be getting (eg,
>     19.95)?".
>
>     For example, this
>
>             print int(0.6/0.2-2), "\n";

Why subtract 2? This example works just as well without the subtraction:

	    perl -e 'print int(0.6/0.2), "\n";' 
	    2

>     will in most computers print 0, not 1, because even such simple numbers
>     as 0.6 and 0.2 cannot be presented exactly by floating-point numbers.

I don't like the phrase "even such simple numbers as 0.6 and 0.2". It
implies that these numbers are "simple" and that there is much less of a
chance that such "complicated" numbers as 952279704355844 or
0.845794282927275986594395362772047519683837890625 can be represented
exactly, when in fact they can. Also "by floating-point numbers" is
incorrect in its generality - they could be represented by decimal
floating-point numbers.

How about

    ... because 0.6 and 0.2 cannot be presented exactly by binary
    floating-point numbers because they are not multiples of a power of
    two.

>     What you think in the above as 'three' is really more like
>     2.9999999999999995559.

And that can be easily demonstrated by subtracting 3:

	    perl -e 'print +(0.6/0.2) - 3, "\n";'
	    -4.44089209850063e-16

	hp


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

Date: Sat, 1 Mar 2008 16:19:01 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 4.4 Does Perl have a round() function?  What about ceil() and floor()?  Trig functions?
Message-Id: <slrnfsisv5.q77.hjp-usenet2@hrunkner.hjp.at>

On 2008-02-15 20:03, PerlFAQ Server <brian@stonehenge.com> wrote:
>     Rounding in financial applications can have serious implications, and
>     the rounding method used should be specified precisely. In these cases,
>     it probably pays not to trust whichever system rounding is being used by
>     Perl, but to instead implement the rounding function you need yourself.
>
>     To see why, notice how you'll still have an issue on half-way-point
>     alternation:
>
>             for ($i = 0; $i < 1.01; $i += 0.05) { printf "%.1f ",$i}
>
>             0.0 0.1 0.1 0.2 0.2 0.2 0.3 0.3 0.4 0.4 0.5 0.5 0.6 0.7 0.7
>             0.8 0.8 0.9 0.9 1.0 1.0
>
>     Don't blame Perl. It's the same as in C. IEEE says we have to do this.

That example conflates two different issues:

1) 0.05 is not exactly representable as a binary floating point number,
   so $i doesn't get the values 0.00, 0.05, 0.10, 0.15, 0.20, 0.25, ...
   as one might naively expect. Instead it gets the values
   0.00000000000000000000
   0.05000000000000000278
   0.10000000000000000555
   0.15000000000000002220
   0.20000000000000001110
   0.25000000000000000000
   ...
   (rounded to 20 digits after the comma). So the second value
   (0.05000000000000000278) is actually a bit above 0.05 and therefore
   has to be rounded up according to the "round to nearest" rule.
   So most of these numbers are not at the "half-way-point", and can be
   clearly and anambiguosly rounded (but the result is not what you
   expect when you think they are at the half-way-point.

2) The one exception is 0.25 which just happens to be exact because all
   the rounding errors cancel out at that point[1]. 0.25 is exactly
   half-way between 0.2 and 0.3 so "round to nearest" cannot decide
   between these two. In school we all learned to round up in this case.
   The IEEE rules, however, mandate that one must round to the nearest
   *even* number, i.e., 0.2 in this case.

I'm not sure which of these issues the example should demonstrate, but
showing both in a single example without adequate explanation is
confusing. The "half-way-point" problem can be demonstrated correctly
with:

            for ($i = 0; $i <= 10; $i += 0.5) { printf "%.0f ",$i}

            0 0 1 2 2 2 3 4 4 4 5 6 6 6 7 8 8 8 9 10 10

The fact that decimal fractions are not generally representable in
binary fp and that adding them is an especially bad idea can be
demonstrated better with:

	    for ($i = 0, $j = 0; $i < 1.01; $i += 0.05, $j += 5) {
		print $i * 100 - $j, " ";
	    }

	    0 0 0 1.77635683940025e-15 0 0 0 0 0 -7.105427357601e-15
	    -7.105427357601e-15 -7.105427357601e-15 0 0 0
	    1.4210854715202e-14 1.4210854715202e-14 1.4210854715202e-14
	    2.8421709430404e-14 2.8421709430404e-14 2.8421709430404e-14

(Although there are still too many 0s in the output - maybe somebody can
find a better example).

>     Perl numbers whose absolute values are integers under 2**31 (on 32 bit

2**53 actually, if the machine uses IEEE FP arithmetic.

	hp

[1] I didn't expect that and I even repeated the calculation with pencil
and paper. Adding a number which is slightly larger than 0.05 5 times
gives exactly 0.25 in IEEE double arithmetic. 


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

Date: Sat, 1 Mar 2008 16:42:00 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Parsing multi-line text
Message-Id: <slrnfsiuaa.q77.hjp-usenet2@hrunkner.hjp.at>

On 2008-02-18 10:42, keith@bytebrothers.co.uk <keith@bytebrothers.co.uk> wrote:
> I have a data file structured something like this:
>
> ------------------8<-----------------------
> Chunk 01
> 	NAME: "Alice"
> 	Description: "Some other string"
> 	Age: 37
> Chunk 02
> 	NAME: "Bob"
> 	Description: "Some other string"
> 	Age: 28
> Chunk 03
> 	FIRST: "Carol"
> 	Description: "Some other string"
> 	Age: 32
> Chunk 04
> 	FIRST: "Dave"
> 	Description: "Some other string"
> 	Age: 22
> ------------------8<-----------------------
>
> and I want to extract from it to produce output something like this:
>
> ------------------8<-----------------------
> 01 NAME: Alice    -> 37
> 02 NAME: Bob     -> 28
> 03 NAME: Carol    -> 32
> 04 NAME: Dave    -> 22
> ------------------8<-----------------------

Sure about that? In the input you have sometimes "FIRST" and sometimes
"NAME", but in the output it is always NAME. Assuming this is
intentional:


#!/usr/bin/perl
use strict;
use warnings;

my $s = <<EOS;
Chunk 01
        NAME: "Alice"
        Description: "Some other string"
        Age: 37
Chunk 02
        NAME: "Bob"
        Description: "Some other string"
        Age: 28
Chunk 03
        FIRST: "Carol"
        Description: "Some other string"
        Age: 32
Chunk 04
        FIRST: "Dave"
        Description: "Some other string"
        Age: 22
EOS

while ($s =~ m{
		^Chunk \s (\d+) \n
		\s+(NAME|FIRST): \s "(.*?)" \n
		\s+Description: \s "(.*?)" \n
		\s+Age: \s (\d+) \n
             }xmg
      ) {
    print "$1 NAME: $3 -> $5\n";
}

	hp


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

Date: Sat, 1 Mar 2008 16:45:47 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Parsing multi-line text
Message-Id: <slrnfsiuhe.q77.hjp-usenet2@hrunkner.hjp.at>

On 2008-02-18 11:18, Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> keith@bytebrothers.co.uk wrote:
>> I have a data file structured something like this:
>> 
>> ------------------8<-----------------------
>> Chunk 01
>> 	NAME: "Alice"
>> 	Description: "Some other string"
>> 	Age: 37
>> Chunk 02
>> 	NAME: "Bob"
>> 	Description: "Some other string"

change this line to

	Description: "Some Chunky string"

>> 	Age: 28
 ...
>> ------------------8<-----------------------
>
>      local $/ = 'Chunk';
>      while (<>) {
>          if ( /(\d+).+[A-Z]+:\s+"([^"]*)".+Age:\s+(\d+)/s ) {
>              printf "%02d NAME: %-10s -> %d\n", $1, $2, $3;
>          }
>      }

and then run this script again.

	hp


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

Date: Sat, 1 Mar 2008 07:29:14 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Spreadsheet::ParseExcel - How to get certain Cells
Message-Id: <dca404cc-faac-4cf0-88d6-03ae5eb94918@u10g2000prn.googlegroups.com>

On Feb 29, 1:01 pm, Tom Brown <n...@home.net> wrote:
> After sleeping over it, I conclude Perl, respectively the module
> Spreadsheet::ParseExcel, can't provide what I was looking for. For a
> simple reason: The initial point where I started was just a partial
> view (let's say excerpt) on a sheet, i. e., the actual sheet has in
> fact a quite different data structure as shown in the filtered excel
> view. Therefore, the output from my script/Spreadsheet::ParseExcel is
> based on the real content of the sheet and not on my partial view.
>
> However, your comments, J., nudged me into the proper direction and I
> got now what I was initally looking for.

I have to play with Perl and Excel from time to time, but my problem
goes the other way -- writing to an Excel file rather than reading
one. The crude way is writing the data to a csv file that Excel will
open natively. This works perfectly for the data but it doesn't
configure the workbook. The other way is to generate an xml file that
Excel will open. This also works perfectly, it's more work for me but
the file will also open in a browser which you can connect with a CSS
file and pretty it up for users that only want to look at the data,
not manipulate it. And in fact, you can do both for your two kinds of
users, those that want to slice and dice the data and those that only
want to look at it.

I'd be very interested in your solution. I'd also be interested to
know why you couldn't open your data file as an xml file and read the
data from that.

CC


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

Date: Sat, 1 Mar 2008 07:42:30 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Tecnique and/or Modules for Perl and HTML
Message-Id: <a16590a0-8cc0-42fc-947f-5aca23a177ae@d21g2000prf.googlegroups.com>

Greetings,

Could someone point me in the right direction? I'm not a web developer
- just a budding perl dude (who's really a database guy).

I'd like to (at first) read from database (using DBI) and display the
contents on a web page. The trick is I want to do it on the same page
that the action button resides and pop the output of the perl program
into a scrollable box. Nothing fancy - just output some data from a
database call. Eventually I'd like to be able to pass variables from a
form to the waiting perl program

There is a bunch of confusing stuff out there everything from
javascript to embperl and then Mason.  And the unspeakable PHP of
course...

Can anyone offer some advice where I should go? (ok - no wisecracks...
<grin>)

thanks,
pg


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

Date: Sat, 1 Mar 2008 08:42:42 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Tecnique and/or Modules for Perl and HTML
Message-Id: <d7994230-07df-4165-82c3-d62b92d975fd@s19g2000prg.googlegroups.com>

On Mar 1, 7:42 am, pgodfrin <pgodf...@gmail.com> wrote:
> Greetings,
>
> Could someone point me in the right direction? I'm not a web developer
> - just a budding perl dude (who's really a database guy).
>
> I'd like to (at first) read from database (using DBI) and display the
> contents on a web page. The trick is I want to do it on the same page
> that the action button resides and pop the output of the perl program
> into a scrollable box. Nothing fancy - just output some data from a
> database call. Eventually I'd like to be able to pass variables from a
> form to the waiting perl program
>
> There is a bunch of confusing stuff out there everything from
> javascript to embperl and then Mason.  And the unspeakable PHP of
> course...
>
> Can anyone offer some advice where I should go? (ok - no wisecracks...
> <grin>)
>
> thanks,
> pg

Have you looked at the CGI module?  The synopsis section will give you
a hint on part of what you need.  By the time you finish reading the
doc, you should have a pretty good idea where to start.  After you've
made an attempt, post back with specific questions and example code
that demonstrates the problem that you're having.
http://search.cpan.org/~lds/CGI.pm-3.33/CGI.pm


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

Date: Sat, 1 Mar 2008 08:42:52 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Tecnique and/or Modules for Perl and HTML
Message-Id: <650c70b0-d7a1-48c6-8e63-950816df8e83@u10g2000prn.googlegroups.com>

On Mar 1, 7:42 am, pgodfrin <pgodf...@gmail.com> wrote:
> Greetings,
>
> Could someone point me in the right direction? I'm not a web developer
> - just a budding perl dude (who's really a database guy).
>
> I'd like to (at first) read from database (using DBI) and display the
> contents on a web page. The trick is I want to do it on the same page
> that the action button resides and pop the output of the perl program
> into a scrollable box. Nothing fancy - just output some data from a
> database call. Eventually I'd like to be able to pass variables from a
> form to the waiting perl program
>
> There is a bunch of confusing stuff out there everything from
> javascript to embperl and then Mason.  And the unspeakable PHP of
> course...
>
> Can anyone offer some advice where I should go? (ok - no wisecracks...
> <grin>)
>
> thanks,
> pg

Have you looked at the CGI module?  The synopsis section will give you
a hint on part of what you need.  By the time you finish reading the
doc, you should have a pretty good idea where to start.  After you've
made an attempt, post back with specific questions and example code
that demonstrates the problem that you're having.
http://search.cpan.org/~lds/CGI.pm-3.33/CGI.pm


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

Date: Sat, 1 Mar 2008 08:56:11 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: Tecnique and/or Modules for Perl and HTML
Message-Id: <54fb37b8-3cc0-48de-b756-821fbcdfb3c8@i29g2000prf.googlegroups.com>

On Mar 1, 10:42 am, Ron Bergin <r...@i.frys.com> wrote:
> On Mar 1, 7:42 am, pgodfrin <pgodf...@gmail.com> wrote:
>
>
>
> > Greetings,
>
> > Could someone point me in the right direction? I'm not a web developer
> > - just a budding perl dude (who's really a database guy).
>
> > I'd like to (at first) read from database (using DBI) and display the
> > contents on a web page. The trick is I want to do it on the same page
> > that the action button resides and pop the output of the perl program
> > into a scrollable box. Nothing fancy - just output some data from a
> > database call. Eventually I'd like to be able to pass variables from a
> > form to the waiting perl program
>
> > There is a bunch of confusing stuff out there everything from
> > javascript to embperl and then Mason.  And the unspeakable PHP of
> > course...
>
> > Can anyone offer some advice where I should go? (ok - no wisecracks...
> > <grin>)
>
> > thanks,
> > pg
>
> Have you looked at the CGI module?  The synopsis section will give you
> a hint on part of what you need.  By the time you finish reading the
> doc, you should have a pretty good idea where to start.  After you've
> made an attempt, post back with specific questions and example code
> that demonstrates the problem that you're having.http://search.cpan.org/~lds/CGI.pm-3.33/CGI.pm

Yep - I've even run the samples. Perhaps it's a conceptual thing, but
it seems to me that the CGI module is all encompassing. When it's run
- it must produce the entire web page. Which is not what I think I
want.

I'm not having a problem per se, but a conceptual quagmire - I have a
web page, I just want to slap a table or text box in the middle of it
with data from a perl DBI query. Maybe that's not how you do it...
pg


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

Date: Sat, 1 Mar 2008 17:04:08 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Threading NOT working as expected
Message-Id: <slrnfsivjq.q77.hjp-usenet2@hrunkner.hjp.at>

On 2008-02-26 16:39, Ted Zlatanov <tzz@lifelogs.com> wrote:
> On Mon, 25 Feb 2008 12:05:09 -0800 (PST) Ted <r.ted.byers@rogers.com> wrote: 
[number of threads should equal number of CPU cores]

> This is incorrect.  A modern single processor will perform well in a
> multithreaded application.  Just because a single thread will run
> doesn't mean a single thread is doing work at any time.
>
> Most of the time in a modern system is spent waiting for I/O and memory
> access.  There are some very special cases where the CPU is actually
> tied up while the application runs, but memory and disk speeds have
> fallen far behind CPU speeds so the CPU will usually be waiting for
> something to happen.  This is why modern CPUs have ridiculously large L1
> and L2 caches and many prefetching optimizations.
>
> In a multithreaded setup, the CPU has a chance to run several threads
> while memory and I/O fetches are happening.

Multithreading won't help for memory fetches. Firstly because CPUs don't
have a way to inform the OS of a slow memory access, and secondly
because the overhead of switching to a different thread would be much
too high for such a (relatively) short wait. There is one exception:
So-called multi-threading CPUs can keep the state of a fixed (and
usually low) number of thrads on the CPU and switch between them. But
these are really just multi-core CPUs which share some of their units.

You are completely right about I/O of course.

	hp


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

Date: Sat, 1 Mar 2008 18:09:32 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Threading NOT working as expected
Message-Id: <pan.2008.03.01.17.09.32@rtij.nl.invlalid>

On Sat, 01 Mar 2008 17:04:08 +0100, Peter J. Holzer wrote:

> On 2008-02-26 16:39, Ted Zlatanov <tzz@lifelogs.com> wrote:
>> On Mon, 25 Feb 2008 12:05:09 -0800 (PST) Ted <r.ted.byers@rogers.com>
>> wrote:
> [number of threads should equal number of CPU cores]
> 
>> This is incorrect.  A modern single processor will perform well in a
>> multithreaded application.  Just because a single thread will run
>> doesn't mean a single thread is doing work at any time.
>>
>> Most of the time in a modern system is spent waiting for I/O and memory
>> access.  There are some very special cases where the CPU is actually
>> tied up while the application runs, but memory and disk speeds have
>> fallen far behind CPU speeds so the CPU will usually be waiting for
>> something to happen.  This is why modern CPUs have ridiculously large
>> L1 and L2 caches and many prefetching optimizations.
>>
>> In a multithreaded setup, the CPU has a chance to run several threads
>> while memory and I/O fetches are happening.
> 
> Multithreading won't help for memory fetches. Firstly because CPUs don't
> have a way to inform the OS of a slow memory access, and secondly
> because the overhead of switching to a different thread would be much
> too high for such a (relatively) short wait. There is one exception:
> So-called multi-threading CPUs can keep the state of a fixed (and
> usually low) number of thrads on the CPU and switch between them. But
> these are really just multi-core CPUs which share some of their units.
> 
> You are completely right about I/O of course.

Not even. If all those I/Os are going to the same disk, you run the risk 
of thrashing, and overall performance goes down instead of up.

Exactly the same behaviour can be seen with processes. Suppose you have a 
bunch of files, together much larger than available memory. These files 
are input to a program that handles one file and writes another output 
file. You can do either:

for f in *; do program "$f" "$f.out"&; done; wait

or

for f in *; do program "$f" "$f.out"; done;

If the program is I/O bound, I expect the second version to be faster 
than the first, although it depends on a lot of things.

So think, design, and profile, profile, profile.

M4



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

Date: Sat, 1 Mar 2008 19:11:00 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Threading NOT working as expected
Message-Id: <slrnfsj71m.s2i.hjp-usenet2@hrunkner.hjp.at>

On 2008-03-01 17:09, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
> On Sat, 01 Mar 2008 17:04:08 +0100, Peter J. Holzer wrote:
>
>> On 2008-02-26 16:39, Ted Zlatanov <tzz@lifelogs.com> wrote:
>>> On Mon, 25 Feb 2008 12:05:09 -0800 (PST) Ted <r.ted.byers@rogers.com>
>>> wrote:
>> [number of threads should equal number of CPU cores]
>> 
>>> This is incorrect.  A modern single processor will perform well in a
>>> multithreaded application.  Just because a single thread will run
>>> doesn't mean a single thread is doing work at any time.
[...]
>>> In a multithreaded setup, the CPU has a chance to run several threads
>>> while memory and I/O fetches are happening.
>> 
>> Multithreading won't help for memory fetches.
[...]
>> You are completely right about I/O of course.
>
> Not even. If all those I/Os are going to the same disk, you run the risk 
> of thrashing, and overall performance goes down instead of up.

Of course. There are few problems which can be parallelized infinitely.
At some point further parallelization degrades performance instead of
improving it.

> Exactly the same behaviour can be seen with processes. Suppose you have a 
> bunch of files, together much larger than available memory. These files 
> are input to a program that handles one file and writes another output 
> file. You can do either:
>
> for f in *; do program "$f" "$f.out"&; done; wait
>
> or
>
> for f in *; do program "$f" "$f.out"; done;
>
> If the program is I/O bound, I expect the second version to be faster 
> than the first, although it depends on a lot of things.

One of the things it depends on is size and placement of the files on
disk. If the files are large and stored (mostly) contiguously, the
second version is almost certainly faster. But if they are small and
scattered all over the disk, the first version may be faster because it
allows the kernel (or even the disk) to decide on the order in which it
reads these files.

> So think, design, and profile, profile, profile.

Full ack.

	hp



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1323
***************************************


home help back first fref pref prev next nref lref last post