|
Boost Users : |
Subject: Re: [Boost-users] [mapreduce] Prim Calculator
From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2009-08-22 13:11:57
> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of Christian Henning
> Sent: 22 August 2009 17:19
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] [mapreduce] Prim Calculator
>
> Hi Craig,
>
> I also have rewritten the prime_calculator. I never like that the fact
> that the reduce key type was std::size_t. It should be bool. is_prime
> is now returning a boolean. I also have changed map value type from
> std::pair<std::size_t,std::size_t> to just std::size_t. I hope this is
> correct in terms of the mapreduce methodologies.
>
> To adopt the mapreduce problem description notation this is what I
> want:
>
> map: ( number, number ) -----> list( boolean, number )
> reduce: ( boolean, list( number ) ---------> list( number )
>
> Well, it all compiles and runs but the results is empty. I have
> intercepted the reduce function and the supplied list is correct.
> Meaning all primes are in there. Weird. Dunno what's wrong here.
Did you try defining the job to write the results to file? This will work
until I fix the iterator issue.
A small optimization in the is_prime is to check for %2 - this avoids
expensive sqrt & loops for even numbers that are always not prime
bool const is_prime(long const number)
{
if (number == 0 || number == 1)
return false;
else if (number == 2)
return true;
else if (number%2 == 0)
return false;
...
}
Regards
-- Craig
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net