Distributed sample sort works, now have to rewrite distributed tree building.

This commit is contained in:
Dongryeol Lee
2011-01-04 19:59:39 +00:00
parent e10555c709
commit 4ceaff3e2a
2 changed files with 35 additions and 3 deletions
@@ -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;
@@ -9,19 +9,43 @@
#include "core/math/math_lib.h"
class DoublePartitionFunction {
private:
int ComputeBucketIndex_(
const std::vector<double> &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<double> &array_in,
const std::vector<double> &partitions_in,
std::vector< std::vector<double> > *buckets_out) {
std::vector< std::vector<double> > *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<double> weights(world.size(), 0);
@@ -40,8 +64,12 @@ int main(int argc, char *argv[]) {
// Sort.
core::parallel::ParallelSampleSort<double> 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;
}