Exemplo n.º 1
0
int execute_python_entrypoint(int argc, char **argv, const char *basename, const char *module, const char *function,
        char *outr, char *errr) {
    PyObject *site, *pmain, *res;
    int ret = 0;

    initialize_interpreter(argc, argv, outr, errr, basename, module, function);

    site = PyImport_ImportModule("site");

    if (site == NULL)
        ret = report_python_error("Failed to import site module",  1);
    else {
        Py_XINCREF(site);

        pmain = PyObject_GetAttrString(site, "main");
        if (pmain == NULL || !PyCallable_Check(pmain)) 
            ret = report_python_error("site module has no main function", 1);
        else {
            Py_XINCREF(pmain);
            res = PyObject_CallObject(pmain, NULL);

            if (res == NULL) 
                ret = report_python_error("Python function terminated unexpectedly", 1);
            
            ret = pyobject_to_int(res);
        }
    }
    PyErr_Clear();
    Py_Finalize();

    //printf("11111 Returning: %d\r\n", ret);
    return ret;
}
Exemplo n.º 2
0
// For testing the python-hmpp linking 
PyObject *hmpp_python_test(PyObject *self, PyObject *args)
{
    PyObject *domain;


    int timestepping_method, flow_algorithm, compute_fluxes_method;
    int skip_initial_step;
    int step;
    double yieldstep, finaltime, duration, epsilon;
    double tmp_timestep;


    // Convert Python arguments to C
    if (!PyArg_ParseTuple(args, "Oddddiiiii", 
                &domain,
                &yieldstep, 
                &finaltime, 
                &duration,
                &epsilon,
                &skip_initial_step,

                &compute_fluxes_method,
                &flow_algorithm,
                &timestepping_method,
                &step
                )) 
    {
        report_python_error(AT, "could not parse input arguments");
        return NULL;
    }

    static struct domain D;
    
    
    D.timestepping_method = timestepping_method;
    D.flow_algorithm = flow_algorithm;
    D.compute_fluxes_method = compute_fluxes_method;
    

    if ( !step )
    {   
        get_python_domain(&D, domain);
        print_domain_struct(&D);
        //fflush(stdout);
    }
    

    //-------------------------------
    // Start evolve procedure
    //-------------------------------

    // For testing single function
    test_single( &D);
    return Py_BuildValue("");
}
Exemplo n.º 3
0
PyObject *hmpp_distribute_to_vertices_and_edges(PyObject *self, PyObject *args)
{
    PyObject *domain;


    int timestepping_method, flow_algorithm, compute_fluxes_method;
    int skip_initial_step;
    int step;
    double yieldstep, finaltime, duration, epsilon;


    // Convert Python arguments to C
    if (!PyArg_ParseTuple(args, "Oddddiiiii", 
                &domain,
                &yieldstep, 
                &finaltime, 
                &duration,
                &epsilon,
                &skip_initial_step,

                &compute_fluxes_method,
                &flow_algorithm,
                &timestepping_method,
                &step
                )) 
    {
        report_python_error(AT, "could not parse input arguments");
        return NULL;
    }

    static struct domain D;
    
    
    D.timestepping_method = timestepping_method;
    D.flow_algorithm = flow_algorithm;
    D.compute_fluxes_method = compute_fluxes_method;
    

    if ( !step )
    {   
        get_python_domain(&D, domain);
        print_domain_struct(&D);
        //fflush(stdout);
    }
    
    // For testing single function
    _distribute_to_vertices_and_edges(&D);
    //update_ghosts(&D);
    //_distribute_to_vertices_and_edges(&D);
    //update_boundary(&D);
    //update_extrema(&D);

    //_extrapolate_second_order_sw(&D);
    return Py_BuildValue("");
}
Exemplo n.º 4
0
PyObject *hmpp_extrapolate_second_order_and_limit_by_vertex(
        PyObject *self, PyObject *args)
{
    PyObject *domain;


    int timestepping_method, flow_algorithm, compute_fluxes_method;
    int skip_initial_step;
    int step;
    long Nid;
    double yieldstep, finaltime, duration, epsilon;


    // Convert Python arguments to C
    if (!PyArg_ParseTuple(args, "Oddddiiiili", 
                &domain,
                &yieldstep, 
                &finaltime, 
                &duration,
                &epsilon,
                &skip_initial_step,

                &compute_fluxes_method,
                &flow_algorithm,
                &timestepping_method,
                &Nid,
                &step
                )) 
    {
        report_python_error(AT, "could not parse input arguments");
        return NULL;
    }

    static struct domain D;
    
    D.boundary_number = Nid;
    
    D.timestepping_method = timestepping_method;
    D.flow_algorithm = flow_algorithm;
    D.compute_fluxes_method = compute_fluxes_method;
    

    if ( !step )
    {   
        get_python_domain(&D, domain);
        //fflush(stdout);
    }
    
    // For testing single function

    test_extrapolate_second_order_and_limit_by_vertex(&D);

    return Py_BuildValue("");
}
Exemplo n.º 5
0
void setup_stream(const char *name, const char *errors) {
    PyObject *stream;
    char buf[100];

    snprintf(buf, 20, "%s", name);
    stream = PySys_GetObject(buf);

    snprintf(buf, 20, "%s", "utf-8");
    snprintf(buf+21, 30, "%s", errors);

    if (!PyFile_SetEncodingAndErrors(stream, buf, buf+21)) 
        exit(report_python_error("Failed to set stream encoding", 1));
    
}
Exemplo n.º 6
0
PyObject *hmpp_evolve(PyObject *self, PyObject *args) 
{
    PyObject *domain;


    int timestepping_method, flow_algorithm, compute_fluxes_method;
    int skip_initial_step;
    int step;
    long Nid;
    double yieldstep, finaltime, duration, epsilon;
    double tmp_timestep;


    // Convert Python arguments to C
    if (!PyArg_ParseTuple(args, "Oddddiiiili", 
                &domain,
                &yieldstep, 
                &finaltime, 
                &duration,
                &epsilon,
                &skip_initial_step,

                &compute_fluxes_method,
                &flow_algorithm,
                &timestepping_method,
                &Nid,
                &step
                )) 
    {
        report_python_error(AT, "could not parse input arguments");
        return NULL;
    }

    static struct domain D;
    
    D.boundary_number = Nid;
    
    D.timestepping_method = timestepping_method;
    D.flow_algorithm = flow_algorithm;
    D.compute_fluxes_method = compute_fluxes_method;
    

    if ( !step )
    {   
        get_python_domain(&D, domain);
        //print_domain_struct(&D);
        //fflush(stdout);
    }
    

    //-------------------------------
    // Start evolve procedure
    //-------------------------------
    tmp_timestep = evolve( &D, 
            yieldstep, finaltime, duration, 
            epsilon, skip_initial_step, step);
/*
    update_boundary(&D);
*/
    DEBUG_LOG_PAR(" GLUE: flux_timestep    %lf\n", D.flux_timestep);
    DEBUG_LOG_PAR(" GLUE: tmp_timestep     %lf\n", tmp_timestep);
    DEBUG_LOG_PAR(" GLUE: fnltime-epsilon  %lf\n", D.finaltime - epsilon);
    DEBUG_LOG_PAR(" GLUE: yieldtime        %lf\n", D.yieldtime);
    return Py_BuildValue("d", tmp_timestep);
}