Skip to content

Commit

Permalink
Manually pushing release docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Aug 5, 2023
1 parent b9adfa3 commit 3afd29d
Show file tree
Hide file tree
Showing 1,823 changed files with 3,264,802 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2011 Bryce Adelstein-Lelbach
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/config.hpp>
#if !defined(HPX_COMPUTE_DEVICE_CODE)
#include <hpx/hpx.hpp>

#include "server/accumulator.hpp"

//[accumulator_registration_definitions
///////////////////////////////////////////////////////////////////////////////
// Add factory registration functionality.
HPX_REGISTER_COMPONENT_MODULE()

///////////////////////////////////////////////////////////////////////////////
typedef hpx::components::component<examples::server::accumulator>
accumulator_type;

HPX_REGISTER_COMPONENT(accumulator_type, accumulator)

///////////////////////////////////////////////////////////////////////////////
// Serialization support for accumulator actions.
HPX_REGISTER_ACTION(
accumulator_type::wrapped_type::reset_action, accumulator_reset_action)
HPX_REGISTER_ACTION(
accumulator_type::wrapped_type::add_action, accumulator_add_action)
HPX_REGISTER_ACTION(
accumulator_type::wrapped_type::query_action, accumulator_query_action)
//]

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright (c) 2014 Hartmut Kaiser
// Copyright (c) 2014 Patricia Grubel
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// This is the first in a series of examples demonstrating the development of a
// fully distributed solver for a simple 1D heat distribution problem.
//
// This example provides a serial base line implementation. No parallelization
// is performed.

#include <hpx/chrono.hpp>
#include <hpx/init.hpp>

#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

#include "print_time_results.hpp"

///////////////////////////////////////////////////////////////////////////////
// Command-line variables
bool header = true; // print csv heading
double k = 0.5; // heat transfer coefficient
double dt = 1.; // time step
double dx = 1.; // grid spacing

///////////////////////////////////////////////////////////////////////////////
//[stepper_1
struct stepper
{
// Our partition type
typedef double partition;

// Our data for one time step
typedef std::vector<partition> space;

// Our operator
static double heat(double left, double middle, double right)
{
return middle + (k * dt / (dx * dx)) * (left - 2 * middle + right);
}

// do all the work on 'nx' data points for 'nt' time steps
space do_work(std::size_t nx, std::size_t nt)
{
// U[t][i] is the state of position i at time t.
std::vector<space> U(2);
for (space& s : U)
s.resize(nx);

// Initial conditions: f(0, i) = i
for (std::size_t i = 0; i != nx; ++i)
U[0][i] = double(i);

// Actual time step loop
for (std::size_t t = 0; t != nt; ++t)
{
space const& current = U[t % 2];
space& next = U[(t + 1) % 2];

next[0] = heat(current[nx - 1], current[0], current[1]);

for (std::size_t i = 1; i != nx - 1; ++i)
next[i] = heat(current[i - 1], current[i], current[i + 1]);

next[nx - 1] = heat(current[nx - 2], current[nx - 1], current[0]);
}

// Return the solution at time-step 'nt'.
return U[nt % 2];
}
};
//]
///////////////////////////////////////////////////////////////////////////////
int hpx_main(hpx::program_options::variables_map& vm)
{
std::uint64_t nx =
vm["nx"].as<std::uint64_t>(); // Number of grid points.
std::uint64_t nt = vm["nt"].as<std::uint64_t>(); // Number of steps.

if (vm.count("no-header"))
header = false;

// Create the stepper object
stepper step;

// Measure execution time.
std::uint64_t t = hpx::chrono::high_resolution_clock::now();

// Execute nt time steps on nx grid points.
stepper::space solution = step.do_work(nx, nt);

// Print the final solution
if (vm.count("results"))
{
for (std::size_t i = 0; i != nx; ++i)
std::cout << "U[" << i << "] = " << solution[i] << std::endl;
}

std::uint64_t elapsed = hpx::chrono::high_resolution_clock::now() - t;

std::uint64_t const os_thread_count = hpx::get_os_thread_count();
print_time_results(os_thread_count, elapsed, nx, nt, header);

return hpx::local::finalize();
}

int main(int argc, char* argv[])
{
namespace po = hpx::program_options;

// clang-format off
po::options_description desc_commandline;
desc_commandline.add_options()
("results", "print generated results (default: false)")
("nx", po::value<std::uint64_t>()->default_value(100),
"Local x dimension")
("nt", po::value<std::uint64_t>()->default_value(45),
"Number of time steps")
("k", po::value<double>(&k)->default_value(0.5),
"Heat transfer coefficient (default: 0.5)")
("dt", po::value<double>(&dt)->default_value(1.0),
"Timestep unit (default: 1.0[s])")
("dx", po::value<double>(&dx)->default_value(1.0),
"Local x dimension")
( "no-header", "do not print out the csv header row")
;
// clang-format on

// Initialize and run HPX
hpx::local::init_params init_args;
init_args.desc_cmdline = desc_commandline;

return hpx::local::init(hpx_main, argc, argv, init_args);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2011 Bryce Adelstein-Lelbach
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <hpx/config.hpp>
#if !defined(HPX_COMPUTE_DEVICE_CODE)
#include <hpx/hpx.hpp>
#include <hpx/include/actions.hpp>
#include <hpx/include/components.hpp>

#include <cstdint>

///////////////////////////////////////////////////////////////////////////////
namespace examples { namespace server {
///////////////////////////////////////////////////////////////////////////
/// This class is a very simple example of an HPX component. An HPX
/// component is a class that:
///
/// * Inherits from a component base class:
/// \a hpx::components::component_base
/// * Exposes methods that can be called asynchronously and/or remotely.
/// These constructs are known as HPX actions.
///
/// By deriving this component from \a locking_hook the runtime system
/// ensures that all action invocations are serialized. That means that
/// the system ensures that no two actions are invoked at the same time on
/// a given component instance. This makes the component thread safe and no
/// additional locking has to be implemented by the user.
///
/// Components are first-class objects in HPX. This means that they are
/// globally addressable; all components have a unique GID.
///
/// This example demonstrates how to write a simple component. Simple
/// components are allocated one at a time with the C++'s new allocator.
/// When a component needs to be created in small quantities, simple
/// components should be used. At least two AGAS requests will be made when
/// a simple component is created.
///
/// This component exposes 3 different actions: reset, add and query.
//[accumulator_server_inherit
class accumulator
: public hpx::components::locking_hook<
hpx::components::component_base<accumulator>>
//]
{
public:
typedef std::int64_t argument_type;

//[accumulator_server_ctor
accumulator()
: value_(0)
{
}
//]

///////////////////////////////////////////////////////////////////////
// Exposed functionality of this component.

//[accumulator_methods
/// Reset the components value to 0.
void reset()
{
// set value_ to 0.
value_ = 0;
}

/// Add the given number to the accumulator.
void add(argument_type arg)
{
// add value_ to arg, and store the result in value_.
value_ += arg;
}

/// Return the current value to the caller.
argument_type query() const
{
// Get the value of value_.
return value_;
}
//]

///////////////////////////////////////////////////////////////////////
// Each of the exposed functions needs to be encapsulated into an
// action type, generating all required boilerplate code for threads,
// serialization, etc.
//[accumulator_action_types
HPX_DEFINE_COMPONENT_ACTION(accumulator, reset)
HPX_DEFINE_COMPONENT_ACTION(accumulator, add)
HPX_DEFINE_COMPONENT_ACTION(accumulator, query)
//]

private:
//[accumulator_server_data_member
argument_type value_;
//]
};
}} // namespace examples::server

//[accumulator_registration_declarations
HPX_REGISTER_ACTION_DECLARATION(
examples::server::accumulator::reset_action, accumulator_reset_action)

HPX_REGISTER_ACTION_DECLARATION(
examples::server::accumulator::add_action, accumulator_add_action)

HPX_REGISTER_ACTION_DECLARATION(
examples::server::accumulator::query_action, accumulator_query_action)
//]

#endif
Loading

0 comments on commit 3afd29d

Please sign in to comment.