diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/math/math_lib.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/math/math_lib.h index 06a9b2fe83..eda617371e 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/math/math_lib.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/math/math_lib.h @@ -22,6 +22,10 @@ class RandomNumberInit { gsl_rng *global_generator_; public: + void set_seed(unsigned int seed_in) { + gsl_rng_set(global_generator_, seed_in); + } + RandomNumberInit() { gsl_rng_env_setup(); global_generator_type_ = gsl_rng_default; diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/parallel_sample_sort.test.cc b/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/parallel_sample_sort.test.cc index 9fbe02874a..2ea610fb97 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/parallel_sample_sort.test.cc +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/parallel/parallel_sample_sort.test.cc @@ -9,19 +9,43 @@ #include "core/math/math_lib.h" class DoublePartitionFunction { + private: + int ComputeBucketIndex_( + const std::vector &partitions_in, double element_in) const { + + int bucket_index = 0; + for(unsigned int i = 0; i < partitions_in.size(); i++) { + if(element_in > partitions_in[i]) { + bucket_index++; + } + else { + break; + } + } + return bucket_index; + } + public: void Partition( const std::vector &array_in, const std::vector &partitions_in, - std::vector< std::vector > *buckets_out) { + std::vector< std::vector > *buckets_out) const { + buckets_out->resize(0); + buckets_out->resize(partitions_in.size() + 1); for(unsigned int i = 0; i < array_in.size(); i++) { int bucket_index = ComputeBucketIndex_(partitions_in, array_in[i]); - (*buckets_out)[i].push_back(array_in[i]); + (*buckets_out)[bucket_index].push_back(array_in[i]); } } }; +namespace core { +namespace math { +extern core::math::RandomNumberInit global_random_number_state_; +}; +}; + int main(int argc, char *argv[]) { // Initialize boost MPI. @@ -29,7 +53,7 @@ int main(int argc, char *argv[]) { boost::mpi::communicator world; // Seed the random number generator. - srand(time(NULL) + world.rank()); + core::math::global_random_number_state_.set_seed(time(NULL) + world.rank()); // Create a random vector of weights. std::vector weights(world.size(), 0); @@ -40,8 +64,12 @@ int main(int argc, char *argv[]) { // Sort. core::parallel::ParallelSampleSort sorter; + DoublePartitionFunction partition_function; sorter.Init(weights, 0.2); sorter.Sort(world, partition_function); + for(unsigned int i = 0; i < weights.size(); i++) { + printf("Sorted weight %d: %g\n", world.rank(), weights[i]); + } return 0; }