コード例 #1
0
ファイル: main.cpp プロジェクト: Abuenameh/CTDG-Norm
void fail(std::string error, worker_output* output, managed_shared_memory& segment) {
    void_allocator void_alloc(segment.get_segment_manager());
    output->Ei = numeric_limits<double>::quiet_NaN();
    output->Ef = numeric_limits<double>::quiet_NaN();
    output->Q = numeric_limits<double>::quiet_NaN();
    output->p = numeric_limits<double>::quiet_NaN();
    output->Es = double_vector(1, numeric_limits<double>::quiet_NaN(), void_alloc);
    complex_vector nan_vector(L, numeric_limits<double>::quiet_NaN(), void_alloc);
    output->b0 = nan_vector;
    output->bf = nan_vector;
    complex_vector_vector nan_vector_vector(L, complex_vector(dim, numeric_limits<double>::quiet_NaN(), void_alloc), void_alloc);
    output->f0 = nan_vector_vector;
    output->ff = nan_vector_vector;
    output->runtime = error.c_str();
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Abuenameh/CTDG-Norm
void threadfunc(std::string prog, double tauf, queue<input>& inputs, vector<results>& res, progress_display& progress, int thread, managed_shared_memory& segment) {

    void_allocator void_alloc(segment.get_segment_manager());

    std::string tau_name = "tau" + lexical_cast<std::string>(thread);
    worker_tau* tau = segment.construct<worker_tau>(tau_name.c_str())();

    std::string output_name = "output" + lexical_cast<std::string>(thread);
    worker_output* output = segment.construct<worker_output>(output_name.c_str())(void_alloc);

    std::vector<std::string> args;
    args.push_back(prog);
    args.push_back("-1");
    args.push_back(tau_name);
    args.push_back(output_name);

    execute(set_args(args));

    for (;;) {
        input in;
        {
            boost::mutex::scoped_lock lock(inputs_mutex);
            if (inputs.empty()) {
                interprocess::scoped_lock<interprocess_mutex> lock(tau->mutex);

                if (tau->full) {
                    tau->cond_full.wait(lock);
                }
                tau->tau = -1;
                tau->cond_empty.notify_one();
                tau->full = true;
                break;
            }
            in = inputs.front();
            inputs.pop();
        }

        {
            interprocess::scoped_lock<interprocess_mutex> lock(tau->mutex);

            if (tau->full) {
                tau->cond_full.wait(lock);
            }
            tau->tau = in.tau;
            tau->cond_empty.notify_one();
            tau->full = true;
        }

        //        results pointRes(void_alloc);
        results pointRes;
        pointRes.tau = in.tau;

        {
            interprocess::scoped_lock<interprocess_mutex> lock(output->mutex);

            if (!output->full) {
                output->cond_empty.wait(lock);
            }
            pointRes.Ei = output->Ei;
            pointRes.Ef = output->Ef;
            pointRes.Q = output->Q;
            pointRes.p = output->p;
            pointRes.Es = vector<double>(output->Es.begin(), output->Es.end());
            pointRes.b0 = vector<complex<double>>(output->b0.begin(), output->b0.end());
            pointRes.bf = vector<complex<double>>(output->bf.begin(), output->bf.end());
            vector<vector<complex<double>>> ff;
            for (int i = 0; i < L; i++) {
                ff.push_back(vector<complex<double>>(output->ff[i].begin(), output->ff[i].end()));
            }
            pointRes.ff = ff;
            pointRes.runtime = string(output->runtime.begin(), output->runtime.end());
            //            pointRes.Es = output->Es;
            //            pointRes.b0 = output->b0;
            //            pointRes.bf = output->bf;
            //            pointRes.f0 = output->f0;
            //            pointRes.ff = output->ff;
            //            pointRes.runtime = output->runtime;
            output->full = false;
            output->cond_full.notify_one();
        }

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

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

    segment.destroy_ptr<worker_output>(output);
}
コード例 #3
0
ファイル: main.cpp プロジェクト: Abuenameh/CTDG-Norm
void evolve(SXFunction& E0, SXFunction& Et, Function& ode_func, vector<double>& p, worker_input* input, worker_output* output, managed_shared_memory& segment) {
    double tau = p[L + 3];
    //    double tauf = tau;//2e-6;
    //    double dt = 0.9e-9*scale;
    double dt = input->dt;
    Integrator integrator_rk("integrator", "rk", ode_func, make_dict("t0", 0, "tf", 2 * tau, "number_of_finite_elements", ceil((2 * tau) / dt)));
    Integrator integrator_cvodes("integrator", "cvodes", ode_func, make_dict("t0", 0, "tf", 2 * tau, "exact_jacobian", false, "max_num_steps", 100000));
    Integrator integrator_rk1("integrator", "rk", ode_func, make_dict("t0", 0, "tf", tau, "number_of_finite_elements", ceil((2 * tau) / dt)));
    Integrator integrator_cvodes1("integrator", "cvodes", ode_func, make_dict("t0", 0, "tf", tau, "exact_jacobian", false, "max_num_steps", 100000));
    Integrator integrator_rk2("integrator", "rk", ode_func, make_dict("t0", tau, "tf", 2 * tau, "number_of_finite_elements", ceil((2 * tau) / dt)));
    Integrator integrator_cvodes2("integrator", "cvodes", ode_func, make_dict("t0", tau, "tf", 2 * tau, "exact_jacobian", false, "max_num_steps", 100000));
    Integrator integrator;
    Integrator integrator1;
    Integrator integrator2;
    if (input->integrator == "rk") {
        integrator = integrator_rk;
        integrator1 = integrator_rk1;
        integrator2 = integrator_rk2;
    }
    if (input->integrator == "cvodes") {
        integrator = integrator_cvodes;
        integrator1 = integrator_cvodes1;
        integrator2 = integrator_cvodes2;
    }

    ptime start_time = microsec_clock::local_time();

    std::vector<double> x0;
    for (int i = 0; i < 2 * L * dim; i++) {
        x0.push_back(input->x0[i]);
    }

    void_allocator void_alloc(segment.get_segment_manager());

    vector<double> xf;
    bool half = false;
    if (half) {
        map<string, DMatrix> res = integrator1(make_map("x0", DMatrix(x0), "p", p));
        xf = res["xf"].nonzeros();
        res = integrator2(make_map("x0", DMatrix(xf), "p", p));
        xf = res["xf"].nonzeros();
    }
    else {
        map<string, DMatrix> res = integrator(make_map("x0", DMatrix(x0), "p", p));
        /*vector<double>*/ xf = res["xf"].nonzeros();
    }

    complex_vector_vector ff(void_alloc);
    for (int i = 0; i < L; i++) {
        complex_vector ffi(void_alloc);
        for (int n = 0; n <= nmax; n++) {
            ffi.push_back(complex<double>(xf[2 * (i * dim + n)], xf[2 * (i * dim + n) + 1]));
        }
        double nrm = sqrt(abs(dot(ffi, ffi)));
        for (int n = 0; n <= nmax; n++) {
            ffi[n] /= nrm;
        }
        ff.push_back(ffi);
    }
    output->ff = ff;

    complex_vector_vector& f0 = input->f0;

    output->b0.clear();
    output->bf.clear();
    for (int i = 0; i < L; i++) {
        output->b0.push_back(b(f0, i, input->J0, input->U0));
        output->bf.push_back(b(ff, i, input->J0, input->U0));
    }

    output->Ei = E0(vector<DMatrix> {x0})[0].toScalar();
    output->Ef = E0(vector<DMatrix> {xf})[0].toScalar();
    output->Q = output->Ef - output->Ei;

    vector<double> pi(L);
    output->p = 0;
    for (int i = 0; i < L; i++) {
        pi[i] = 1 - norm(dot(ff[i], f0[i]));
        output->p += pi[i];
    }
    output->p /= L;

    ptime stop_time = microsec_clock::local_time();
    time_period period(start_time, stop_time);
    output->runtime = to_simple_string(period.length()).c_str();
}
コード例 #4
0
ファイル: counters.hpp プロジェクト: hundeboll/fox
 counters() :
     m_segment(create_only, SHM_NAME, 65536),
     m_allocator(m_segment.get_segment_manager()),
     m_counter_map(m_segment.construct<shared_map>(SHM_MAP_NAME)
             (std::less<key_type>(), m_allocator))
 {}