|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55860 - sandbox/libs/mapreduce/examples/prime
From: cdm.henderson_at_[hidden]
Date: 2009-08-29 07:34:20
Author: chenderson
Date: 2009-08-29 07:34:20 EDT (Sat, 29 Aug 2009)
New Revision: 55860
URL: http://svn.boost.org/trac/boost/changeset/55860
Log:
Small optimisations
Text files modified:
sandbox/libs/mapreduce/examples/prime/prime.cpp | 22 ++++++++++++----------
1 files changed, 12 insertions(+), 10 deletions(-)
Modified: sandbox/libs/mapreduce/examples/prime/prime.cpp
==============================================================================
--- sandbox/libs/mapreduce/examples/prime/prime.cpp (original)
+++ sandbox/libs/mapreduce/examples/prime/prime.cpp 2009-08-29 07:34:20 EDT (Sat, 29 Aug 2009)
@@ -1,4 +1,6 @@
// Based on code from Christian Henning [chhenning_at_[hidden]]
+#define _SECURE_SCL 0
+#define _HAS_ITERATOR_DEBUGGING 0
#include <boost/mapreduce.hpp>
namespace prime_calculator {
@@ -15,7 +17,7 @@
long n = std::abs(number);
long const sqrt_number = static_cast<long>(std::sqrt(static_cast<double>(n)));
- for (long i = 3; i < sqrt_number; ++i)
+ for (long i = 3; i < sqrt_number; i+=2)
{
if (n % i == 0)
return false;
@@ -88,15 +90,16 @@
int main(int argc, char* argv[])
{
boost::mapreduce::specification spec;
-
- boost::mapreduce::results result;
- prime_calculator::job::datasource_type datasource(0, 60000, 1000);
-
spec.map_tasks = 0;
spec.reduce_tasks = std::max(1U, boost::thread::hardware_concurrency());
+ int const prime_limit = 100;
+ prime_calculator::job::datasource_type datasource(0, prime_limit, prime_limit/spec.reduce_tasks);
+
+
std::cout <<"\nRunning Parallel Prime_Calculator MapReduce..." <<std::endl;
prime_calculator::job job(datasource, spec);
+ boost::mapreduce::results result;
#ifdef _DEBUG
job.run<boost::mapreduce::schedule_policy::sequential<prime_calculator::job> >(result);
#else
@@ -104,12 +107,11 @@
#endif
std::cout <<"\nMapReduce Finished." <<std::endl;
- for (prime_calculator::job::const_result_iterator it = job.begin_results()
- ; it!=job.end_results()
- ; ++it
- )
+ for (prime_calculator::job::const_result_iterator it = job.begin_results();
+ it!=job.end_results();
+ ++it)
{
- std::cout <<it->first <<" ";
+ std::cout <<it->second <<" ";
}
return 0;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk