Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cpu use in threads

2 views
Skip to first unread message

Angshuman Guin

unread,
Mar 27, 2004, 1:48:43 PM3/27/04
to
I am trying to use the capabilities of a multi(4) processor system to split
a task by using threads. But when I run the program I see only one cpu being
used although I have spawned 2 threads.

Am I doing anything wrong? Here is some relevant portion of my code:
__________________________________
use threads;
...
...
...
my $thr1 = threads->new(\&sub1, @det_files);
my $thr2 = threads->new(\&sub1, @det_files1);

$thr1->join;
$thr2->join;
...
...
__________________________________

And here is the output from perl -V


_______________________________

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.21-1.1931.2.382.entsmp,
archname=i386-linux-thread-multi
uname='linux str'


config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 -Dmyhostnam
e=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat,
Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix
=/usr -Dsiteprefix=/usr -Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Du
sethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -
Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallus
rbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef'
useithreads=define usemultiplicity=
useperlio= d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=un uselongdouble=
usemymalloc=, bincompat5005=undef
Compiler:
cc='gcc', ccflags
='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-ali
asing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr
/include/gdbm',
optimize='',


cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-st
rict-aliasing -I/usr/local/include -I/usr/include/gdbm'
ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 3.2.2-5)',
gccosandvers=''
gccversion='3.2.2 200302'
intsize=r, longsize=r, ptrsize=5, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long'
k', ivsize=4'
ivtype='l, nvtype='double'
o_nonbl', nvsize=, Off_t='', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='gcc'
l', ldflags =' -L/u'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
perllibs=
libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libper
gnulibc_version='2.3.2'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so', d_dlsymun=undef,
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi
/CORE'
cccdlflags='-fPIC'
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5', lddlflags='s
Unicode/Normalize XS/A'


Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT
Locally applied patches:
MAINT18379
Built under linux
Compiled at Aug 13 2003 11:47:58
@INC:
/usr/lib/perl5/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/5.8.0
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.0
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/5.8.0

__________________________________


Thanks in advance!
-AG-

Tassilo v. Parseval

unread,
Mar 28, 2004, 2:37:52 AM3/28/04
to
Also sprach Angshuman Guin:

> I am trying to use the capabilities of a multi(4) processor system to split
> a task by using threads. But when I run the program I see only one cpu being
> used although I have spawned 2 threads.

I am not an expert for Perl's threading capabilities. However, the POSIX
thread library it uses (where available) isn't quite yet ready for SMP
and wont distribute the threads over the processors (AFAIK).

For a real multi-processor system you should be using something else.
One standard for parallel programming is MPI. See for instance

<http://www-unix.mcs.anl.gov/mpi/>

for an introduction on MPI and MPICH which is a very reasonable free
implementation of it.

Naturally, MPI (Message Passing Interface) is very different from
threads. No data is shared between processors and must be passed around
explicitely. As it is used in the field of scientific computing, the
libraries you find for it are for C and FORTRAN. With Parallel::MPI and
Parallel::MPI::Simple there are two Perl modules available.

[...]

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval

ctc...@hotmail.com

unread,
Mar 29, 2004, 12:43:12 PM3/29/04
to
"Angshuman Guin" <angs...@hotmail.com> wrote:
> I am trying to use the capabilities of a multi(4) processor system to
> split a task by using threads. But when I run the program I see only one
> cpu being used although I have spawned 2 threads.
>
> Am I doing anything wrong? Here is some relevant portion of my code:
> __________________________________
> use threads;
> ...
> ...
> ...
> my $thr1 = threads->new(\&sub1, @det_files);
> my $thr2 = threads->new(\&sub1, @det_files1);
>
> $thr1->join;
> $thr2->join;

Alas, the only machine I have with 5.8 is a single CPU, but on
it each thread shows up a different process (with top), so I'm assuming
they would run simultaneously if I were to have multiple CPUs.

But there is one difference I notice in our versions that may be important:

> useithreads=define usemultiplicity=
> useperlio= d_sfio=undef uselargefiles=define usesocks=undef

your usemultiplicity seems to be unset (but strangly isn't listed as undef,
like must others are), while mine is :
usemultiplicity=define

I don't know that this is the problem, but it is what I would look into
first.

Well, actually, I'd probably not use threading at all, but rather fork.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB

ctc...@hotmail.com

unread,
Mar 29, 2004, 12:43:49 PM3/29/04
to
"Angshuman Guin" <angs...@hotmail.com> wrote:
> I am trying to use the capabilities of a multi(4) processor system to
> split a task by using threads. But when I run the program I see only one
> cpu being used although I have spawned 2 threads.
>
> Am I doing anything wrong? Here is some relevant portion of my code:
> __________________________________
> use threads;
> ...
> ...
> ...
> my $thr1 = threads->new(\&sub1, @det_files);
> my $thr2 = threads->new(\&sub1, @det_files1);
>
> $thr1->join;
> $thr2->join;

Alas, the only machine I have with 5.8 is a single CPU, but on


it each thread shows up a different process (with top), so I'm assuming
they would run simultaneously if I were to have multiple CPUs.

But there is one difference I notice in our versions that may be important:

> useithreads=define usemultiplicity=
> useperlio= d_sfio=undef uselargefiles=define usesocks=undef

your usemultiplicity seems to be unset (but strangly isn't listed as undef,
like most others are), while mine is :

Walter Roberson

unread,
Mar 29, 2004, 1:17:43 PM3/29/04
to
In article <c45vcg$4js$1...@nets3.rz.RWTH-Aachen.DE>,
Tassilo v. Parseval <tassilo....@post.rwth-aachen.de> wrote:
:I am not an expert for Perl's threading capabilities. However, the POSIX

:thread library it uses (where available) isn't quite yet ready for SMP
:and wont distribute the threads over the processors (AFAIK).

I haven't looked at the standards in this regards, but on at least
one variety of "real" SMP (SGI Challenge XL), what happens is that
each of the threads may run on a different CPU but the time is
added into a single accounting structure -- resulting in oddities
like having a single process that is taking 700% of a CPU.
--
Warning: potentially contains traces of nuts.

Angshuman Guin

unread,
Mar 29, 2004, 7:13:22 PM3/29/04
to
Yes I think you are right. The CPU was still showing nearly 99.9% usage.
However the cpu time was jumping at double the pace of the refresh rate. I
think it was really using two CPUs. I'll increase the threads and see if the
thing scales up.

Thanks!


"Walter Roberson" <robe...@ibd.nrc-cnrc.gc.ca> wrote in message
news:c49p87$8e3$1...@canopus.cc.umanitoba.ca...

0 new messages