Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <hpx/hpx_main.hpp>
- #include <hpx/include/lcos.hpp>
- #include <hpx/include/actions.hpp>
- #include <hpx/include/components.hpp>
- #include <hpx/include/iostreams.hpp>
- #include <boost/format.hpp>
- #include <cstddef>
- #include <list>
- #include <mutex>
- #include <set>
- #include <vector>
- #include "../../common.h"
- std::size_t ep_worker(std::size_t desired)
- {
- int i;
- double *a = (double *) malloc( n * sizeof(double));
- double *b = (double *) malloc( n * sizeof(double));
- double *c = (double *) malloc( n * sizeof(double));
- /* fill it with random */
- for( i = 0; i < n; i++ ) {
- a[i] = rand() % 10;
- b[i] = rand() % 10;
- }
- for( i = 0; i < n; i++ ) {
- c[i] = a[i] * b[i];
- }
- free(a);
- free(b);
- free(c);
- return desired;
- }
- HPX_PLAIN_ACTION(ep_worker, ep_worker_action);
- void ep_foreman()
- {
- std::size_t const os_threads = hpx::get_os_thread_count();
- cores = os_threads;
- hpx::naming::id_type const here = hpx::find_here();
- std::set<std::size_t> attendance;
- for (std::size_t os_thread = 0; os_thread < os_threads; ++os_thread)
- attendance.insert(os_thread);
- while (!attendance.empty())
- {
- std::vector<hpx::lcos::future<std::size_t> > futures;
- futures.reserve(attendance.size());
- for (std::size_t worker : attendance)
- {
- typedef ep_worker_action action_type;
- int i, total_tasks = 100000;
- for( i = 0; i < total_tasks/attendance.size(); i++ ) {
- futures.push_back(hpx::async<action_type>(here, worker));
- }
- }
- hpx::lcos::local::spinlock mtx;
- hpx::lcos::wait_each(
- hpx::util::unwrapped([&](std::size_t t) {
- if (std::size_t(-1) != t)
- {
- std::lock_guard<hpx::lcos::local::spinlock> lk(mtx);
- attendance.erase(t);
- }
- }),
- futures);
- }
- }
- HPX_PLAIN_ACTION(ep_foreman, ep_foreman_action);
- int main(int argc, char **argv)
- {
- cores = 1;
- n = 1000;
- total_tasks = 1000;
- process_input(&argc, &argv, 3);
- std::vector<hpx::naming::id_type> localities =
- hpx::find_all_localities();
- std::vector<hpx::lcos::future<void> > futures;
- futures.reserve(localities.size());
- for (hpx::naming::id_type const& node : localities)
- {
- typedef ep_foreman_action action_type;
- futures.push_back(hpx::async<action_type>(node));
- }
- START_TIMER;
- hpx::wait_all(futures);
- /* stop timer */
- STOP_TIMER_AND_PRINT(("Cores: %d Tasks: %d\tn: %d\n", cores, total_tasks, n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement