Exemple #1
0
void plain_deferred_arguments()
{
    void_f4_count.store(0);
    int_f4_count.store(0);

    {
        future<void> f1 = dataflow(hpx::launch::deferred, &void_f4, 42);
        future<int> f2 = dataflow(hpx::launch::deferred, &int_f4, 42);

        f1.wait();
        HPX_TEST_EQ(void_f4_count, 1u);

        HPX_TEST_EQ(f2.get(), 84);
        HPX_TEST_EQ(int_f4_count, 1u);
    }

    void_f5_count.store(0);
    int_f5_count.store(0);

    {
        future<void> f1 = dataflow(&void_f5, 42, async(hpx::launch::deferred, &int_f));
        future<int> f2 = dataflow(&int_f5, 42, async(hpx::launch::deferred, &int_f));

        f1.wait();
        HPX_TEST_EQ(void_f5_count, 1u);

        HPX_TEST_EQ(f2.get(), 126);
        HPX_TEST_EQ(int_f5_count, 1u);
    }
}
Exemple #2
0
block rec_mult(block A, block B, block C) {
    if(C.width <= blocksize || C.height <= blocksize ) {
        return serial_mult(A, B, C);
    } 
    future<block> C11 = async(calc_c11, A, B, C);
    future<block> C12 = async(calc_c12, A, B, C);
    future<block> C21 = async(calc_c21, A, B, C);
    future<block> C22 = async(calc_c22, A, B, C);

    C11.wait();
    C12.wait();
    C21.wait();
    C22.wait();
    /*
       auto f_A = make_ready_future(A);
       auto f_B = make_ready_future(B);
       auto f_C = make_ready_future(C);
       future<block> C11 = dataflow(unwrapped(calc_c11), f_A, f_B, f_C);
       future<block> C12 = dataflow(unwrapped(calc_c12), f_A, f_B, f_C);
       future<block> C21 = dataflow(unwrapped(calc_c21), f_A, f_B, f_C);
       future<block> C22 = dataflow(unwrapped(calc_c22), f_A, f_B, f_C);

       future<block> result = dataflow(unwrapped(combine_blocks), C11, C12, C21, C22, f_C);
       */
    return C;
}
Exemple #3
0
block calc_c22(block A, block B, block C) {
    block tempC = C.block22();
    tempC.add_scratch();
    future<block> A21B12 = async(rec_mult, A.block21(), B.block12(), C.block22());
    future<block> A22B22 = async(rec_mult, A.block22(), B.block22(), tempC);
    return add_blocks(A21B12.get(), A22B22.get(), C.block22());
}
Exemple #4
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;
}
void plain_arguments(Executor& exec)
{
    void_f4_count.store(0);
    int_f4_count.store(0);

    {
        future<void> f1 = dataflow(exec, &void_f4, 42);
        future<int> f2 = dataflow(exec, &int_f4, 42);

        f1.wait();
        HPX_TEST_EQ(void_f4_count, 1u);

        HPX_TEST_EQ(f2.get(), 84);
        HPX_TEST_EQ(int_f4_count, 1u);
    }

    void_f5_count.store(0);
    int_f5_count.store(0);

    {
        future<void> f1 = dataflow(exec, &void_f5, 42, async(&int_f));
        future<int> f2 = dataflow(exec, &int_f5, 42, async(&int_f));

        f1.wait();
        HPX_TEST_EQ(void_f5_count, 1u);

        HPX_TEST_EQ(f2.get(), 126);
        HPX_TEST_EQ(int_f5_count, 1u);
    }
}
Exemple #6
0
block calc_c11(block A, block B, block C) {
    block tempC = C.block11();//scratch space
    tempC.add_scratch();
    future<block> A11B11 = async(rec_mult, A.block11(), B.block11(), C.block11());
    future<block> A12B21 = async(rec_mult, A.block12(), B.block21(), tempC);
    return add_blocks(A11B11.get(), A12B21.get(), C.block11());
}
Exemple #7
0
void future_function_pointers()
{
    future_void_f1_count.store(0);
    future_void_f2_count.store(0);

    future<void> f1
        = dataflow(
            &future_void_f1, async(&future_void_sf1,
                shared_future<void>(make_ready_future()))
        );

    f1.wait();

    HPX_TEST_EQ(future_void_f1_count, 2u);
    future_void_f1_count.store(0);

    future<void> f2 = dataflow(
        &future_void_f2
      , async(&future_void_sf1, shared_future<void>(make_ready_future()))
      , async(&future_void_sf1, shared_future<void>(make_ready_future()))
    );

    f2.wait();
    HPX_TEST_EQ(future_void_f1_count, 2u);
    HPX_TEST_EQ(future_void_f2_count, 1u);
    future_void_f1_count.store(0);
    future_void_f2_count.store(0);

    future<int> f3 = dataflow(
        &future_int_f1
      , make_ready_future()
    );

    HPX_TEST_EQ(f3.get(), 1);
    HPX_TEST_EQ(future_int_f1_count, 1u);
    future_int_f1_count.store(0);

    future<int> f4 = dataflow(
        &future_int_f2
      , dataflow(&future_int_f1, make_ready_future())
      , dataflow(&future_int_f1, make_ready_future())
    );

    HPX_TEST_EQ(f4.get(), 2);
    HPX_TEST_EQ(future_int_f1_count, 2u);
    HPX_TEST_EQ(future_int_f2_count, 1u);
    future_int_f1_count.store(0);
    future_int_f2_count.store(0);

    future_int_f_vector_count.store(0);
    std::vector<future<int> > vf;
    for(std::size_t i = 0; i < 10; ++i)
    {
        vf.push_back(dataflow(&future_int_f1, make_ready_future()));
    }
    future<int> f5 = dataflow(&future_int_f_vector, boost::ref(vf));

    HPX_TEST_EQ(f5.get(), 10);
}
Exemple #8
0
int hpx_main(variables_map&)
{
    {
        using hpx::async;

        // create an explicit future
        null_thread_executed = false;
        {
            HPX_TEST(async<null_action>(hpx::find_here()).get());
        }
        HPX_TEST(null_thread_executed);

        // create an implicit future
        null_thread_executed = false;
        {
            HPX_TEST(async<null_action>(hpx::find_here()).get());
        }
        HPX_TEST(null_thread_executed);

        //test two successive 'get' from a promise
        hpx::lcos::shared_future<int> int_promise(async<int_action>(hpx::find_here()));
        HPX_TEST(int_promise.get() == int_promise.get());
    }

    {
        using hpx::async;
        null_action do_null;

        // create an explicit future
        null_thread_executed = false;
        {
            HPX_TEST(async(do_null, hpx::find_here()).get());
        }
        HPX_TEST(null_thread_executed);

        // create an implicit future
        null_thread_executed = false;
        {
            HPX_TEST(async(do_null, hpx::find_here()).get());
        }
        HPX_TEST(null_thread_executed);

        //test two successive 'get' from a promise
        int_action do_int;
        hpx::lcos::shared_future<int> int_promise(async(do_int, hpx::find_here()));
        HPX_TEST(int_promise.get() == int_promise.get());
    }

    hpx::finalize();       // Initiate shutdown of the runtime system.
    return hpx::util::report_errors();
}
Exemple #9
0
void measure_function_futures(boost::uint64_t count, bool csv)
{
    std::vector<unique_future<double> > futures;

    futures.reserve(count);

    // start the clock
    high_resolution_timer walltime;

    for (boost::uint64_t i = 0; i < count; ++i)
        futures.push_back(async(&null_function));

    wait(futures, [&] (std::size_t, double r) { global_scratch += r; });

    // stop the clock
    const double duration = walltime.elapsed();

    if (csv)
        cout << ( boost::format("%1%,%2%\n")
                % count
                % duration)
              << flush;
    else
        cout << ( boost::format("invoked %1% futures (functions) in %2% seconds\n")
                % count
                % duration)
              << flush;
}
void function_pointers(Executor& exec)
{
    void_f_count.store(0);
    int_f_count.store(0);
    void_f1_count.store(0);
    int_f1_count.store(0);
    int_f2_count.store(0);

    future<void> f1 = dataflow(exec, unwrapped(&void_f1), async(&int_f));
    future<int>
        f2 = dataflow(exec,
            unwrapped(&int_f1)
          , dataflow(exec,
                unwrapped(&int_f1)
              , make_ready_future(42))
        );
    future<int>
        f3 = dataflow(exec,
            unwrapped(&int_f2)
          , dataflow(exec,
                unwrapped(&int_f1)
              , make_ready_future(42)
            )
          , dataflow(exec,
                unwrapped(&int_f1)
              , make_ready_future(37)
            )
        );

    int_f_vector_count.store(0);
    std::vector<future<int> > vf;
    for(std::size_t i = 0; i < 10; ++i)
    {
        vf.push_back(dataflow(exec, unwrapped(&int_f1), make_ready_future(42)));
    }
    future<int> f4 = dataflow(exec, unwrapped(&int_f_vector), std::move(vf));

    future<int>
        f5 = dataflow(exec,
            unwrapped(&int_f1)
          , dataflow(exec,
                unwrapped(&int_f1)
              , make_ready_future(42))
          , dataflow(exec,
                unwrapped(&void_f)
              , make_ready_future())
        );

    f1.wait();
    HPX_TEST_EQ(f2.get(), 126);
    HPX_TEST_EQ(f3.get(), 163);
    HPX_TEST_EQ(f4.get(), 10 * 84);
    HPX_TEST_EQ(f5.get(), 126);
    HPX_TEST_EQ(void_f_count, 1u);
    HPX_TEST_EQ(int_f_count, 1u);
    HPX_TEST_EQ(void_f1_count, 1u);
    HPX_TEST_EQ(int_f1_count, 16u);
    HPX_TEST_EQ(int_f2_count, 1u);
}
Exemple #11
0
void LU( int size, int numBlocks)
{
    vector<vector<block>> blockList;
    vector<vector<vector<shared_future<block>>>> dfArray(2);
    shared_future<block> *diag_block, *first_col;
    shared_future<int> fsize = make_ready_future(size);

    auto rowOp = unwrapped(&ProcessBlockOnRow);
    auto colOp = unwrapped(&ProcessBlockOnColumn);
    auto innerOp = unwrapped(&ProcessInnerBlock);
    auto diagOp = unwrapped(&ProcessDiagonalBlock);

    getBlockList(blockList, numBlocks, size);

    for(int i = 0; i < 2; i++){
        dfArray[i].resize( numBlocks );
        for(int j = 0; j < numBlocks; j++){
            dfArray[i][j].resize( numBlocks, make_ready_future( block()));
        }
    }
    vector<vector<shared_future<block>>> &last_array = dfArray[0];
    vector<vector<shared_future<block>>> &current_array = dfArray[1];

    //converts blocks to shared_futures for dataflow input in dfArray[0]
    dfArray[0][0][0] = async( ProcessDiagonalBlock, size, blockList[0][0] );
    diag_block = &dfArray[0][0][0];
    for(int i = 1; i < numBlocks; i++) {
        dfArray[0][0][i] = dataflow( rowOp, fsize, make_ready_future( blockList[0][i] ), *diag_block);
    }
    for(int i = 1; i < numBlocks; i++) {
        dfArray[0][i][0] = dataflow( colOp, fsize, make_ready_future( blockList[i][0] ), *diag_block);
        first_col = &dfArray[0][i][0];
        for(int j = 1; j < numBlocks; j++) {
            dfArray[0][i][j] = dataflow( innerOp, fsize, make_ready_future( blockList[i][j]), dfArray[0][0][j], *first_col);
        }
    }
    //bulk of work, entirely in shared_futures
    for(int i = 1; i < numBlocks; i++) {
        last_array = dfArray[i-1];
        current_array = dfArray[i];

        current_array[i][i] = dataflow( diagOp, fsize, last_array[i][i]);
        diag_block = &current_array[i][i];
        for(int j = i + 1; j < numBlocks; j++){
            current_array[i][j] = dataflow( rowOp, fsize, last_array[i][j], *diag_block);
        }
        for(int j = i + 1; j < numBlocks; j++){
            current_array[j][i] = dataflow( colOp, fsize, last_array[j][i], *diag_block);
            first_col = &current_array[j][i];
            for(int k = i + 1; k < numBlocks; k++) {
                current_array[j][k] = dataflow( innerOp, fsize, last_array[j][k], current_array[i][k], *first_col);
           }
        }
    }
    wait_all(current_array[numBlocks-1][numBlocks-1]);
}
Exemple #12
0
void exec_spawn(int input){
    hpx::threads::thread_id_type id = hpx::threads::get_self_id();
    cout << "in spawn #" << input << ", executor: " << hpx::threads::get_executor(id) << endl;

    {
        local_priority_queue_executor exec1(1);
        auto f = async(exec1, thread_setup, input);
        f.wait();
    }
}
///////////////////////////////////////////////////////////////////////////////
//[fib_func
boost::uint64_t fibonacci(boost::uint64_t n)
{
  if (n < 2)
    return n;

  // We restrict ourselves to execute the Fibonacci function locally.
  hpx::naming::id_type const locality_id = hpx::find_here();

  // Invoking the Fibonacci algorithm twice is inefficient.
  // However, we intentionally demonstrate it this way to create some
  // heavy workload.
  using hpx::lcos::future;
  using hpx::async;

  fibonacci_action fib;
  future<boost::uint64_t> n1 = async(fib, locality_id, n - 1);
  future<boost::uint64_t> n2 = async(fib, locality_id, n - 2);

  return n1.get() + n2.get();   // wait for the Futures to return their values
}
Exemple #14
0
void LU( int numBlocks)
{
    printf("LU\n");
    hpx::naming::id_type here = hpx::find_here();
    vector<vector<block> > blockList;
    getBlockList(blockList, numBlocks);
    vector<vector<vector<shared_future<block> > > > dfArray(numBlocks);
    shared_future<block> *diag_block, *first_col;

    for(int i = 0; i < numBlocks; i++){
        dfArray[i].resize(numBlocks);
        for(int j = 0; j < numBlocks; j++){
            dfArray[i][j].resize(numBlocks, hpx::make_ready_future(block()));
        }
    }
    //first iteration through matrix, initialized vector of futures
    dfArray[0][0][0] = async( ProcessDiagonalBlock, blockList[0][0] );
    diag_block = &dfArray[0][0][0];
    for(int i = 1; i < numBlocks; i++) {
        dfArray[0][0][i] = dataflow( unwrapped( &ProcessBlockOnRow ),
            hpx::make_ready_future( blockList[0][i] ), *diag_block);
    }
    for(int i = 1; i < numBlocks; i++) {
        dfArray[0][i][0] = dataflow( unwrapped( &ProcessBlockOnColumn ),
            hpx::make_ready_future( blockList[i][0] ), *diag_block);
        first_col = &dfArray[0][i][0];
        for(int j = 1; j < numBlocks; j++) {
            dfArray[0][i][j] = dataflow( unwrapped( &ProcessInnerBlock ),
                hpx::make_ready_future( blockList[i][j]), dfArray[0][0][j], *first_col );
        }
    }
    //all calculation after initialization. Each iteration,
    //the number of tasks/blocks spawned is decreased.
    for(int i = 1; i < numBlocks; i++) {
        dfArray[i][i][i] = dataflow( unwrapped( &ProcessDiagonalBlock ),
            dfArray[i-1][i][i]);
        diag_block = &dfArray[i][i][i];
        for(int j = i + 1; j < numBlocks; j++){
            dfArray[i][i][j] = dataflow( unwrapped(&ProcessBlockOnRow),
                dfArray[i-1][i][j], *diag_block);
        }
        for(int j = i + 1; j < numBlocks; j++){
            dfArray[i][j][i] = dataflow( unwrapped( &ProcessBlockOnColumn ),
                dfArray[i-1][j][i], *diag_block);
            first_col = &dfArray[i][j][i];
            for(int k = i + 1; k < numBlocks; k++) {
                dfArray[i][j][k] = dataflow( unwrapped( &ProcessInnerBlock ),
                    dfArray[i-1][j][k], dfArray[i][i][k], *first_col );
            }
        }
    }
    wait_all(dfArray[numBlocks-1][numBlocks-1][numBlocks-1]);
}
Exemple #15
0
void tree_boot(
    boost::uint64_t count
  , boost::uint64_t grain_size
  , thread_id_type thread
    )
{
    HPX_ASSERT(grain_size);
    HPX_ASSERT(count);

    std::vector<unique_future<void> > promises;

    boost::uint64_t const actors = (count > grain_size) ? grain_size : count;

    boost::uint64_t child_count = 0;
    boost::uint64_t children = 0;

    if (count > grain_size)
    {
        for (children = grain_size; children != 0; --children)
        {
            child_count = ((count - grain_size) / children);

            if (child_count >= grain_size)
                break;
        }

        promises.reserve(children + grain_size);
    }
    else
        promises.reserve(count);

    for (boost::uint64_t i = 0; i < children; ++i)
        promises.push_back(async(&tree_boot, child_count, grain_size, thread));

    for (boost::uint64_t i = 0; i < actors; ++i)
        promises.push_back(async(&change_thread_state, thread));

    detail::wait(promises);
}
Exemple #16
0
int hpx_main() {
    vector<hpx::lcos::future<void>> threads;
    //threads.push_back(async(thread_setup, 42));

    {
        //local_priority_queue_executor exec;
        for(int i = 0; i < 8; i++) {
            //threads.push_back(async(exec, thread_setup, i));
            threads.push_back(async(exec_spawn, i));
        }
        hpx::wait_all(threads);
        cout << "All done" << endl;
    }
    return hpx::finalize();
}
Exemple #17
0
void measure_function_futures_wait_all(
    std::uint64_t count, bool csv, Executor& exec)
{
    std::vector<future<double> > futures;
    futures.reserve(count);

    // start the clock
    high_resolution_timer walltime;
    for (std::uint64_t i = 0; i < count; ++i)
        futures.push_back(async(exec, &null_function));
    wait_all(futures);

    const double duration = walltime.elapsed();
    print_stats("async", "WaitAll", ExecName(exec), count, duration, csv);
}
Exemple #18
0
void LU( int numBlocks)
{
    hpx::naming::id_type here = hpx::find_here();
    vector<vector<block>> blockList;
    getBlockList(blockList, numBlocks);
    vector<vector<vector<future<block>>>> dfArray(numBlocks);
    future<block> *diag_block, *first_col;

    for(int i = 0; i < numBlocks; i++){
        dfArray[i].resize(numBlocks);
        for(int j = 0; j < numBlocks; j++){
            dfArray[i][j].resize(numBlocks);
        }
    }
    dfArray[0][0][0] = async( ProcessDiagonalBlock, blockList[0][0] );
    diag_block = &dfArray[0][0][0];
    for(int i = 1; i < numBlocks; i++) {
        dfArray[0][0][i] = dataflow( unwrapped( &ProcessBlockOnRow ), hpx::make_ready_future( blockList[0][i] ), *diag_block);
    }
    for(int i = 1; i < numBlocks; i++) {
        dfArray[0][i][0] = dataflow( unwrapped( &ProcessBlockOnColumn ), hpx::make_ready_future( blockList[i][0] ), *diag_block);
        first_col = &dfArray[0][i][0];
        for(int j = 1; j < numBlocks; j++) {
            dfArray[0][i][j] = dataflow( unwrapped( &remote_inner ),
                                         hpx::make_ready_future( blockList[i][j] ), 
                                         dfArray[0][0][j], *first_col, hpx::make_ready_future(j) );
        }
    }
    for(int i = 1; i < numBlocks; i++) {
        dfArray[i][i][i] = dataflow( unwrapped( &ProcessDiagonalBlock ), dfArray[i-1][i][i]);
        diag_block = &dfArray[i][i][i];
        for(int j = i + 1; j < numBlocks; j++){
            dfArray[i][i][j] = dataflow( unwrapped(&ProcessBlockOnRow), dfArray[i-1][i][j], *diag_block);
        }
        for(int j = i + 1; j < numBlocks; j++){
            dfArray[i][j][i] = dataflow( unwrapped( &ProcessBlockOnColumn ), dfArray[i-1][j][i], *diag_block);
            first_col = &dfArray[i][j][i];
            for(int k = i + 1; k < numBlocks; k++) {
                dfArray[i][j][k] = dataflow( unwrapped( &remote_inner), 
                                             dfArray[i-1][j][k], dfArray[i][i][k], *first_col,
                                             hpx::make_ready_future(k));
            }
        }
    }
    wait(*diag_block);
}
int hpx_main()
{
    using hpx::lcos::unique_future;
    using hpx::async;

    {
        test_action do_test;

        unique_future<int> f = async(do_test, hpx::find_here());
        unique_future<int> p = f.then(hpx::util::bind(future_callback, 
            hpx::util::placeholders::_1));

        HPX_TEST_EQ(p.get(), 42);
    }

    hpx::finalize();
    return hpx::util::report_errors();
}
Exemple #20
0
void InitMatrix3( int size )
{
    vector<double> L, U;
    L.reserve(size*size);
    U.reserve(size*size);
    vector<shared_future<void>> futures, LU_futures;
    futures.reserve(size);
    LU_futures.reserve(size);
    int range = 8;

    for(int i = 0; i < size; i += range) {
        futures.push_back( async( &initA, std::ref(L), std::ref(U), i, size, range));
    }
    if(size % range != 0) {
	    initA(L, U, size - size % range, size, size % range);
    }
    hpx::lcos::wait_all(futures);
}
Exemple #21
0
void InitMatrix3()
{
    vector<future<void>> futures;
    futures.reserve(size);
    for(int i = 0; i < size; i++)
        for(int j = 0; j < size; j++){
            if(i >= j)
                L[i*size + j] = i-j+1;
            else
                L[i*size + j] = 0;
            if(i <= j)
                U[i*size + j] = j-i+1;
            else
                U[i*size + j] = 0;
        }
    for(int i = 0; i < size; i++) {
        futures.push_back( async( initLoop, i));
    }
    wait(futures);
}
Exemple #22
0
int hpx_main()
{
    
    {
        using namespace std;
        ifstream fin;
        string path = __FILE__;
        string wordlist_path;
        string remove = "spell_check.cpp";
        for (int i = 0; i < path.length() - remove.length(); i++)
        {
            wordlist_path.push_back(path[i]);
            if (path[i] == '\\')
            {
                wordlist_path.push_back(path[i]);
            }
        }
        //list of American English words in alphabetical order. Provided by Kevin at http://wordlist.sourceforge.net/
        wordlist_path = wordlist_path + "5desk.txt";
        fin.open(wordlist_path);
        int wordcount = 0;
        cout << "Reading dictionary file to memory...\n";
        hpx::util::high_resolution_timer t;
        if(fin.is_open())
        {
            string temp;
            while (fin.good())
            {
                getline(fin, temp);
                for (int i = 0; i < temp.length(); i++)
                temp[i] = tolower(temp[i]);
                words.push_back(temp);
                wordcount++;
            }
            cout << wordcount << " words loaded in " << t.elapsed() << "s.\n";
        }
        else
        {
            cout << "Error: Unable to open file.\n";
            return hpx::finalize();
        }
        fin.close();
        char* word = new char[1024];
        cout << "Enter the words you would like to spellcheck, separated by a \"Space\", and then press \"Enter\".\n";
        cin.getline(word,1024, '\n');
        vector<bool> contraction;
        vector<string> strs;
        {
            vector<string> temp;
            boost::split(temp, word, boost::is_any_of("\n\t -"));
            for (int i = 0; i < temp.size(); i++)
            {
                bool isContraction = false;
                string holder;
                for (int j = 0; j < temp[i].size(); j++)
                {
                    //a size check to avoid errors
                    if (temp[i].size() - j - 1 == 2)
                    {
                    //if this is a contraction, ignore the rest of it...
                        if (temp[i][j+1] == '\'' && temp[i][j] == 'n' && temp[i][j+2] == 't')
                        {
                            //but label this as a contraction
                            isContraction = true;
                            break;
                        }
                    }
                    //remove any garbage characters
                    if (toupper(temp[i][j]) >= 'A' && toupper(temp[i][j]) <= 'Z')
                        holder.push_back(tolower(temp[i][j]));
                }
                if (holder.size() > 0)
                {
                    contraction.push_back(isContraction);
                    strs.push_back(holder);
                }
            }
        }
        t.restart();
        {
            using hpx::lcos::future;
            using hpx::async;
            using hpx::wait_all;
            vector<search_action> sAct;//[sizeX * sizeY];
            vector<future<string>> wordRun;
            wordRun.reserve(strs.size());
            for (int i = 0; i < strs.size(); ++i)
            {
                string& single = strs[i]; 
                int start = 0;
                hpx::naming::id_type const locality_id = hpx::find_here();
                search_action temp;
                wordRun.push_back(async(temp, locality_id, start, wordcount, single));
                sAct.push_back(temp);
                //cout << search(0, wordcount, single) << endl;
            }
            wait_all(wordRun);
            cout << "Search completed in " << t.elapsed() << "s.\n";
            for (int i = 0; i < strs.size(); i++)
            {
                cout << "Word number " << i + 1 << ":\n";
                if (contraction[i])
                    cout << "Note: This word seems to be a contraction.\nThe last two letters have been ignored.\n";
                cout << wordRun[i].get();
            }
        }
    }
    return hpx::finalize(); // Handles HPX shutdown
}
Exemple #23
0
int hpx_main(boost::program_options::variables_map&)
{
    using hpx::lcos::future;
    using hpx::async;

    {
        future<int> p = async<test_action>(hpx::find_here());
        HPX_TEST_EQ(p.get(), 42);
    }

    {
        test_action do_test;
        future<int> p = async(do_test, hpx::find_here());
        HPX_TEST_EQ(p.get(), 42);
    }

    {
        bool data_cb_called = false;
        bool error_cb_called = false;

        future<int> f = async<test_action>(hpx::find_here());
        future<int> p = f.then(boost::bind(future_callback, 
            boost::ref(data_cb_called), boost::ref(error_cb_called), _1));

        HPX_TEST_EQ(p.get(), 42);
        HPX_TEST(data_cb_called);
        HPX_TEST(!error_cb_called);
    }

    {
        bool data_cb_called = false;
        bool error_cb_called = false;
        test_action do_test;

        future<int> f = async(do_test, hpx::find_here());

        // The HPX_STD_FUNCTION is a workaround for a GCC bug, see the
        // async_callback_non_deduced_context regression test.
        future<int> p = f.then(
            HPX_STD_FUNCTION<int(hpx::lcos::future<int>)>(
                boost::bind(future_callback, boost::ref(data_cb_called),
                    boost::ref(error_cb_called), _1)));

        HPX_TEST_EQ(p.get(), 42);
        HPX_TEST(data_cb_called);
        HPX_TEST(!error_cb_called);
    }

    {
        future<int> p = async<test_error_action>(hpx::find_here());

        std::string what_msg;

        try {
            p.get();      // throws
            HPX_TEST(false);
        }
        catch (std::exception const& e) {
            HPX_TEST(true);
            what_msg = e.what();
        }

        HPX_TEST_EQ(what_msg, error_msg);
    }

    {
        test_error_action do_error;
        future<int> p = async(do_error, hpx::find_here());

        std::string what_msg;

        try {
            p.get();      // throws
            HPX_TEST(false);
        }
        catch (std::exception const& e) {
            HPX_TEST(true);
            what_msg = e.what();
        }

        HPX_TEST_EQ(what_msg, error_msg);
    }

    {
        bool data_cb_called = false;
        bool error_cb_called = false;

        future<int> f = async<test_error_action>(hpx::find_here());
        future<int> p = f.then(boost::bind(future_callback, 
            boost::ref(data_cb_called), boost::ref(error_cb_called), _1));

        std::string what_msg;

        try {
            f.get();      // throws
            p.get();
            HPX_TEST(false);
        }
        catch (std::exception const& e) {
            HPX_TEST(true);
            what_msg = e.what();
        }

        HPX_TEST_EQ(what_msg, error_msg);
        HPX_TEST(!data_cb_called);
        HPX_TEST(error_cb_called);
    }

    {
        bool data_cb_called = false;
        bool error_cb_called = false;
        test_error_action do_test_error;

        future<int> f = async(do_test_error, hpx::find_here());

        // The HPX_STD_FUNCTION is a workaround for a GCC bug, see the
        // async_callback_non_deduced_context regression test.
        future<int> p = f.then(
            HPX_STD_FUNCTION<int(hpx::lcos::future<int>)>(
                boost::bind(future_callback, boost::ref(data_cb_called),
                    boost::ref(error_cb_called), _1)));

        std::string what_msg;

        try {
            f.get();      // throws
            p.get();
            HPX_TEST(false);
        }
        catch (std::exception const& e) {
            HPX_TEST(true);
            what_msg = e.what();
        }

        HPX_TEST_EQ(what_msg, error_msg);
        HPX_TEST(!data_cb_called);
        HPX_TEST(error_cb_called);
    }

    hpx::finalize();
    return hpx::util::report_errors();
}
Exemple #24
0
int hpx_main()
{
    BMP SetImage;
    SetImage.SetBitDepth(24);
    SetImage.SetSize(sizeX * 2, sizeY);
    hpx::util::high_resolution_timer t;

    {
        using namespace std;

        using hpx::future;
        using hpx::async;
        using hpx::wait_all;

        int const max_iteration = 255;

        vector<future<int> > iteration;
        iteration.reserve(sizeX*sizeY);

        hpx::cout << "Initial setup completed in "
                  << t.elapsed()
                  << "s. Initializing and running futures...\n"
                  << hpx::flush;
        t.restart();

        {
            hpx::threads::executors::local_queue_executor exec;

            for (int i = 0; i < sizeX; ++i)
            {
                for (int j = 0; j < sizeY; ++j)
                {
                    float x0 = (float)i * 3.5f / (float)sizeX - 2.5f;
                    float y0 = (float)j * 2.0f / (float)sizeY - 1.0f;

                    iteration.push_back(async(exec, &fractal_pixel_value,
                        x0, y0, max_iteration));
                }
            }

            // the executor's destructor will wait for all spawned tasks to
            // finish executing
        }

        hpx::cout << sizeX*sizeY << " calculations run in "
                  << t.elapsed()
                  << "s. Transferring from futures to general memory...\n"
                  << hpx::flush;
        t.restart();

        for (int i = 0; i < sizeX; ++i)
        {
            for (int j = 0; j < sizeY; ++j)
            {
                int it = iteration[i*sizeX + j].get();
                for (int k = 0; k < 2; ++k)
                {
                    int p = (it * 255) / max_iteration;
                    SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p));
                }
            }
        }
    }

    hpx::cout << "Transfer process completed in "
              << t.elapsed() << "s. Writing to hard disk...\n"
              << hpx::flush;
    t.restart();

    SetImage.WriteToFile("out.bmp");

    hpx::cout << "Fractal image written to file \"out.bmp\" from memory in "
              << t.elapsed() << "s.\nShutting down process.\n"
              << hpx::flush;

    return hpx::finalize(); // Handles HPX shutdown
}
Exemple #25
0
int hpx_main()
{
    BMP SetImage;
    SetImage.SetBitDepth(24);
    SetImage.SetSize(sizeX * 2,sizeY);
    hpx::util::high_resolution_timer t;

    {
        using namespace std;

        using hpx::future;
        using hpx::async;
        using hpx::wait_all;

        int const max_iteration = 255;

        vector<future<int> > iteration;
        iteration.reserve(sizeX*sizeY);

        hpx::cout << "Initial setup completed in " 
                  << t.elapsed() 
                  << "s. Initializing and running futures...\n";
        t.restart();

        hpx::id_type const here = hpx::find_here();
        fractals_action fractal_pixel;

        for (int i = 0; i < sizeX; i++)
        {
            for (int j = 0; j < sizeY; j++)
            {
                float x0 = (float)i * 3.5f / (float)sizeX - 2.5f;
                float y0 = (float)j * 2.0f / (float)sizeY - 1.0f;

                iteration.push_back(async(fractal_pixel, here, x0, y0, max_iteration));
            }
        }
        wait_all(iteration);

        hpx::cout << sizeX*sizeY << " calculations run in " 
                  << t.elapsed() 
                  << "s. Transferring from futures to general memory...\n";
        t.restart();

        for (int i = 0; i < sizeX; ++i)
        {
            for (int j = 0; j < sizeY; ++j)
            {
                int it = iteration[i*sizeX + j].get();
                for (int k = 0; k < 2; ++k)
                {
                    int p = (it * 255) / max_iteration;
                    SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p));
                }
            }
        }
    }

    hpx::cout << "Transfer process completed in " 
              << t.elapsed() << "s. Writing to hard disk...\n";
    t.restart();

    SetImage.WriteToFile("out.bmp");
    
    hpx::cout << "Fractal image written to file \"out.bmp\" from memory in " 
              << t.elapsed() << "s.\nInitializing shutdown process.\n";

    return hpx::finalize(); // Handles HPX shutdown
}