int hpx_main(variables_map& vm)
{
    int test;
    std::string inputFile;

    inputFile = vm["input"].as<std::string>();
    {
        id_type prefix = get_applier().get_runtime_support_gid();

        bhcontroller dat;

        dat.create(prefix);
        test = dat.construct(inputFile);
        if(test == 0){
            dat.run_simulation();
        }
        dat.free();

//        std::cout << (boost::format("total error   : %1%\n"
//                                    "average error : %2%\n")
//                     % r % (r / size));  
    }

    finalize();
    std::cout<<"OH YEAH!\n";
    return 0;
}
int hpx_main(variables_map& vm)
{
    {
        boost::uint64_t n = vm["n-value"].as<boost::uint64_t>();

        const id_type prefix = get_applier().get_runtime_support_gid();

        high_resolution_timer t;

        jacobsthal_future f(prefix, prefix, n);

        bigint r = f.get();

        double elapsed = t.elapsed();

        std::cout
            << ( boost::format("jacobsthal(%1%) == %2%\n"
                               "elapsed time == %3%\n")
               % n % r % elapsed);
    }

    finalize();

    return 0;
}
int hpx_main(
    variables_map& vm
    )
{
    if (vm.count("no-header"))
        header = false;

    {
        if (0 == tasks)
            throw std::invalid_argument("count of 0 tasks specified\n");

        // Start the clock.
        high_resolution_timer t;

        for (boost::uint64_t i = 0; i < tasks; ++i)
            register_work(HPX_STD_BIND(&invoke_worker, delay));

        // Reschedule hpx_main until all other hpx-threads have finished. We
        // should be resumed after most of the null px-threads have been
        // executed. If we haven't, we just reschedule ourselves again.
        do {
            suspend();
        } while (get_thread_count(hpx::threads::thread_priority_normal) > 1);

        print_results(get_os_thread_count(), t.elapsed());
    }

    return finalize();
}
int hpx_main(variables_map& vm)
{
    {
        boost::uint64_t m = vm["m-value"].as<boost::uint64_t>()
                      , n = vm["n-value"].as<boost::uint64_t>();

        const id_type prefix = get_applier().get_runtime_support_gid();

        high_resolution_timer t;

        ackermann_peter_future f(prefix, prefix, m, n);

        boost::uint64_t r = f.get();

        double elapsed = t.elapsed();

        std::cout
            << ( boost::format("ackermann_peter(%1%, %2%) == %3%\n"
                               "elapsed time == %4%\n")
               % m % n % r % elapsed);
    }

    finalize();

    return 0;
}
Exemple #5
0
int hpx_main(variables_map& vm)
{
    boost::uint64_t const futures = vm["futures"].as<boost::uint64_t>();
    boost::uint64_t const grain_size = vm["grain-size"].as<boost::uint64_t>();

    {
        thread_id_type thread_id = register_thread_nullary(
            boost::bind(&test_dummy_thread, futures));
        HPX_TEST(thread_id != hpx::threads::invalid_thread_id);

        // Flood the queues with suspension operations before the rescheduling
        // attempt.
        unique_future<void> before = async(&tree_boot, futures, grain_size, thread_id);

        set_thread_state(thread_id, pending, wait_signaled);

        // Flood the queues with suspension operations after the rescheduling
        // attempt.
        unique_future<void> after = async(&tree_boot, futures, grain_size, thread_id);

        before.get();
        after.get();

        set_thread_state(thread_id, pending, wait_terminate);
    }

    finalize();

    return 0;
}
int hpx_main(variables_map& vm)
{
    unsigned int size(0), allocblock(0), blocksize(0);

    size = vm["size"].as<unsigned int>();
    allocblock = vm["allocblock"].as<unsigned int>();
    blocksize = vm["blocksize"].as<unsigned int>();
    {
        id_type prefix = get_applier().get_runtime_support_gid();

        smphplmatrex dat;

        dat.create(prefix);
        dat.construct(size, allocblock, blocksize);

        double r = dat.LUsolve();

        dat.free();

        std::cout << (boost::format("total error   : %1%\n"
                                    "average error : %2%\n")
                     % r % (r / size));
    }

    finalize();
    return 0;
}
int hpx_main(variables_map& vm)
{
    std::size_t pxthreads = 0;

    if (vm.count("pxthreads"))
        pxthreads = vm["pxthreads"].as<std::size_t>();
    
    std::size_t iterations = 0;

    if (vm.count("iterations"))
        iterations = vm["iterations"].as<std::size_t>();

    std::size_t suspend_duration = 0;

    if (vm.count("suspend-duration"))
        suspend_duration = vm["suspend-duration"].as<std::size_t>();

    {
        barrier b(pxthreads + 1);

        // Create the hpx-threads.
        for (std::size_t i = 0; i < pxthreads; ++i)
            register_work(boost::bind
                (&suspend_test, boost::ref(b), iterations, suspend_duration));

        b.wait(); // Wait for all hpx-threads to enter the barrier.
    }

    // Initiate shutdown of the runtime system.
    return finalize();
}
int hpx_main(variables_map& vm)
{
    boost::uint64_t const futures = vm["futures"].as<boost::uint64_t>();
    boost::uint64_t const grain_size = vm["grain-size"].as<boost::uint64_t>();

    {
        id_type const prefix = find_here();

        thread_id_type thread_id = register_thread_nullary
            (boost::bind(&test_dummy_thread, futures));
        boost::uint64_t thread = boost::uint64_t(thread_id);

        // Flood the queues with suspension operations before the rescheduling
        // attempt.
        future<void> before =
            async<tree_boot_action>(prefix, futures, grain_size, prefix, thread);

        set_thread_state(thread_id, pending, wait_signaled);

        // Flood the queues with suspension operations after the rescheduling
        // attempt.
        future<void> after =
            async<tree_boot_action>(prefix, futures, grain_size, prefix, thread);

        before.get();
        after.get();

        set_thread_state(thread_id, pending, wait_terminate);
    }

    finalize();

    return 0;
}
Exemple #9
0
int hpx_main(variables_map& vm)
{
    std::size_t pxthreads = 0;

    if (vm.count("pxthreads"))
        pxthreads = vm["pxthreads"].as<std::size_t>();

    std::size_t iterations = 0;

    if (vm.count("iterations"))
        iterations = vm["iterations"].as<std::size_t>();

    for (std::size_t i = 0; i < iterations; ++i)
    {
        // create a barrier waiting on 'count' threads
        barrier b(pxthreads + 1);

        boost::atomic<std::size_t> c(0);

        // create the threads which will wait on the barrier
        for (std::size_t i = 0; i < pxthreads; ++i)
            register_work(hpx::util::bind
                (&local_barrier_test, std::ref(b), std::ref(c)));

        b.wait(); // wait for all threads to enter the barrier
        HPX_TEST_EQ(pxthreads, c);
    }

    // initiate shutdown of the runtime system
    finalize();
    return 0;
}
int hpx_main(
    variables_map& vm
    )
{
    if (vm.count("no-header"))
        header = false;

    std::size_t num_os_threads = hpx::get_os_thread_count();

    int num_executors = vm["executors"].as<int>();
    if (num_executors <= 0)
        throw std::invalid_argument("number of executors to use must be larger than 0");

    if (std::size_t(num_executors) > num_os_threads)
        throw std::invalid_argument("number of executors to use must be \
                                        smaller than number of OS threads");

    std::size_t num_cores_per_executor = vm["cores"].as<int>();

    if ((num_executors - 1) * num_cores_per_executor > num_os_threads)
        throw std::invalid_argument("number of cores per executor should not \
                                     cause oversubscription");

    if (0 == tasks)
        throw std::invalid_argument("count of 0 tasks specified\n");

    // Start the clock.
    high_resolution_timer t;

    // create the executor instances
    using hpx::threads::executors::local_priority_queue_executor;

    {
        std::vector<local_priority_queue_executor> executors;
        for (std::size_t i = 0; i != std::size_t(num_executors); ++i)
        {
            // make sure we don't oversubscribe the cores, the last executor will
            // be bound to the remaining number of cores
            if ((i + 1) * num_cores_per_executor > num_os_threads)
            {
                HPX_ASSERT(i == std::size_t(num_executors) - 1);
                num_cores_per_executor = num_os_threads - i * num_cores_per_executor;
            }
            executors.push_back(local_priority_queue_executor(num_cores_per_executor));
        }

        t.restart();

        // schedule normal threads
        for (boost::uint64_t i = 0; i < tasks; ++i)
            executors[i % num_executors].add(
                hpx::util::bind(&worker_timed, delay * 1000));
    // destructors of executors will wait for all tasks to finish executing
    }

    print_results(num_os_threads, t.elapsed());

    return finalize();
}
Exemple #11
0
int hpx_main(variables_map& vm)
{
  here = find_here();
  pi = boost::math::constants::pi<double>();

  //    dt = vm["dt-value"].as<double>();
  //    dx = vm["dx-value"].as<double>();
  //    c = vm["c-value"].as<double>();
  nx = vm["nx-value"].as<boost::uint64_t>();
  nt = vm["nt-value"].as<boost::uint64_t>();

  c = 1.0;

  dt = 1.0/(nt-1);
  dx = 1.0/(nx-1);
  alpha_squared = (c*dt/dx)*(c*dt/dx);

  // check that alpha_squared satisfies the stability condition
  if (0.25 < alpha_squared)
    {
      cout << (("alpha^2 = (c*dt/dx)^2 should be less than 0.25 for stability!\n"))
          << flush;
    }

  u = std::vector<std::vector<data> >(nt, std::vector<data>(nx));

  cout << (boost::format("dt = %1%\n") % dt) << flush;
  cout << (boost::format("dx = %1%\n") % dx) << flush;
  cout << (boost::format("alpha^2 = %1%\n") % alpha_squared) << flush;

  {
    // Keep track of the time required to execute.
    high_resolution_timer t;

    std::vector<future<double> > futures;
    for (boost::uint64_t i=0;i<nx;i++)
      futures.push_back(async<wave_action>(here,nt-1,i));

    // open file for output
    std::ofstream outfile;
    outfile.open ("output.dat");

    wait(futures, [&](std::size_t i, double n)
         { double x_here = i*dx;
           outfile << (boost::format("%1% %2%\n") % x_here % n) << flush; });

    outfile.close();

    char const* fmt = "elapsed time: %1% [s]\n";
    std::cout << (boost::format(fmt) % t.elapsed());

  }

  finalize();
  return 0;
}
int hpx_main(variables_map&)
{
    test_void_actions();
    test_void_direct_actions();
    test_object_actions();
    test_object_direct_actions();

    finalize();

    return hpx::util::report_errors();
}
Exemple #13
0
int hpx_main(
    variables_map& vm
    )
{
    {
        simple_mobile_object a(hpx::find_here());
        simple_mobile_object b(hpx::find_here());

        id_type a_id = a.get_id();
        gid_type a_gid = get_stripped_gid(a_id.get_gid());
        boost::uint64_t b_lva = b.get_lva();

        // Resolve a_gid.
        address addr = hpx::agas::resolve(a_id).get();

        ///////////////////////////////////////////////////////////////////////
        HPX_TEST_EQ(addr.address_, a.get_lva());
        HPX_SANITY_EQ(hpx::agas::resolve(a_id).get().address_, a.get_lva());

        ///////////////////////////////////////////////////////////////////////
        // Change a's GID to point to b.

        // Rebind the GID.
        boost::uint64_t a_lva = addr.address_;
        addr.address_ = b_lva;
        HPX_TEST(get_agas_client().bind_local(a_gid, addr));

        // Update our AGAS cache.
        get_agas_client().update_cache_entry(a_gid, addr);

        ///////////////////////////////////////////////////////////////////////
        HPX_TEST_EQ(b_lva, a.get_lva());
        HPX_SANITY_EQ(hpx::agas::resolve(a_id).get().address_, a.get_lva());

        ///////////////////////////////////////////////////////////////////////
        // Now we restore the original bindings to prevent a double free.

        // Rebind the GID.
        addr.address_ = a_lva;
        HPX_TEST(get_agas_client().bind_local(a_gid, addr));

        // Update our AGAS cache.
        get_agas_client().update_cache_entry(a_gid, addr);

        ///////////////////////////////////////////////////////////////////////
        HPX_TEST_EQ(hpx::agas::resolve(a_id).get().address_, a_lva);
        HPX_SANITY_EQ(hpx::agas::resolve(a_id).get().address_, a.get_lva());
    }

    finalize();
    return report_errors();
}
Exemple #14
0
int hpx_main(
    variables_map&
    )
{
    {
        const boost::format fmter("%1% %|40t|%2%\n");

        cout << HPX_SIZEOF(hpx::naming::gid_type)
             << HPX_SIZEOF(hpx::naming::id_type)
             << HPX_SIZEOF(hpx::naming::address)
             << flush;
    }

    finalize();
    return 0;
}
Exemple #15
0
int hpx_main(variables_map & vm)
{
    {
        std::size_t nx = vm["nx"].as<std::size_t>();
        std::size_t ny = vm["ny"].as<std::size_t>();
        std::size_t max_iterations = vm["max_iterations"].as<std::size_t>();
        std::size_t line_block = vm["line_block"].as<std::size_t>();

        jacobi::grid u(nx, ny, 1.0);

        jacobi::solver solver(u, nx, line_block);

        solver.run(max_iterations);
    }

    return finalize();
}
Exemple #16
0
int hpx_main(variables_map& vm)
{
    {
        std::cout << "commands: localities, help, quit\n";

        while (true)
        {
            std::cout << "> ";

            std::string arg;
            std::getline(std::cin, arg);

            if (arg.empty())
                continue;

            else if (0 == std::string("quit").find(arg))
                break;

            else if (0 == std::string("localities").find(arg))
            {
                std::vector<id_type> localities = hpx::find_all_localities();

                for (id_type const& locality_ : localities)
                {
                    address addr = hpx::agas::resolve(locality_).get();

                    std::cout << ( boost::format("  [%1%] %2%\n")
                                 % get_locality_id_from_gid(locality_.get_gid())
                                 % addr.locality_);
                }

                continue;
            }

            else if (0 != std::string("help").find(arg))
                std::cout << ( boost::format("error: unknown command '%1%'\n")
                             % arg);

            std::cout << "commands: localities, help, quit\n";
        }
    }

    finalize();
    return 0;
}
Exemple #17
0
int hpx_main(variables_map& vm)
{
    std::size_t pxthreads = 0;

    if (vm.count("pxthreads"))
        pxthreads = vm["pxthreads"].as<std::size_t>();

    std::size_t iterations = 0;

    if (vm.count("iterations"))
        iterations = vm["iterations"].as<std::size_t>();

    for (std::size_t i = 0; i < iterations; ++i)
    {
        event e;

        boost::atomic<std::size_t> c(0);

        std::vector<hpx::future<void> > futs;
        futs.reserve(pxthreads);
        // Create the threads which will wait on the event
        for (std::size_t i = 0; i < pxthreads; ++i)
        {
            futs.push_back(
                hpx::async(&local_event_test, boost::ref(e), boost::ref(c))
            );
        }

        // Release all the threads.
        e.set();

        // Wait for all the our threads to finish executing.
        hpx::wait_all(futs);

        HPX_TEST_EQ(pxthreads, c);

        // Make sure that waiting on a set event works.
        e.wait();
    }

    // Initiate shutdown of the runtime system.
    return finalize();
}
Exemple #18
0
int hpx_main(
    variables_map& vm
    )
{
    {
        num_iterations = vm["delay-iterations"].as<boost::uint64_t>();

        const boost::uint64_t count = vm["futures"].as<boost::uint64_t>();

        if (HPX_UNLIKELY(0 == count))
            throw std::logic_error("error: count of 0 futures specified\n");

        measure_action_futures(count, vm.count("csv") != 0);
        measure_function_futures(count, vm.count("csv") != 0);
    }

    finalize();
    return 0;
}
Exemple #19
0
int hpx_main(variables_map& vm)
{
    boost::uint64_t const futures = vm["futures"].as<boost::uint64_t>();
    boost::uint64_t const grain_size = vm["grain-size"].as<boost::uint64_t>();

    {
        id_type const prefix = find_here();

        thread_id_type thread = register_thread_nullary
            (hpx::util::bind(&test_dummy_thread, futures));

        tree_boot(futures, grain_size, prefix,
            reinterpret_cast<boost::uint64_t>(thread.get()));

        set_thread_state(thread, pending, wait_terminate);
    }

    finalize();

    return 0;
}
Exemple #20
0
int hpx_main(
    variables_map& vm
    )
{
    {
        cout << std::string(80, '#') << "\n"
             << "simple component test\n"
             << std::string(80, '#') << "\n" << flush;

        hpx_test_main<simple_refcnt_monitor>(vm);

        cout << std::string(80, '#') << "\n"
             << "managed component test\n"
             << std::string(80, '#') << "\n" << flush;

        hpx_test_main<managed_refcnt_monitor>(vm);
    }

    finalize();
    return report_errors();
}
Exemple #21
0
int hpx_main(
    variables_map&
    )
{
    {
#       define HPX_SIZEOF(type)                                               \
            hpx::util::format("{1:-40} {2}\n",                                \
                HPX_PP_STRINGIZE(type), sizeof(type))                         \
            /**/

        cout << HPX_SIZEOF(hpx::naming::gid_type)
             << HPX_SIZEOF(hpx::naming::id_type)
             << HPX_SIZEOF(hpx::naming::address)
             << HPX_SIZEOF(hpx::threads::thread_data)
             << flush;

#       undef HPX_SIZEOF
    }

    finalize();
    return 0;
}
int hpx_main(variables_map& vm)
{
    std::size_t num_threads = 1;

    if (vm.count("threads"))
        num_threads = vm["threads"].as<std::size_t>();

    std::size_t pxthreads = 0;

    if (vm.count("pxthreads"))
        pxthreads = vm["pxthreads"].as<std::size_t>();
    
    std::size_t iterations = 0;

    if (vm.count("iterations"))
        iterations = vm["iterations"].as<std::size_t>();

    for (std::size_t i = 0; i < iterations; ++i)
    {
        id_type prefix = get_applier().get_runtime_support_gid();

        // create a barrier waiting on 'count' threads
        barrier b;
        b.create_one(prefix, pxthreads + 1);

        boost::atomic<std::size_t> c(0);

        for (std::size_t j = 0; j < pxthreads; ++j)
            register_work(boost::bind 
                (&barrier_test, b.get_gid(), boost::ref(c), pxthreads));

        b.wait(); // wait for all threads to enter the barrier
        HPX_TEST_EQ(pxthreads, c.load());
    }

    // initiate shutdown of the runtime system
    finalize();
    return 0;
}
Exemple #23
0
int hpx_main(
    variables_map& vm
    )
{
    for (hpx::id_type const& l : hpx::find_all_localities())
    {
        cout << std::string(80, '#') << "\n"
             << "simple component test: " << l << "\n"
             << std::string(80, '#') << "\n" << flush;

        hpx_test_main<simple_object>(vm, l);

        cout << std::string(80, '#') << "\n"
             << "managed component test: " << l << "\n"
             << std::string(80, '#') << "\n" << flush;

        hpx_test_main<managed_object>(vm, l);
    }

    finalize();
    return report_errors();
}
int hpx_main(
    variables_map& vm
    )
{
    if (vm.count("no-header"))
        header = false;

    {
        if (0 == tasks)
            throw std::invalid_argument("count of 0 tasks specified\n");

        if (0 == feeders || feeders > get_os_thread_count())
            throw std::invalid_argument("number of feeders must be between 1 and OS-thread-count\n");

        // Start the clock.
        thread_aware_timer t;

        if (0 == vm.count("no-stack")) {
            for (boost::uint64_t i = 0; i != feeders; ++i)
                register_work(HPX_STD_BIND(&create_tasks, tasks/feeders));
        }
        else {
            for (boost::uint64_t i = 0; i != feeders; ++i)
                register_work(HPX_STD_BIND(&create_stackless_tasks, tasks/feeders));
        }

        // Reschedule hpx_main until all other hpx-threads have finished. We
        // should be resumed after most of the null HPX-threads have been
        // executed. If we haven't, we just reschedule ourselves again.
        do {
            suspend();
        } while (get_thread_count(hpx::threads::thread_priority_normal) > 1);

        print_results(get_os_thread_count(), t.elapsed());
    }

    return finalize();
}
int hpx_main(variables_map& vm)
{
    typedef
        basic_any<hpx::util::portable_binary_iarchive, hpx::util::portable_binary_oarchive>
        any_type;

    {
        std::vector<char> buffer;

        small_object const f(17);
        HPX_TEST_LTE(sizeof(small_object), sizeof(void*));

        any_type any(f);

        out(buffer, any);
        any_type any_in;
        in(buffer, any_in);
        HPX_TEST(!any_in.empty());
        HPX_TEST_EQ(any, any_in);
    }

    {
        std::vector<char> buffer;

        big_object const f(5, 12);
        HPX_TEST_LT(sizeof(void*), sizeof(big_object));

        any_type any(f);

        out(buffer, any);
        any_type any_in;
        in(buffer, any_in);
        HPX_TEST(!any_in.empty());
        HPX_TEST_EQ(any, any_in);
    }

    return finalize();
}
Exemple #26
0
int hpx_main(variables_map& vm)
{
    std::size_t elements = 0;

    if (vm.count("elements"))
        elements = vm["elements"].as<std::size_t>();

    // get list of all known localities
    std::vector<id_type> prefixes = hpx::find_remote_localities();
    id_type prefix;

    // execute the qsort() function on any of the remote localities
    if (!prefixes.empty())
        prefix = prefixes[0];

    // execute the qsort() function locally
    else
      prefix = hpx::find_here();

    {
        // create a (remote) memory block
        memory_block mb;
        mb.create<int, uint8_t>(prefix, elements);
        access_memory_block<int> data(mb.get());

        // randomly fill the vector
        std::generate(data.get_ptr(), data.get_ptr() + elements, std::rand);

        std::cout << "serial quicksort" << std::endl;

        high_resolution_timer t;
        quicksort_serial<int>::call(data.get_ptr(), 0, elements);
        double elapsed = t.elapsed();

        std::cout << "  elapsed=" << elapsed << "\n"
                  << "  count=" << quicksort_serial<int>::sort_count << "\n";

//        int* it = data.get_ptr();
//        int* end = data.get_ptr() + elements;

//        for (; it < end; ++it)
//            std::cout << *it << "\n";

        std::generate(data.get_ptr(), data.get_ptr() + elements, std::rand);

        std::cout << "parallel quicksort" << std::endl;

        t.restart();
        future<void> n = async<quicksort_parallel<int>::action_type>(
            prefix, prefix, mb.get_gid(), 0, elements);
        ::hpx::lcos::wait(n);
        elapsed = t.elapsed();

        std::cout << "  elapsed=" << elapsed << "\n"
                  << "  count=" << quicksort_parallel<int>::sort_count << "\n";

//        it = data.get_ptr();
//        end = data.get_ptr() + elements;

//        for (; it < end; ++it)
//            std::cout << *it << "\n";

        mb.free();
    }

    // initiate shutdown of the runtime systems on all localities
    finalize(1.0);

    return 0;
}
int hpx_main(
    variables_map& vm
    )
{
    if (vm.count("no-header"))
        header = false;

    ///////////////////////////////////////////////////////////////////////////
    // Initialize the PRNG seed.
    if (!seed)
        seed = boost::uint64_t(std::time(0));

    {

        ///////////////////////////////////////////////////////////////////////
        // Validate command-line arguments.
        if (0 == tasks)
            throw std::invalid_argument("count of 0 tasks specified\n");

        if (min_delay > max_delay)
            throw std::invalid_argument("minimum delay cannot be larger than "
                                        "maximum delay\n");

        if (min_delay > total_delay)
            throw std::invalid_argument("minimum delay cannot be larger than"
                                        "total delay\n");

        if (max_delay > total_delay)
            throw std::invalid_argument("maximum delay cannot be larger than "
                                        "total delay\n");

        if ((min_delay * tasks) > total_delay)
            throw std::invalid_argument("minimum delay is too small for the "
                                        "specified total delay and number of "
                                        "tasks\n");

        if ((max_delay * tasks) < total_delay)
            throw std::invalid_argument("maximum delay is too small for the "
                                        "specified total delay and number of "
                                        "tasks\n");

        ///////////////////////////////////////////////////////////////////////
        // Randomly generate a description of the heterogeneous workload.
        std::vector<boost::uint64_t> payloads;
        payloads.reserve(tasks);

        // For random numbers, we use a 64-bit specialization of Boost.Random's
        // mersenne twister engine (good uniform distribution up to 311
        // dimensions, cycle length 2 ^ 19937 - 1)
        boost::random::mt19937_64 prng(seed);

        boost::uint64_t current_sum = 0;

        for (boost::uint64_t i = 0; i < tasks; ++i)
        {
            // Credit to Spencer Ruport for putting this algorithm on
            // stackoverflow.
            boost::uint64_t const low_calc
                = (total_delay - current_sum) - (max_delay * (tasks - 1 - i));

            bool const negative
                = (total_delay - current_sum) < (max_delay * (tasks - 1 - i));

            boost::uint64_t const low
                = (negative || (low_calc < min_delay)) ? min_delay : low_calc;

            boost::uint64_t const high_calc
                = (total_delay - current_sum) - (min_delay * (tasks - 1 - i));

            boost::uint64_t const high
                = (high_calc > max_delay) ? max_delay : high_calc;

            // Our range is [low, high].
            boost::random::uniform_int_distribution<boost::uint64_t>
                dist(low, high);

            boost::uint64_t const payload = dist(prng);

            if (payload < min_delay)
                throw std::logic_error("task delay is below minimum");

            if (payload > max_delay)
                throw std::logic_error("task delay is above maximum");

            current_sum += payload;
            payloads.push_back(payload);
        }

        // Randomly shuffle the entire sequence to deal with drift.
        boost::function<boost::uint64_t(boost::uint64_t)> shuffler_f =
            boost::bind(&shuffler, boost::ref(prng), _1);
        std::random_shuffle(payloads.begin(), payloads.end()
                          , shuffler_f);

        ///////////////////////////////////////////////////////////////////////
        // Validate the payloads.
        if (payloads.size() != tasks)
            throw std::logic_error("incorrect number of tasks generated");

        boost::uint64_t const payloads_sum =
            std::accumulate(payloads.begin(), payloads.end(), 0ULL);
        if (payloads_sum != total_delay)
            throw std::logic_error("incorrect total delay generated");

        ///////////////////////////////////////////////////////////////////////
        // Start the clock.
        high_resolution_timer t;

        ///////////////////////////////////////////////////////////////////////
        // Queue the tasks in a serial loop.
        for (boost::uint64_t i = 0; i < tasks; ++i)
            register_work(HPX_STD_BIND(&invoke_worker, payloads[i]));

        ///////////////////////////////////////////////////////////////////////
        // Wait for the work to finish.
        do {
            // Reschedule hpx_main until all other px-threads have finished. We
            // should be resumed after most of the null px-threads have been
            // executed. If we haven't, we just reschedule ourselves again.
            suspend();
        } while (get_thread_count(hpx::threads::thread_priority_normal) > 1);

        ///////////////////////////////////////////////////////////////////////
        // Print the results.
        print_results(get_os_thread_count(), t.elapsed());
    }

    finalize();
    return 0;
}
Exemple #28
0
int hpx_main(variables_map& vm)
{
    {
        {
            if (sizeof(small_object) <= sizeof(void*))
                std::cout << "object is small\n";
            else
                std::cout << "object is large\n";

            small_object const f(17);

            function<boost::uint64_t(boost::uint64_t const&)> f0(f);

            function<boost::uint64_t(boost::uint64_t const&)> f1(f0);

            function<boost::uint64_t(boost::uint64_t const&)> f2;

            f2 = f0;

            f0(7);
            f1(9);
            f2(11);
        }

        {
            if (sizeof(big_object) <= sizeof(void*))
                std::cout << "object is small\n";
            else
                std::cout << "object is large\n";

            big_object const f(5, 12);

            function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&)> f0(f);

            function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&)> f1(f0);

            function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&)> f2;

            f2 = f0;

            f0(0, 1);
            f1(1, 0);
            f2(1, 1);
        }
    }
    // non serializable version
    {
        {
            if (sizeof(small_object) <= sizeof(void*))
                std::cout << "object is small\n";
            else
                std::cout << "object is large\n";

            small_object const f(17);

            function<boost::uint64_t(boost::uint64_t const&), void, void> f0(f);

            function<boost::uint64_t(boost::uint64_t const&), void, void> f1(f0);

            function<boost::uint64_t(boost::uint64_t const&), void, void> f2;

            f2 = f0;

            f0(2);
            f1(4);
            f2(6);
        }

        {
            if (sizeof(big_object) <= sizeof(void*))
                std::cout << "object is small\n";
            else
                std::cout << "object is large\n";

            big_object const f(5, 12);

            function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&), void, void> f0(f);

            function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&), void, void> f1(f0);

            function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&), void, void> f2;

            f2 = f0;

            f0(3, 4);
            f1(5, 6);
            f2(7, 8);
        }
    }

    finalize();

    return 0;
}
Exemple #29
0
int hpx_main(
    variables_map& vm
    )
{
    {
        if (vm.count("no-header"))
            header = false;

        if (vm.count("csv-header"))
            csv_header = true;

        if (0 == tasks)
            throw std::invalid_argument("count of 0 tasks specified\n");

        if (suspended_tasks > tasks)
            throw std::invalid_argument(
                "suspended tasks must be smaller than tasks\n");

        std::uint64_t const os_thread_count = get_os_thread_count();

        ///////////////////////////////////////////////////////////////////////
        stage_worker_function stage_worker;

        if ("static-balanced-stackbased" == distribution)
            stage_worker = &stage_worker_static_balanced_stackbased;
        else if ("static-imbalanced" == distribution)
            stage_worker = &stage_worker_static_imbalanced;
        else if ("round-robin" == distribution)
            stage_worker = &stage_worker_round_robin;
        else
            throw std::invalid_argument(
                "invalid distribution type specified (valid options are "
                "\"static-balanced\", \"static-imbalanced\" or \"round-robin\")"
                );

        ///////////////////////////////////////////////////////////////////////
        std::uint64_t tasks_per_feeder = 0;
        //std::uint64_t total_tasks = 0;
        std::uint64_t suspended_tasks_per_feeder = 0;
        std::uint64_t total_suspended_tasks = 0;

        if ("strong" == scaling)
        {
            if (tasks % os_thread_count)
                throw std::invalid_argument(
                    "tasks must be cleanly divisable by OS-thread count\n");

            if (suspended_tasks % os_thread_count)
                throw std::invalid_argument(
                    "suspended tasks must be cleanly divisable by OS-thread "
                    "count\n");

            tasks_per_feeder = tasks / os_thread_count;
            //total_tasks      = tasks;
            suspended_tasks_per_feeder = suspended_tasks / os_thread_count;
            total_suspended_tasks      = suspended_tasks;
        }
        else if ("weak" == scaling)
        {
            tasks_per_feeder = tasks;
            //total_tasks      = tasks * os_thread_count;
            suspended_tasks_per_feeder = suspended_tasks;
            total_suspended_tasks      = suspended_tasks * os_thread_count;
        }
        else
            throw std::invalid_argument(
                "invalid scaling type specified (valid options are \"strong\" "
                "or \"weak\")");

        ///////////////////////////////////////////////////////////////////////
        if (suspended_tasks != 0)
        {
            std::uint64_t gcd = boost::math::gcd(tasks_per_feeder
                                                 , suspended_tasks_per_feeder);

            suspend_step = suspended_tasks_per_feeder / gcd;
            // We check earlier to make sure that there are never more
            // suspended tasks than tasks requested.
            no_suspend_step = (tasks_per_feeder / gcd) - suspend_step;
        }

        ///////////////////////////////////////////////////////////////////////
        std::vector<std::string> counter_shortnames;
        std::vector<std::string> counters;
        if (vm.count("counter"))
        {
            std::vector<std::string> raw_counters =
                vm["counter"].as<std::vector<std::string> >();

            for (std::uint64_t i = 0; i < raw_counters.size(); ++i)
            {
                std::vector<std::string> entry;
                boost::algorithm::split(entry, raw_counters[i],
                    boost::algorithm::is_any_of(","),
                    boost::algorithm::token_compress_on);

                HPX_ASSERT(entry.size() == 2);

                counter_shortnames.push_back(entry[0]);
                counters.push_back(entry[1]);
            }
        }

        std::shared_ptr<hpx::util::activate_counters> ac;
        if (!counters.empty())
            ac.reset(new hpx::util::activate_counters(counters));

        ///////////////////////////////////////////////////////////////////////
        // Start the clock.
        high_resolution_timer t;

        if (ac)
            ac->reset_counters();

        // This needs to stay here; we may have suspended as recently as the
        // performance counter reset (which is called just before the staging
        // function).
        std::uint64_t const num_thread = hpx::get_worker_thread_num();

        for (std::uint64_t i = 0; i < os_thread_count; ++i)
        {
            if (num_thread == i) continue;

            register_work(hpx::util::bind(&stage_workers
                                    , i
                                    , tasks_per_feeder
                                    , stage_worker
                                      )
                , "stage_workers"
                , hpx::threads::pending
                , hpx::threads::thread_priority_normal
                , i
                  );
        }

        stage_workers(num_thread, tasks_per_feeder, stage_worker);

        double warmup_estimate = t.elapsed();

        // Schedule a low-priority thread; when it is executed, it checks to
        // make sure all the tasks (which are normal priority) have been
        // executed, and then it
        hpx::lcos::local::barrier finished(2);

        register_work(hpx::util::bind(&wait_for_tasks
                                , std::ref(finished)
                                , total_suspended_tasks
                                 )
            , "wait_for_tasks", hpx::threads::pending
            , hpx::threads::thread_priority_low);

        finished.wait();

        // Stop the clock
        double time_elapsed = t.elapsed();

        print_results(os_thread_count, time_elapsed, warmup_estimate
                    , counter_shortnames, ac);
    }

    if (suspended_tasks != 0)
        // Force termination of all suspended tasks.
        hpx::get_runtime().get_thread_manager().abort_all_suspended_threads();

    return finalize();
}
int hpx_main(variables_map& vm)
{
    bool do_logging = false;

    if (vm.count("verbose"))
        do_logging = true;

    std::size_t timesteps = 0;
    
    if (vm.count("timesteps"))
        timesteps = vm["timesteps"].as<std::size_t>();
        
    std::size_t grain_size = 3;
    if (vm.count("grain-size"))
        grain_size = vm["grain-size"].as<std::size_t>();
    
    std::size_t allowedl = 0;
    if (vm.count("refinement"))
        allowedl = vm["refinement"].as<std::size_t>();
    
    std::size_t nx0 = 0;
    if (vm.count("dimensions"))
        nx0 = vm["dimensions"].as<std::size_t>();

    parameter par;

    // default pars
    par->allowedl       = allowedl;
    par->loglevel       = 2;
    par->output         = 1.0;
    par->output_stdout  = 1;
    par->lambda         = 0.15;
    par->nt0            = timesteps;
    par->minx0          = -15.0;
    par->maxx0          = 15.0;
    par->ethreshold     = 0.005;
    par->R0             = 8.0;
    par->amp            = 0.1;
    par->amp_dot        = 0.1;
    par->delta          = 1.0;
    par->gw             = 5;
    par->eps            = 0.0;
    par->output_level   = 0;
    par->granularity    = grain_size;

    for (std::size_t i = 0; i < HPX_SMP_AMR3D_MAX_LEVELS; i++)
        par->refine_level[i] = 1.5;

    id_type rt_id = get_applier().get_runtime_support_gid();

    section root;
    hpx::components::stubs::runtime_support::get_config(rt_id, root);

    if (root.has_section("smp_amr3d"))
    {
        section pars = *(root.get_section("smp_amr3d"));

        appconfig_option<double>("lambda", pars, par->lambda);
        appconfig_option<std::size_t>("refinement", pars, par->allowedl);
        appconfig_option<std::size_t>("loglevel", pars, par->loglevel);
        appconfig_option<double>("output", pars, par->output);
        appconfig_option<std::size_t>("output_stdout", pars, par->output_stdout);
        appconfig_option<std::size_t>("output_level", pars, par->output_level);
        appconfig_option<std::size_t>("dimensions", pars, nx0);
        appconfig_option<std::size_t>("timesteps", pars, par->nt0);
        appconfig_option<double>("maxx0", pars, par->maxx0);
        appconfig_option<double>("minx0", pars, par->minx0);
        appconfig_option<double>("ethreshold", pars, par->ethreshold);
        appconfig_option<double>("R0", pars, par->R0);
        appconfig_option<double>("delta", pars, par->delta);
        appconfig_option<double>("amp", pars, par->amp);
        appconfig_option<double>("amp_dot", pars, par->amp_dot);
        appconfig_option<std::size_t>("ghostwidth", pars, par->gw);
        appconfig_option<double>("eps", pars, par->eps);
        appconfig_option<std::size_t>("grain_size", pars, par->granularity);

        for (std::size_t i = 0; i < par->allowedl; i++)
        {
            std::string ref_level = "refine_level_"
                                  + lexical_cast<std::string>(i);
            appconfig_option<double>(ref_level, pars, par->refine_level[i]);
        }
    }

    // derived parameters
    if ((nx0 % par->granularity) != 0)
    {
        std::string msg = boost::str(boost::format(
            "dimensions (%1%) must be cleanly divisible by the grain-size "
            "(%2%)") % nx0 % par->granularity);
        HPX_THROW_IN_CURRENT_FUNC(bad_parameter, msg);
    }

    // the number of timesteps each px thread can take independent of
    // communication
    par->time_granularity = par->granularity / 3;
    
    // set up refinement centered around the middle of the grid
    par->nx[0] = nx0 / par->granularity;

    for (std::size_t i = 1; i < (par->allowedl + 1); ++i)
    {
        par->nx[i] = std::size_t(par->refine_level[i - 1] * par->nx[i - 1]);

        if ((par->nx[i] % 2) == 0)
            par->nx[i] += 1;

        if (par->nx[i] > (2 * par->nx[i - 1] - 5))
            par->nx[i] = 2 * par->nx[i - 1] - 5;
    }

    // for each row, record what the lowest level on the row is
    std::size_t num_rows = 1 << par->allowedl;

    // account for prolongation and restriction (which is done every other step)
    if (par->allowedl > 0)
        num_rows += (1 << par->allowedl) / 2;

    num_rows *= 2; // we take two timesteps in the mesh
    par->num_rows = num_rows;

    int ii = -1; 
    for (std::size_t i = 0; i < num_rows; ++i)
    {
        if (((i + 5) % 3) != 0 || (par->allowedl == 0))
            ii++;

        int level = -1;
        for (std::size_t j = par->allowedl; j>=0; --j)
        {
            if ((ii % (1 << j)) == 0)
            {
                level = par->allowedl - j;
                par->level_row.push_back(level);
                break;
            }
        }
    }

    par->dx0 = (par->maxx0 - par->minx0) / (nx0 - 1);
    par->dt0 = par->lambda * par->dx0;

    par->min.resize(par->allowedl + 1);
    par->max.resize(par->allowedl + 1);
    par->min[0] = par->minx0;
    par->max[0] = par->maxx0;
    for (std::size_t i = par->allowedl; i > 0; --i)
    {
        par->min[i] = 0.5 * (par->maxx0 - par->minx0) + par->minx0
            - (par->nx[i] - 1) / 2 * par->dx0 / (1 << i) * par->granularity;
        par->max[i] = par->min[i] + ((par->nx[i] - 1) * par->granularity
                    + par->granularity - 1) * par->dx0 / (1 << i);
    }

    par->rowsize.resize(par->allowedl + 1);
    for (int i = 0; i <= par->allowedl; ++i)
    {
        par->rowsize[i] = 0;
        for (int j = par->allowedl; j >= i; --j)
            par->rowsize[i] += par->nx[j] * par->nx[j] * par->nx[j];
    }
    
    // get component types needed below
    component_type function_type = get_component_type<stencil>();
    component_type logging_type = get_component_type<logging>();

    {
        id_type here = get_applier().get_runtime_support_gid();

        high_resolution_timer t;

        // we are in spherical symmetry, r=0 is the smallest radial domain point
        unigrid_mesh um;
        um.create(here);
        boost::shared_ptr<std::vector<id_type> > result_data =
            um.init_execute(function_type, par->rowsize[0], par->nt0,
                par->loglevel ? logging_type : component_invalid, par);

        std::cout << "Elapsed time: " << t.elapsed() << " [s]" << std::endl;

        for (std::size_t i = 0; i < result_data->size(); ++i)
            hpx::components::stubs::memory_block::free((*result_data)[i]);
    } // unigrid_mesh needs to go out of scope before shutdown

    // initiate shutdown of the runtime systems on all localities
    finalize();
    return 0;
}