Boost logo

Boost :

From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-05-14 16:40:32


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 14 May 2008 16:36 pm, Frank Mori Hess wrote:
> On Wednesday 14 May 2008 16:24 pm, James Sutherland wrote:
> > Phil,
> > Thank you for your suggestions - I am hunting in the dark here...
> >
> > >> for( int itask=0; itask<nTasks; ++itask ){
> > >> boost::thread_group threads;
> > >> for( int i=0; i<nThreads; ++i ){
> > >> threads.create_thread( MyStruct(itask++ + 100) );
> > >> }
> > >> threads.join_all();
> > >> }
> > >
> > > Did you really want the ++itask in the first for() ? Isn't it being
> > > incremented enough in the create_thread line?
> >
> > This was intentional. This highly contrived example creates a fixed
> > amount of work (nTasks) and divides them up among nThreads threads.
> > As a thread takes a task, I increment itask. Strange, I know...
>
> No, if you also increment itask in the outer loop, you are doing fewer
> tasks when nThreads is smaller. Although, what I said before about
> creating more threads than you think was wrong (I misunderstood your
> program).

Also, your program appears to output the cpu time spent on the program, not
the real time it took. What I see (after fixing the itask increment):

$time ./a.out
Executing 12 tasks using 1 threads.
time: 9.64

real 0m9.668s
user 0m9.641s
sys 0m0.004s

$ time ./a.out
Executing 12 tasks using 2 threads.
time: 9.91

real 0m4.991s
user 0m9.909s
sys 0m0.012s

- --
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIK05B5vihyNWuA4URAkAbAKCWSBb0kLmh61BLesNiBRCDm8rdhACgp0Wi
SR1/9LEMLdcr8K4eSOeOA+o=
=mGQ4
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk