File: pover_video.cpp

package info (click to toggle)
onetbb 2022.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,440 kB
  • sloc: cpp: 129,228; ansic: 9,745; python: 808; xml: 183; objc: 176; makefile: 66; sh: 66; awk: 41; javascript: 37
file content (184 lines) | stat: -rw-r--r-- 5,367 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
    Copyright (c) 2005-2021 Intel Corporation

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

// Support for GUI display for Polygon overlay demo

#define VIDEO_WINMAIN_ARGS
#include <iostream>

#include "oneapi/tbb/tick_count.h"

#include "common/utility/get_default_num_threads.hpp"

#include "polyover.hpp"
#include "polymain.hpp"
#include "pover_video.hpp"
#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>

void rt_sleep(int msec) {
    usleep(msec * 1000);
}

#else //_WIN32

#undef OLDUNIXTIME
#undef STDTIME

#include <windows.h>

void rt_sleep(int msec) {
    Sleep(msec);
}

#endif /*  _WIN32  */

bool g_next_frame() {
    if (++n_next_frame_calls >= frame_skips) { // the data race here is benign
        n_next_frame_calls = 0;
        return gVideo->next_frame();
    }
    return gVideo->running;
}

bool g_last_frame() {
    if (n_next_frame_calls)
        return gVideo->next_frame();
    return gVideo->running;
}

bool initializeVideo(int argc, char *argv[]) {
    //pover_video *l_video = new pover_video();
    //gVideo = l_video;
    gVideo->init_console(); // don't check return code.
    gVideo->title = g_windowTitle;
    g_useGraphics = gVideo->init_window(g_xwinsize, g_ywinsize);
    return true;
}

void pover_video::on_process() {
    oneapi::tbb::tick_count t0, t1;
    double naiveParallelTime, domainSplitParallelTime;
    // create map1  These could be done in parallel, if the pseudorandom number generator were re-seeded.
    GenerateMap(
        &gPolymap1, gMapXSize, gMapYSize, gNPolygons, /*red*/ 255, /*green*/ 0, /*blue*/ 127);
    // create map2
    GenerateMap(
        &gPolymap2, gMapXSize, gMapYSize, gNPolygons, /*red*/ 0, /*green*/ 255, /*blue*/ 127);
    //
    // Draw source maps
    gDrawXOffset = map1XLoc;
    gDrawYOffset = map1YLoc;
    for (int i = 0; i < int(gPolymap1->size()); i++) {
        (*gPolymap1)[i].drawPoly();
    }
    gDrawXOffset = map2XLoc;
    gDrawYOffset = map2YLoc;
    for (int i = 0; i < int(gPolymap2->size()); i++) {
        (*gPolymap2)[i].drawPoly();
    }
    gDoDraw = true;

    // run serial map generation
    gDrawXOffset = maprXLoc;
    gDrawYOffset = maprYLoc;
    {
        RPolygon *xp =
            new RPolygon(0, 0, gMapXSize - 1, gMapYSize - 1, 0, 0, 0); // Clear the output space
        delete xp;
        t0 = oneapi::tbb::tick_count::now();
        SerialOverlayMaps(&gResultMap, gPolymap1, gPolymap2);
        t1 = oneapi::tbb::tick_count::now();
        std::cout << "Serial overlay took " << (t1 - t0).seconds() * 1000 << " msec"
                  << "\n";
        gSerialTime = (t1 - t0).seconds() * 1000;
#if _DEBUG
        CheckPolygonMap(gResultMap);
        // keep the map for comparison purposes.
#else
        delete gResultMap;
#endif
        if (gCsvFile.is_open()) {
            gCsvFile << "Serial Time," << gSerialTime << "\n";
            gCsvFile << "Threads,";
            if (gThreadsLow == THREADS_UNSET || gThreadsLow == utility::get_default_num_threads()) {
                gCsvFile << "Threads,Automatic";
            }
            else {
                for (int i = gThreadsLow; i <= gThreadsHigh; i++) {
                    gCsvFile << i;
                    if (i < gThreadsHigh)
                        gCsvFile << ",";
                }
            }
            gCsvFile << "\n";
        }
        if (gIsGraphicalVersion)
            rt_sleep(2000);
    }
    // run naive parallel map generation
    {
        Polygon_map_t *resultMap;
        if (gCsvFile.is_open()) {
            gCsvFile << "Naive Time";
        }
        NaiveParallelOverlay(resultMap, *gPolymap1, *gPolymap2);
        delete resultMap;
        if (gIsGraphicalVersion)
            rt_sleep(2000);
    }
    // run split map generation
    {
        Polygon_map_t *resultMap;
        if (gCsvFile.is_open()) {
            gCsvFile << "Split Time";
        }
        SplitParallelOverlay(&resultMap, gPolymap1, gPolymap2);
        delete resultMap;
        if (gIsGraphicalVersion)
            rt_sleep(2000);
    }
    // split, accumulating into concurrent vector
    {
        concurrent_Polygon_map_t *cresultMap;
        if (gCsvFile.is_open()) {
            gCsvFile << "Split CV time";
        }
        SplitParallelOverlayCV(&cresultMap, gPolymap1, gPolymap2);
        delete cresultMap;
        if (gIsGraphicalVersion)
            rt_sleep(2000);
    }
    // split, accumulating into ETS
    {
        ETS_Polygon_map_t *cresultMap;
        if (gCsvFile.is_open()) {
            gCsvFile << "Split ETS time";
        }
        SplitParallelOverlayETS(&cresultMap, gPolymap1, gPolymap2);
        delete cresultMap;
        if (gIsGraphicalVersion)
            rt_sleep(2000);
    }
    if (gIsGraphicalVersion)
        rt_sleep(8000);
    delete gPolymap1;
    delete gPolymap2;
#if _DEBUG
    delete gResultMap;
#endif
}