| 1 |
/* |
| 2 |
Copyright (c) 2005-2021 Intel Corporation |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#define VIDEO_WINMAIN_ARGS |
| 18 |
|
| 19 |
#include <cstdio> |
| 20 |
|
| 21 |
#include <iostream> |
| 22 |
|
| 23 |
#include "oneapi/tbb/tick_count.h" |
| 24 |
|
| 25 |
#include "common/utility/utility.hpp" |
| 26 |
|
| 27 |
#include "fractal.hpp" |
| 28 |
#include "fractal_video.hpp" |
| 29 |
|
| 30 |
bool silent = false; |
| 31 |
bool single = false; |
| 32 |
bool schedule_auto = false; |
| 33 |
int grain_size = 8; |
| 34 |
|
| 35 |
int main(int argc, char *argv[]) { |
| 36 |
oneapi::tbb::tick_count mainStartTime = oneapi::tbb::tick_count::now(); |
| 37 |
|
| 38 |
// It is used for console mode for test with different number of threads and also has |
| 39 |
// meaning for GUI: threads.first - use separate event/updating loop thread (>0) or not (0). |
| 40 |
// threads.second - initialization value for scheduler |
| 41 |
utility::thread_number_range threads(utility::get_default_num_threads); |
| 42 |
int num_frames = -1; |
| 43 |
int max_iterations = 1000000; |
| 44 |
|
| 45 |
// command line parsing |
| 46 |
utility::parse_cli_arguments( |
| 47 |
argc, |
| 48 |
argv, |
| 49 |
utility::cli_argument_pack() |
| 50 |
//"-h" option for displaying help is present implicitly |
| 51 |
.positional_arg(threads, "n-of-threads", utility::thread_number_range_desc) |
| 52 |
.positional_arg( |
| 53 |
num_frames, "n-of-frames", "number of frames the example processes internally") |
| 54 |
.positional_arg( |
| 55 |
max_iterations, "max-of-iterations", "maximum number of the fractal iterations") |
| 56 |
.positional_arg(grain_size, "grain-size", "the grain size value") |
| 57 |
.arg(schedule_auto, "use-auto-partitioner", "use oneapi::tbb::auto_partitioner") |
| 58 |
.arg(silent, "silent", "no output except elapsed time") |
| 59 |
.arg(single, "single", "process only one fractal")); |
| 60 |
|
| 61 |
fractal_video video; |
| 62 |
|
| 63 |
// video layer init |
| 64 |
if (video.init_window(1024, 512)) { |
| 65 |
video.calc_fps = false; |
| 66 |
video.threaded = threads.first > 0; |
| 67 |
// initialize fractal group |
| 68 |
fractal_group fg(video.get_drawing_memory(), threads.last, max_iterations, num_frames); |
| 69 |
video.set_fractal_group(fg); |
| 70 |
// main loop |
| 71 |
video.main_loop(); |
| 72 |
} |
| 73 |
else if (video.init_console()) { |
| 74 |
// in console mode we always have limited number of frames |
| 75 |
num_frames = num_frames < 0 ? 1 : num_frames; |
| 76 |
for (int p = threads.first; p <= threads.last; p = threads.step(p)) { |
| 77 |
if (!silent) |
| 78 |
printf("Threads = %d\n", p); |
| 79 |
fractal_group fg(video.get_drawing_memory(), p, max_iterations, num_frames); |
| 80 |
fg.run(!single); |
| 81 |
} |
| 82 |
} |
| 83 |
video.terminate(); |
| 84 |
utility::report_elapsed_time((oneapi::tbb::tick_count::now() - mainStartTime).seconds()); |
| 85 |
return 0; |
| 86 |
} |