Skip to content

Commit da09424

Browse files
committed
simplify omp scheduling in phongplot
1 parent 072e352 commit da09424

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

src/plot.cpp

+12-29
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,9 @@ std::pair<Position, Direction> RayTracePlot::get_pixel_ray(
12031203
double p1 = static_cast<double>(pixels_[1]);
12041204
double vert_fov_radians = horiz_fov_radians * p1 / p0;
12051205

1206-
// This can be changed to alter the perspective distortion effect.
1207-
// This is in units of cm. Most of the time does not need to be changed.
1206+
// focal_plane_dist can be changed to alter the perspective distortion
1207+
// effect. This is in units of cm. This seems to look good most of the
1208+
// time. TODO let this variable be set through XML.
12081209
constexpr double focal_plane_dist = 10.0;
12091210
const double dx = 2.0 * focal_plane_dist * std::tan(0.5 * horiz_fov_radians );
12101211
const double dy = p1 / p0 * dx;
@@ -1551,36 +1552,18 @@ void PhongPlot::create_output() const
15511552
size_t height = pixels_[1];
15521553
ImageData data({width, height}, not_found_);
15531554

1554-
#pragma omp parallel
1555-
{
1555+
#pragma omp parallel for schedule(dynamic) collapse(2)
1556+
for (int horiz=0; horiz<pixels_[0]; ++horiz) {
1557+
for (int vert=0; vert<pixels_[1]; ++vert) {
15561558

1557-
#ifdef _OPENMP
1558-
const int n_threads = omp_get_max_threads();
1559-
const int tid = omp_get_thread_num();
1560-
#else
1561-
int n_threads = 1;
1562-
int tid = 0;
1563-
#endif
1559+
// RayTracePlot implements camera ray generation
1560+
std::pair<Position, Direction> ru = get_pixel_ray(horiz, vert);
1561+
PhongRay ray(ru.first, ru.second, *this);
15641562

1565-
int vert = tid;
1566-
for (int iter = 0; iter <= pixels_[1] / n_threads; iter++) {
1567-
if (vert < pixels_[1]) {
1568-
for (int horiz = 0; horiz < pixels_[0]; ++horiz) {
1569-
1570-
// RayTracePlot implements camera ray generation
1571-
std::pair<Position, Direction> ru = get_pixel_ray(horiz, vert);
1572-
PhongRay ray(ru.first, ru.second, *this);
1573-
1574-
ray.trace();
1575-
data(horiz, vert) = ray.result_color();
1576-
}
1577-
} // end "if" vert in correct range
1578-
1579-
// TODO: can maybe remove this barrier
1580-
#pragma omp barrier
1581-
vert += n_threads;
1563+
ray.trace();
1564+
data(horiz, vert) = ray.result_color();
15821565
}
1583-
} // end omp parallel
1566+
}
15841567

15851568
#ifdef USE_LIBPNG
15861569
output_png(path_plot(), data);

0 commit comments

Comments
 (0)