-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,823 changed files
with
3,264,802 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
tags/v1.9.1/html/_downloads/01237b2a90614802ab4171dda000dc11/accumulator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
139 changes: 139 additions & 0 deletions
139
tags/v1.9.1/html/_downloads/15487131c52c6487f27ab78c60499d37/1d_stencil_1.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
115 changes: 115 additions & 0 deletions
115
tags/v1.9.1/html/_downloads/1bbb2fb52e13275836c343488653ecb9/accumulator.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.