New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Sierpinski Triangle example #2012
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0a198d3
Added Sierpinski example
satyaki3794 2451274
Added dependencies for sierpinski in Makefile
satyaki3794 59dea53
Merge branch 'master' into sierpinski
satyaki3794 5607fcf
Added copyright and Boost license info
satyaki3794 fa301af
Modified code to adhere to HPX guidelines
satyaki3794 e4fd5d5
Merge branch 'sierpinski' of https://github.com/satyaki3794/hpx into …
satyaki3794 0bf77b5
Merge branch 'master' into sierpinski
satyaki3794 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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,122 @@ | ||
# Copyright (c) 2007-2015 Hartmut Kaiser | ||
# Copyright (c) 2011 Bryce Adelstein-Lelbach | ||
# | ||
# 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) | ||
|
||
set(example_programs | ||
allow_unknown_options | ||
component_ctors | ||
component_in_executable | ||
component_inheritance | ||
component_with_executor | ||
composable_guard | ||
customize_async | ||
data_actions | ||
error_handling | ||
event_synchronization | ||
factorial | ||
fibonacci | ||
fibonacci_await | ||
fibonacci_one | ||
fibonacci_futures | ||
fibonacci_futures_distributed | ||
fractals | ||
fractals_struct | ||
safe_object | ||
sierpinski | ||
interest_calculator | ||
interval_timer | ||
latch_local | ||
latch_remote | ||
non_atomic_rma | ||
partitioned_vector_spmd_foreach | ||
pingpong | ||
print_to_console | ||
quicksort | ||
shared_mutex | ||
simple_future_continuation | ||
simplest_hello_world | ||
timed_futures | ||
timed_wake | ||
use_main_thread | ||
wait_composition | ||
zerocopy_rdma | ||
) | ||
|
||
set(allow_unknown_options_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(component_in_executable_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(component_ctors_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(component_inheritance_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(component_with_executor_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(customize_async_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(event_synchronization_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(error_handling_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(fractals_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(interval_timer_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(partitioned_vector_spmd_foreach_FLAGS | ||
COMPONENT_DEPENDENCIES iostreams partitioned_vector) | ||
set(pingpong_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(shared_mutex_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(simplest_hello_world_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(simple_future_continuation_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(timed_futures_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
|
||
if(HPX_HAVE_LOCAL_SCHEDULER OR HPX_HAVE_ALL_SCHEDULERS) | ||
set(example_programs ${example_programs} | ||
fractals_executor | ||
) | ||
set(fractals_executor_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
endif() | ||
|
||
if(HPX_WITH_CXX11_LAMBDAS) | ||
set(example_programs ${example_programs} | ||
1d_wave_equation | ||
hello_world | ||
fibonacci_dataflow | ||
pipeline1 | ||
vector_counting_dotproduct | ||
vector_zip_dotproduct | ||
) | ||
|
||
set(1d_wave_equation_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
if(HPX_HAVE_COMPRESSION_SNAPPY AND SNAPPY_FOUND) | ||
set(hello_world_FLAGS COMPONENT_DEPENDENCIES iostreams DEPENDENCIES compress_snappy_lib) | ||
else() | ||
set(hello_world_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
endif() | ||
set(vector_counting_dotproduct_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
set(vector_zip_dotproduct_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
endif() | ||
|
||
if(HPX_WITH_TUPLE_RVALUE_SWAP) | ||
set(example_programs ${example_programs} | ||
sort_by_key_demo | ||
) | ||
set(sort_by_key_demo_FLAGS COMPONENT_DEPENDENCIES iostreams) | ||
endif() | ||
|
||
foreach(example_program ${example_programs}) | ||
set(sources | ||
${example_program}.cpp) | ||
|
||
source_group("Source Files" FILES ${sources}) | ||
|
||
# add example executable | ||
add_hpx_executable(${example_program} | ||
SOURCES ${sources} | ||
${${example_program}_FLAGS} | ||
FOLDER "Examples/Quickstart") | ||
|
||
# add a custom target for this example | ||
add_hpx_pseudo_target(examples.quickstart.${example_program}) | ||
|
||
# make pseudo-targets depend on master pseudo-target | ||
add_hpx_pseudo_dependencies(examples.quickstart | ||
examples.quickstart.${example_program}) | ||
|
||
# add dependencies to pseudo-target | ||
add_hpx_pseudo_dependencies(examples.quickstart.${example_program} | ||
${example_program}_exe) | ||
endforeach() | ||
|
||
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,130 @@ | ||
|
||
// http://www.wikiwand.com/en/Sierpinski_triangle | ||
// At each iteration, a white triangle in deleted from the middle of every black triangle, | ||
// thereby splitting it into three equal triangles. | ||
|
||
// Takes two program options, the number of iterations (n-value, with default 5) | ||
// and the side length of the original triangle (side-length, with default 100) | ||
|
||
|
||
#include <hpx/hpx_init.hpp> | ||
#include <hpx/include/actions.hpp> | ||
#include <hpx/include/async.hpp> | ||
#include <hpx/include/util.hpp> | ||
#include <hpx/include/iostreams.hpp> | ||
#include <hpx/include/serialization.hpp> | ||
|
||
#include <iostream> | ||
|
||
#include <boost/cstdint.hpp> | ||
#include <boost/format.hpp> | ||
|
||
// Class representing a Sierpinski triangle | ||
class sierpinski{ | ||
|
||
public: | ||
boost::uint64_t black_triangles, white_triangles; | ||
double area; | ||
|
||
sierpinski(){} | ||
sierpinski(boost::uint64_t black, boost::uint64_t white, double area){ | ||
this->black_triangles = black; | ||
this->white_triangles = white; | ||
this->area = area; | ||
} | ||
|
||
inline sierpinski operator+(const sierpinski& other) const { | ||
sierpinski res = sierpinski (black_triangles+other.black_triangles, white_triangles+other.white_triangles, area+other.area); | ||
return res; | ||
} | ||
|
||
|
||
private: | ||
|
||
//Serialization is necessary to transmit objects from one locality to another | ||
friend class hpx::serialization::access; | ||
template <class Archive> | ||
void serialize(Archive & ar, const unsigned int version) | ||
{ | ||
ar & black_triangles; | ||
ar & white_triangles; | ||
ar & area; | ||
} | ||
}; | ||
|
||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// forward declaration of the get_sierpinski function | ||
sierpinski get_sierpinski(boost::uint64_t n, double len); | ||
|
||
|
||
// This is to generate the required boilerplate we need for the remote | ||
// invocation to work. | ||
HPX_PLAIN_ACTION(get_sierpinski, get_sierpinski_action); | ||
|
||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
sierpinski get_sierpinski(boost::uint64_t n, double len) | ||
{ | ||
if (n == 0) | ||
return sierpinski(1, 0, sqrt(3)/4.0*len*len); | ||
|
||
hpx::naming::id_type const locality_id = hpx::find_here(); | ||
|
||
// The problem for iteration n is broken down into three sub-problems, | ||
// each of size n-1 (and side length gets halved). It is very inefficient as it does the same calculations | ||
// three times but this is the method used for the sake of using parallelization. | ||
|
||
get_sierpinski_action s; | ||
hpx::future<sierpinski> n1 = hpx::async(s, locality_id, n - 1, len/2); | ||
hpx::future<sierpinski> n2 = hpx::async(s, locality_id, n - 1, len/2); | ||
hpx::future<sierpinski> n3 = hpx::async(s, locality_id, n - 1, len/2); | ||
|
||
sierpinski ans = n1.get() + n2.get() + n3.get(); | ||
ans.white_triangles++; | ||
return ans; | ||
} | ||
|
||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
int hpx_main(boost::program_options::variables_map& vm) | ||
{ | ||
boost::uint64_t n = vm["n-value"].as<boost::uint64_t>(); | ||
boost::uint64_t len = vm["side-length"].as<boost::uint64_t>(); | ||
|
||
{ | ||
get_sierpinski_action s; | ||
sierpinski ans = s(hpx::find_here(), n, (double)len); | ||
|
||
hpx::cout << "After iteration: " << n << hpx::endl; | ||
hpx::cout << "Black triangles: " << ans.black_triangles << hpx::endl; | ||
hpx::cout << "White triangles: " << ans.white_triangles << hpx::endl; | ||
hpx::cout << "Area: " << ans.area << hpx::endl; | ||
} | ||
|
||
return hpx::finalize(); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
int main(int argc, char* argv[]) | ||
{ | ||
// Configure application-specific options | ||
boost::program_options::options_description | ||
desc_commandline("Usage: " HPX_APPLICATION_STRING " [options]"); | ||
|
||
desc_commandline.add_options() | ||
( "n-value", | ||
boost::program_options::value<boost::uint64_t>()->default_value(5), | ||
"n value for the Sierpinski function") | ||
; | ||
desc_commandline.add_options() | ||
( "side-length", | ||
boost::program_options::value<boost::uint64_t>()->default_value(100), | ||
"side-length of the original triangle") | ||
; | ||
|
||
return hpx::init(desc_commandline, argc, argv); | ||
} | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was added by accident