-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (59 loc) · 2.31 KB
/
Copy pathmain.cpp
File metadata and controls
77 lines (59 loc) · 2.31 KB
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
#include <iostream>
#include <string>
#include <vector>
#ifdef _OPENMP
#include <opencv2/opencv.hpp>
#include <omp.h>
#endif
void printOpenMPInfo();
int main() {
printOpenMPInfo();
std::cout << std::endl;
std::cout << "=== OpenMP Info ===" << std::endl;
std::cout << "Max threads: " << omp_get_max_threads() << std::endl;
// 4K Image
cv::Mat image(2160, 3840, CV_8UC3, cv::Scalar(0, 255, 0));
cv::Mat gray_image(image.rows, image.cols, CV_8U);
std::cout << "\nParallel processing start..." << std::endl;
double start_time = omp_get_wtime();
#pragma omp parallel for
for (int r = 0; r < image.rows; ++r) {
if (r % 500 == 0) {
#pragma omp critical
{
std::cout << "Row " << r << " - Thread ID: " << omp_get_thread_num() << std::endl;
}
}
const cv::Vec3b* ptr_in = image.ptr<cv::Vec3b>(r);
uchar* ptr_out = gray_image.ptr<uchar>(r);
for (int c = 0; c < image.cols; ++c) {
ptr_out[c] = static_cast<uchar>(0.299 * ptr_in[c][2] + 0.587 * ptr_in[c][1] + 0.114 * ptr_in[c][0]);
}
}
double end_time = omp_get_wtime();
std::cout << "Processing done! Time: " << (end_time - start_time) << " seconds" << std::endl;
std::cout << "Result channels: " << gray_image.channels() << std::endl;
return 0;
}
void printOpenMPInfo() {
#ifdef _OPENMP
long value = _OPENMP;
std::string versionStr = "Unknown Version";
// OpenMP specification mapping (MSVC Experimental value included)
if (value == 200505) versionStr = "2.5";
else if (value == 200805) versionStr = "3.0";
else if (value == 201107) versionStr = "3.1";
else if (value == 201307) versionStr = "4.0";
else if (value == 201511) versionStr = "4.5";
else if (value == 201811) versionStr = "5.0";
else if (value == 202011) versionStr = "5.1";
else if (value == 202111) versionStr = "5.2";
else if (value == 202311) versionStr = "6.0 (Preview or Final)";
else if (value == 2019) versionStr = "3.1 ~ 4.5 (MSVC Experimental SIMD/LLVM)";
std::cout << "OpenMP is enabled.\n";
std::cout << "Constant value (_OPENMP): " << value << "\n";
std::cout << "Supported OpenMP version: " << versionStr << "\n";
#else
std::cout << "OpenMP is not enabled.\n";
#endif
}