Beispiel #1
0
void lock_and_wait(
    mutex& m
  , barrier& b0
  , barrier& b1
  , fifo_type& hpxthreads
  , std::size_t wait
) {
    // Wait for all hpxthreads in this iteration to be created.
    b0.wait();

    const thread_id_type this_ = get_self_id();

    while (true)
    {
        // Try to acquire the mutex.
        boost::unique_lock<mutex> l(m, boost::try_to_lock);

        if (l.owns_lock())
        {
            hpxthreads.push(new std::pair<thread_id_type, std::size_t>
                (this_, get_thread_phase(this_)));
            break;
        }

        // Schedule a wakeup.
        set_thread_state(this_, milliseconds(30), pending);

        // Suspend this HPX thread.
        hpx::this_thread::suspend(suspended);
    }

    // Make hpx_main wait for us to finish.
    b1.wait();
}
void suspend_test(barrier& b, std::size_t iterations, std::size_t n)
{
    for (std::size_t i = 0; i < iterations; ++i)
    {
        // Enter the 'suspended' state for n microseconds. 
        hpx::this_thread::suspend(microseconds(n), "suspend_test");
    }

    // Wait for all hpx-threads to enter the barrier.
    b.wait();
}
Beispiel #3
0
 void operator()(Iterator first,Iterator last,
                 std::vector<value_type>& buffer,
                 unsigned i,barrier& b)
 {
     value_type& ith_element=*(first+i);
     bool update_source=false;
     for(unsigned step=0,stride=1;stride<=i;++step,stride*=2)
     {
         value_type const& source=(step%2)?
             buffer[i]:ith_element;
         value_type& dest=(step%2)?
             ith_element:buffer[i];
         value_type const& addend=(step%2)?
             buffer[i-stride]:*(first+i-stride);
         dest=source+addend;
         update_source=!(step%2);
         b.wait();
     }
     if(update_source)
     {
         ith_element=buffer[i];
     }
     b.done_waiting();
 }
Beispiel #4
0
void local_barrier_test(barrier& b, boost::atomic<std::size_t>& c)
{
    ++c;
    // wait for all threads to enter the barrier
    b.wait();
}
void threadfunc(double Wi, double Wf, double mu, vector<double> xi, double tauf, queue<input>& inputs, vector<results>& res, progress_display& progress, barrier& bar, int thread) {
    //    DynamicsProblem* prob;
    //
    //    {
    //        prob = new DynamicsProblem(Wi, Wf, mu, xi);
    //    }

    DynamicsProblem prob(Wi, Wf, mu, xi);

    bar.wait();

    for (;;) {
        input in;
        {
            boost::mutex::scoped_lock lock(inputs_mutex);
            if (inputs.empty()) {
                break;
            }
            in = inputs.front();
            inputs.pop();
        }
        double tau = in.tau;

        results pointRes;
        pointRes.tau = tau;

        try {
            prob.evolve(tau, pointRes);
            //            prob->evolve(tau, pointRes);
        }
        catch (std::exception& e) {
            cerr << "Failed at tau = " << tau << endl;
            cerr << e.what() << endl;
            pointRes.Ei = numeric_limits<double>::quiet_NaN();
            pointRes.Ef = numeric_limits<double>::quiet_NaN();
            pointRes.Q = numeric_limits<double>::quiet_NaN();
            pointRes.p = numeric_limits<double>::quiet_NaN();
            pointRes.U0 = numeric_limits<double>::quiet_NaN();
            pointRes.J0 = vector<double>(L, numeric_limits<double>::quiet_NaN());
            pointRes.b0 = vector<complex<double>>(L, numeric_limits<double>::quiet_NaN());
            pointRes.bf = vector<complex<double>>(L, numeric_limits<double>::quiet_NaN());
            pointRes.f0 = vector<vector<complex<double>>>(L, vector<complex<double>>(dim, numeric_limits<double>::quiet_NaN()));
            pointRes.ff = vector<vector<complex<double>>>(L, vector<complex<double>>(dim, numeric_limits<double>::quiet_NaN()));
            pointRes.runtime = "Failed";
        }

        {
            boost::mutex::scoped_lock lock(inputs_mutex);
            res.push_back(pointRes);
        }

        {
            boost::mutex::scoped_lock lock(progress_mutex);
            ++progress;
        }
    }

    bar.wait();

    {
        boost::mutex::scoped_lock lock(problem_mutex);
        //        delete prob;
    }


}
Beispiel #6
0
void f(barrier& b) {
    for (int i = 0; i < 3; i++){
        b.enter();
    }
}