Esempio n. 1
0
/*
 * All of the threads in the pool wait on a barrier until
 * they are told to wake up and do some work.  At present,
 * the only actions they can take are to render the scene
 * or to terminate be returning to the master.
 */
void * thread_worker(void * voidparms) {
    thr_parms * parms = (thr_parms *) voidparms;

#if defined(USECPUAFFINITY)
    /* Optionally set CPU affinity mask for each thread */
    int cpuaffinity = -1;

#if defined(__MIC__)
    /* On the MIC platform, we want 4 threads per CPU, with a hard-coded  */
    /* mapping that puts neighboring workers on neighboring CPUs with the */
    /* hope of better L1/L2 cache sharing                                 */
    cpuaffinity = parms->tid / 4;
#endif

    if (cpuaffinity > 0) {
        rt_thread_set_self_cpuaffinity(cpuaffinity);
#if 0
        printf("Thread[%d] setting affinity to %d\n", parms->tid, parms->tid / 4);
#endif
    }
#endif

    while (rt_thread_barrier(parms->runbar, 0)) {
        thread_trace(parms);
    }
    return NULL;
}
Esempio n. 2
0
void trace_shm(scenedef scene, /*char * buffer,  */ int startx, int stopx, int starty, int stopy) {

  thr_parms * parms;

  parms = (thr_parms *) rt_getmem(sizeof(thr_parms));  

  parms->tid=0;
  parms->nthr=1;
  parms->scene=scene;
  parms->startx=startx;
  parms->stopx=stopx;
  parms->starty=starty;
  parms->stopy=stopy;

  thread_trace(parms);

  rt_freemem(parms);
}
Esempio n. 3
0
/*
 * Render the scene
 */
void renderscene(scenedef * scene) {
    flt runtime;
    rt_timerhandle rtth; /* render time timer handle */

    /* if certain key aspects of the scene parameters have been changed */
    /* since the last frame rendered, or when rendering the scene the   */
    /* first time, various setup, initialization and memory allocation  */
    /* routines need to be run in order to prepare for rendering.       */
    if (scene->scenecheck)
        rendercheck(scene);

    if (scene->mynode == 0)
        rt_ui_progress(0);     /* print 0% progress at start of rendering */


    /*
     * Core Ray Tracing Code
     *
     * Ideally, as little as possible other than this code should be
     * executed for rendering a frame.  Most if not all memory allocations
     * should be done outside of the core code, and all setup should be
     * done outside of here.  This will give the best speed when rendering
     * walk-throughs and similar things.
     */

    rtth=rt_timer_create();  /* create/init rendering timer              */
    rt_timer_start(rtth);    /* start ray tracing timer                  */

    camera_init(scene);      /* Initialize all aspects of camera system  */

#if defined(MPI) && defined(THR)
    /* reset the rows counter for this frame */
    rt_atomic_int_set(((thr_parms *) scene->threadparms)[0].rowsdone, 0);
#endif

#ifdef THR
    /* if using threads, wake up the child threads...  */
    rt_thread_barrier(((thr_parms *) scene->threadparms)[0].runbar, 1);
#endif

#ifdef MPI
    /* if using message passing, start persistent receives */
    rt_start_scanlinereceives(scene->parbuf); /* start scanline receives */
#endif

    /* Actually Ray Trace The Image */
    thread_trace(&((thr_parms *) scene->threadparms)[0]);

#ifdef MPI
    rt_waitscanlines(scene->parbuf);  /* wait for all scanlines to recv/send  */
#endif

    rt_timer_stop(rtth);              /* stop timer for ray tracing runtime   */
    runtime=rt_timer_time(rtth);
    rt_timer_destroy(rtth);

    /*
     * End of Core Ray Tracing Code
     *
     * Anything after here should be UI, tear-down, or reset code
     *
     */

    if (scene->mynode == 0) {
        char msgtxt[256];

        rt_ui_progress(100); /* print 100% progress when finished rendering */

        sprintf(msgtxt, "\n  Ray Tracing Time: %10.4f seconds", runtime);
        rt_ui_message(MSG_0, msgtxt);

        if (scene->writeimagefile)
            renderio(scene);
    }
} /* end of renderscene() */