示例#1
0
    void interpolator::connect(std::string symbolic_name_base)
    {
        // Connect to the config object.
        hpx::naming::id_type cfg_gid = hpx::agas::resolve_name(symbolic_name_base).get();
        cfg_ = configuration(cfg_gid);
        config_data data = cfg_.get();

        if (data.symbolic_name_[data.symbolic_name_.size()-1] != '/')
            data.symbolic_name_ += "/";

        // Connect to the partitions.
        partitions_.reserve(data.num_instances_);
        for (std::size_t i = 0; i < data.num_instances_; ++i)
        {
            partitions_.push_back(hpx::naming::id_type());
            hpx::naming::id_type id = hpx::agas::resolve_name(
                    data.symbolic_name_ + std::to_string(i)).get();
        }

        // Read required data from given file.
        num_values_[dimension::ye] = extract_data_range(data.datafile_name_,
            "ye", minval_[dimension::ye], maxval_[dimension::ye],
            delta_[dimension::ye]);
        num_values_[dimension::temp] = extract_data_range(data.datafile_name_,
            "logtemp", minval_[dimension::temp], maxval_[dimension::temp],
            delta_[dimension::temp]);
        num_values_[dimension::rho] = extract_data_range(data.datafile_name_,
            "logrho", minval_[dimension::rho], maxval_[dimension::rho],
            delta_[dimension::rho]);

        num_partitions_per_dim_ = static_cast<std::size_t>(
            std::exp(std::log(double(data.num_instances_)) / 3));
    }
示例#2
0
    void interpolate1d::fill_partitions(std::string const& datafilename,
        hpx::future<std::vector<partition> > && future)
    {
        // read required data from file
        double maxval = 0;
        num_elements_ = extract_data_range(datafilename, minval_, maxval, delta_);

        // initialize the partitions
        partitions_ = future.get();

        std::size_t num_localities = partitions_.size();
        HPX_ASSERT(0 != num_localities);

        std::size_t partition_size = num_elements_ / num_localities;
        std::size_t last_partition_size =
            num_elements_ - partition_size * (num_localities-1);

        for (std::size_t i = 0; i != num_localities; ++i)
        {
            dimension dim;
            if (i == num_localities-1) {
                dim.offset_ = partition_size * i;
                dim.count_ = last_partition_size;
                dim.size_ = num_elements_;
            }
            else {
                dim.offset_ = partition_size * i;
                dim.count_ = partition_size;
                dim.size_ = num_elements_;
            }
            partitions_[i].init(datafilename, dim, num_localities);
        }
    }
示例#3
0
    void interpolate1d::fill_partitions(std::string const& datafilename,
        async_create_result_type future)
    {
        // read required data from file
        double maxval = 0;
        num_elements_ = extract_data_range(datafilename, minval_, maxval, delta_);

        // initialize the partitions
        distributing_factory::result_type results = future.get();
        distributing_factory::iterator_range_type parts =
            hpx::util::locality_results(results);

        for (hpx::naming::id_type const& id : parts)
            partitions_.push_back(id);

        std::size_t num_localities = partitions_.size();
        HPX_ASSERT(0 != num_localities);

        std::size_t partition_size = num_elements_ / num_localities;
        std::size_t last_partition_size =
            num_elements_ - partition_size * (num_localities-1);

        for (std::size_t i = 0; i != num_localities; ++i)
        {
            dimension dim;
            if (i == num_localities-1) {
                dim.offset_ = partition_size * i;
                dim.count_ = last_partition_size;
                dim.size_ = num_elements_;
            }
            else {
                dim.offset_ = partition_size * i;
                dim.count_ = partition_size;
                dim.size_ = num_elements_;
            }
            stubs::partition::init(partitions_[i], datafilename, dim,
                num_localities);
        }
    }
示例#4
0
文件: partition.cpp 项目: whchung/hpx
    void partition::init(std::string datafilename, dimension const& dim,
        std::size_t num_nodes)
    {
        // store all parameters
        dim_ = dim;

        // account for necessary overlap
        std::size_t ghost_width_left = 0, ghost_width_right = 0;
        if (dim_.offset_ + dim_.count_ < dim_.size_-1)
            ++ghost_width_right;

        if (dim_.offset_ > 0)
            ++ghost_width_left;

        // extract the full data range
        extract_data_range(datafilename, min_value_, max_value_, delta_,
            dim_.offset_, dim_.offset_+dim_.count_);

        // read the slice of our data
        values_.reset(new double[dim_.count_ + ghost_width_left + ghost_width_right]);
        extract_data(datafilename, values_.get(),
            dim_.offset_ - ghost_width_left,
            dim_.count_ + ghost_width_left + ghost_width_right);
    }
示例#5
0
    void interpolator::fill_partitions(std::string const& datafilename,
        std::string symbolic_name_base, async_create_result_type future)
    {
        // Read required data from file.
        num_values_[dimension::ye] = extract_data_range(datafilename,
            "ye", minval_[dimension::ye], maxval_[dimension::ye],
            delta_[dimension::ye]);
        num_values_[dimension::temp] = extract_data_range(datafilename,
            "logtemp", minval_[dimension::temp], maxval_[dimension::temp],
            delta_[dimension::temp]);
        num_values_[dimension::rho] = extract_data_range(datafilename,
            "logrho", minval_[dimension::rho], maxval_[dimension::rho],
            delta_[dimension::rho]);

        // Wait for the partitions to be created.
        distributing_factory::result_type results = future.get();
        distributing_factory::iterator_range_type parts =
            hpx::util::locality_results(results);

        for (hpx::naming::id_type id : parts)
        {
            std::cout << "Partition " << partitions_.size() << ": " << id << "\n";
            partitions_.push_back(id);
        }

        // Initialize all attached partition objects.
        std::size_t num_localities = partitions_.size();
        HPX_ASSERT(0 != num_localities);

        num_partitions_per_dim_ = static_cast<std::size_t>(
            std::exp(std::log(double(num_localities)) / 3));

        std::size_t partition_size_x =
            num_values_[dimension::ye] / num_partitions_per_dim_;
        std::size_t last_partition_size_x = num_values_[dimension::ye] -
            partition_size_x * (num_partitions_per_dim_-1);

        std::size_t partition_size_y =
            num_values_[dimension::temp] / num_partitions_per_dim_;
        std::size_t last_partition_size_y = num_values_[dimension::temp] -
            partition_size_y * (num_partitions_per_dim_-1);

        std::size_t partition_size_z =
            num_values_[dimension::rho] / num_partitions_per_dim_;
        std::size_t last_partition_size_z = num_values_[dimension::rho] -
            partition_size_z * (num_partitions_per_dim_-1);

        dimension dim_x(num_values_[dimension::ye]);
        dimension dim_y(num_values_[dimension::temp]);
        dimension dim_z(num_values_[dimension::rho]);

        std::vector<hpx::lcos::future<void> > lazy_sync;
        for (std::size_t x = 0; x != num_partitions_per_dim_; ++x)
        {
            dim_x.offset_ = partition_size_x * x;
            if (x == num_partitions_per_dim_-1)
                dim_x.count_ = last_partition_size_x;
            else
                dim_x.count_ = partition_size_x;

            for (std::size_t y = 0; y != num_partitions_per_dim_; ++y)
            {
                dim_y.offset_ = partition_size_y * y;
                if (y == num_partitions_per_dim_-1)
                    dim_y.count_ = last_partition_size_y;
                else
                    dim_y.count_ = partition_size_y;

                for (std::size_t z = 0; z != num_partitions_per_dim_; ++z)
                {
                    dim_z.offset_ = partition_size_z * z;
                    if (z == num_partitions_per_dim_-1)
                        dim_z.count_ = last_partition_size_z;
                    else
                        dim_z.count_ = partition_size_z;

                    std::size_t index =
                        x + (y + z * num_partitions_per_dim_) * num_partitions_per_dim_;
                    HPX_ASSERT(index < partitions_.size());

                    lazy_sync.push_back(stubs::partition3d::init_async(
                        partitions_[index], datafilename, dim_x, dim_y, dim_z));
                }
            }
        }

        // Create the config object locally.
        hpx::naming::id_type config_id =
            hpx::find_locality(configuration::get_component_type());
        cfg_ = configuration(config_id, datafilename, symbolic_name_base,
            num_localities);
        hpx::agas::register_name(symbolic_name_base, cfg_.get_id());

        if (symbolic_name_base[symbolic_name_base.size() - 1] != '/')
            symbolic_name_base += "/";

        std::size_t i = 0;

        // Register symbolic names of all involved components.
        for (hpx::naming::id_type const& id : partitions_)
        {
            hpx::agas::register_name(
                symbolic_name_base + std::to_string(i++),
                id);
        }

        // Wait for initialization to finish.
        hpx::wait_all(lazy_sync);
    }