Esempio n. 1
0
static void parallel_thread(void)
{
    unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
#if RUNTIME == RUNTIME_SERIAL
    for ( int y = starty; y < stopy; y++ )
#elif RUNTIME == RUNTIME_OPENMP
#pragma omp parallel for
    for ( int y = starty; y < stopy; y++ )
#elif RUNTIME == RUNTIME_CILK
    _Cilk_for(int y = starty; y < stopy; y++)
#elif RUNTIME == RUNTIME_TBB
    tbb::parallel_for(starty, stopy, [mboxsize] (int y)
#endif
    {
        unsigned int serial = 1;
        unsigned int local_mbox[mboxsize];
        memset(local_mbox, 0, mboxsize);
        drawing_area drawing(startx, totaly - y, stopx - startx, 1);
        for ( int x = startx; x < stopx; x++ ) {
            color_t c = render_one_pixel(x, y, local_mbox, serial, startx, stopx, starty, stopy);
            drawing.put_pixel(c);
        }
        video->next_frame();
    }
#if RUNTIME == RUNTIME_TBB
    );
#endif
}
Esempio n. 2
0
//todo: comment out following routine  in TBB implementation
///*
static void draw_task (void)
{
    // thread-local storage
    unsigned int serial = 1;
    unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
    unsigned int * local_mbox = (unsigned int *) alloca(mboxsize);
    memset(local_mbox,0,mboxsize);

    for (int y = starty; y < stopy; y++) { {
        drawing_area drawing(startx, totaly-y, stopx-startx, 1);
        for (int x = startx; x < stopx; x++) {
            color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy);
            drawing.put_pixel(c);
        } }
        if(!video->next_frame()) return;
    }
}
Esempio n. 3
0
    void operator() (const tbb::blocked_range<int> &r) const
    {
        // task-local storage
        unsigned int serial = 1;
        unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
        unsigned int * local_mbox = (unsigned int *) alloca(mboxsize);
        memset(local_mbox,0,mboxsize);

        for (int y = r.begin(); y != r.end(); ++y) { {
            drawing_area drawing(startx, totaly-y, stopx-startx, 1);
            for (int x = startx; x < stopx; x++) {
                color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy);
                drawing.put_pixel(c);
            } }
            if(!video->next_frame()) return;
        }
    }
Esempio n. 4
0
    void operator() (const tbb::blocked_range2d<int> &r) const
    {
       // task-local storage
        unsigned int serial = 1;
        unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
        unsigned int * local_mbox = (unsigned int *) alloca(mboxsize);
        memset(local_mbox,0,mboxsize);
#ifdef MARK_RENDERING_AREA
        // compute thread number while first task run
        thread_id_t::reference thread_id = thread_ids.local();
        if (thread_id == -1) thread_id = thread_number++;
        // choose thread color
        int pos = thread_id % NUM_COLORS;
        if(video->running) {
            drawing_area drawing(r.cols().begin(), totaly-r.rows().end(), r.cols().end() - r.cols().begin(), r.rows().end()-r.rows().begin());
            for (int i = 1, y = r.rows().begin(); y != r.rows().end(); ++y, i++) {
                drawing.set_pos(0, drawing.size_y-i);
                for (int x = r.cols().begin(); x != r.cols().end(); x++) {
                    int d = (y % 3 == 0) ? 2 : 1;
                    drawing.put_pixel(video->get_color(colors[pos][0]/d, colors[pos][1]/d, colors[pos][2]/d));
                }
            }
        }
#endif
        if(video->next_frame()) {
            drawing_area drawing(r.cols().begin(), totaly-r.rows().end(), r.cols().end() - r.cols().begin(), r.rows().end()-r.rows().begin());
            for (int i = 1, y = r.rows().begin(); y != r.rows().end(); ++y, i++) {
                drawing.set_pos(0, drawing.size_y-i);
                for (int x = r.cols().begin(); x != r.cols().end(); x++) {
#ifdef MARK_RENDERING_AREA
                    float alpha = y==r.rows().begin()||y==r.rows().end()-1||x==r.cols().begin()||x==r.cols().end()-1
                                ? border_alpha : inner_alpha;
                    color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy, colors[pos], alpha);
#else
                    color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy);
#endif
                    drawing.put_pixel(c);
                }
            }
        }
    }
Esempio n. 5
0
    void operator () (const tbb::blocked_range <int> &r) const {

        unsigned int serial = 1;
        unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
        unsigned int * local_mbox = (unsigned int *) alloca(mboxsize);
        memset(local_mbox,0,mboxsize);

        for (int y=r.begin(); y!=r.end(); ++y) {
            drawing_area drawing(startx, totaly-y, stopx-startx, 1);

            // Acquire mutex to protect pixel calculation from multithreaded access (Needed?)
//			pthread_mutex_lock (&rgb_mutex);
            for (int x = startx; x < stopx; x++) {
                color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy);
                drawing.put_pixel(c);
            }

            // Release the mutex after pixel calculation complete
//			pthread_mutex_unlock (&rgb_mutex);

            if(!video->next_frame()) tbb::task::self().cancel_group_execution();
        }
    }