diff --git a/src/array_slice.cpp b/src/array_slice.cpp index 42e5be8b7..b9905c16f 100644 --- a/src/array_slice.cpp +++ b/src/array_slice.cpp @@ -20,6 +20,7 @@ h5fields.cpp */ +#include #include #include #include @@ -277,7 +278,7 @@ static void get_array_slice_chunkloop(fields_chunk *fc, int ichnk, component cgr for (int i = 0; i < data->rank; ++i) { direction d = data->ds[i]; int isd = isS.in_direction(d), ied = ieS.in_direction(d); - start[i] = (min(isd, ied) - data->min_corner.in_direction(d)) / 2; + start[i] = (std::min(isd, ied) - data->min_corner.in_direction(d)) / 2; count[i] = abs(ied - isd) / 2 + 1; slice_size *= count[i]; if (ied < isd) offset[permute.in_direction(d)] = count[i] - 1; diff --git a/src/bands.cpp b/src/bands.cpp index 9449c792f..d1b141863 100644 --- a/src/bands.cpp +++ b/src/bands.cpp @@ -15,6 +15,7 @@ % Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #include #include #include @@ -33,9 +34,9 @@ namespace meep { double fields::last_source_time() { double last_time = 0; - if (sources != NULL) last_time = max(last_time, sources->last_time_max()); + if (sources != NULL) last_time = std::max(last_time, sources->last_time_max()); for (int i = 0; i < num_chunks; i++) - if (chunks[i]->is_mine()) last_time = max(last_time, chunks[i]->last_source_time()); + if (chunks[i]->is_mine()) last_time = std::max(last_time, chunks[i]->last_source_time()); return max_to_all(last_time); } diff --git a/src/dft.cpp b/src/dft.cpp index 60896fcf9..8be4173eb 100644 --- a/src/dft.cpp +++ b/src/dft.cpp @@ -772,7 +772,7 @@ complex dft_chunk::process_dft_component(int rank, direction *ds, ivec m for (int i = 0; i < rank; ++i) { direction d = ds[i]; int isd = isS.in_direction(d), ied = ieS.in_direction(d); - start[i] = (min(isd, ied) - min_corner.in_direction(d)) / 2; + start[i] = (std::min(isd, ied) - min_corner.in_direction(d)) / 2; file_count[i] = abs(ied - isd) / 2 + 1; if (ied < isd) file_offset[permute.in_direction(d)] = file_count[i] - 1; array_count[i] = (max_corner.in_direction(d) - min_corner.in_direction(d)) / 2 + 1; @@ -944,7 +944,7 @@ complex fields::process_dft_component(dft_chunk **chunklists, int num_ch LOOP_OVER_DIRECTIONS(chunk->fc->gv.dim, d) { this_bufsz *= (chunk->ie.in_direction(d) - chunk->is.in_direction(d)) / 2 + 1; } - bufsz = max(bufsz, this_bufsz); + bufsz = std::max(bufsz, this_bufsz); } am_now_working_on(MpiAllTime); max_corner = max_to_all(max_corner); diff --git a/src/h5fields.cpp b/src/h5fields.cpp index 1c597e1d1..672b273d1 100644 --- a/src/h5fields.cpp +++ b/src/h5fields.cpp @@ -86,7 +86,7 @@ static void h5_findsize_chunkloop(fields_chunk *fc, int ichnk, component cgrid, LOOP_OVER_DIRECTIONS(fc->gv.dim, d) { bufsz *= (ie.in_direction(d) - is.in_direction(d)) / 2 + 1; } - data->bufsz = max(data->bufsz, bufsz); + data->bufsz = std::max(data->bufsz, bufsz); } static void h5_output_chunkloop(fields_chunk *fc, int ichnk, component cgrid, ivec is, ivec ie, @@ -124,7 +124,7 @@ static void h5_output_chunkloop(fields_chunk *fc, int ichnk, component cgrid, iv for (int i = 0; i < data->rank; ++i) { direction d = data->ds[i]; int isd = isS.in_direction(d), ied = ieS.in_direction(d); - start[i] = (min(isd, ied) - data->min_corner.in_direction(d)) / 2; + start[i] = (std::min(isd, ied) - data->min_corner.in_direction(d)) / 2; count[i] = abs(ied - isd) / 2 + 1; if (ied < isd) offset[permute.in_direction(d)] = count[i] - 1; } diff --git a/src/integrate.cpp b/src/integrate.cpp index 0fdfb5433..7445df910 100644 --- a/src/integrate.cpp +++ b/src/integrate.cpp @@ -119,11 +119,11 @@ static void integrate_chunkloop(fields_chunk *fc, int ichunk, component cgrid, i } complex integrand = data->integrand(fvals, loc, data->integrand_data_); - maxabs = max(maxabs, abs(integrand)); + maxabs = std::max(maxabs, abs(integrand)); sum += integrand * IVEC_LOOP_WEIGHT(s0, s1, e0, e1, dV0 + dV1 * loop_i2); } - data->maxabs = max(data->maxabs, maxabs); + data->maxabs = std::max(data->maxabs, maxabs); data->sum += sum; } diff --git a/src/integrate2.cpp b/src/integrate2.cpp index cc22b0535..48e255d74 100644 --- a/src/integrate2.cpp +++ b/src/integrate2.cpp @@ -177,11 +177,11 @@ static void integrate_chunkloop(fields_chunk *fc, int ichunk, component cgrid, i } complex integrand = data->integrand(fvals, loc, data->integrand_data_); - maxabs = max(maxabs, abs(integrand)); + maxabs = std::max(maxabs, abs(integrand)); sum += integrand * IVEC_LOOP_WEIGHT(s0, s1, e0, e1, dV0 + dV1 * loop_i2); } - data->maxabs = max(data->maxabs, maxabs); + data->maxabs = std::max(data->maxabs, maxabs); data->sum += sum; } diff --git a/src/loop_in_chunks.cpp b/src/loop_in_chunks.cpp index d84433c18..eabd4c825 100644 --- a/src/loop_in_chunks.cpp +++ b/src/loop_in_chunks.cpp @@ -459,22 +459,22 @@ void fields::loop_in_chunks(field_chunkloop chunkloop, void *chunkloop_data, con e0c.set_direction(d, e1.in_direction(dS)); } if (iecS.in_direction(dS) == iscS.in_direction(dS)) { - double w = min(s0c.in_direction(d), e0c.in_direction(d)); + double w = std::min(s0c.in_direction(d), e0c.in_direction(d)); s0c.set_direction(d, w); e0c.set_direction(d, w); s1c.set_direction(d, w); e1c.set_direction(d, w); } else if (iecS.in_direction(dS) == iscS.in_direction(dS) + 1 * 2) { - double w = min(s0c.in_direction(d), e1c.in_direction(d)); + double w = std::min(s0c.in_direction(d), e1c.in_direction(d)); s0c.set_direction(d, w); e1c.set_direction(d, w); - w = min(s1c.in_direction(d), e0c.in_direction(d)); + w = std::min(s1c.in_direction(d), e0c.in_direction(d)); s1c.set_direction(d, w); e0c.set_direction(d, w); } else if (iecS.in_direction(dS) == iscS.in_direction(dS) + 2 * 2) { - double w = min(s1c.in_direction(d), e1c.in_direction(d)); + double w = std::min(s1c.in_direction(d), e1c.in_direction(d)); s1c.set_direction(d, w); e1c.set_direction(d, w); } diff --git a/src/meep_internals.hpp b/src/meep_internals.hpp index 0bb56b5a5..aeebb7bc3 100644 --- a/src/meep_internals.hpp +++ b/src/meep_internals.hpp @@ -24,14 +24,6 @@ namespace meep { #define DOCMP for (int cmp = 0; cmp < 2 - is_real; cmp++) #define DOCMP2 for (int cmp = 0; cmp < 2; cmp++) -inline double max(double a, double b) { return (a > b) ? a : b; } -inline double min(double a, double b) { return (a < b) ? a : b; } -inline int max(int a, int b) { return (a > b) ? a : b; } -inline size_t max(size_t a, size_t b) { return (a > b) ? a : b; } -inline int min(int a, int b) { return (a < b) ? a : b; } -static inline int abs(int a) { return a < 0 ? -a : a; } -static inline double abs(double a) { return fabs(a); } - // note that C99 has a round() function, but I don't want to rely on it static inline int my_round(double x) { return int(floor(fabs(x) + 0.5) * (x < 0 ? -1 : 1)); } diff --git a/src/sources.cpp b/src/sources.cpp index 4308377b0..65eda579c 100644 --- a/src/sources.cpp +++ b/src/sources.cpp @@ -53,7 +53,7 @@ src_time *src_time::add_to(src_time *others, src_time **added) const { } double src_time::last_time_max(double after) { - after = max(last_time(), after); + after = std::max(last_time(), after); if (next) return next->last_time_max(after); else diff --git a/src/structure.cpp b/src/structure.cpp index a269bee83..576b2f539 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -937,14 +937,14 @@ structure_chunk::structure_chunk(const grid_volume &thegv, const volume &vol_lim double structure::max_eps() const { double themax = 0.0; for (int i = 0; i < num_chunks; i++) - if (chunks[i]->is_mine()) themax = max(themax, chunks[i]->max_eps()); + if (chunks[i]->is_mine()) themax = std::max(themax, chunks[i]->max_eps()); return max_to_all(themax); } double fields::max_eps() const { double themax = 0.0; for (int i = 0; i < num_chunks; i++) - if (chunks[i]->is_mine()) themax = max(themax, chunks[i]->s->max_eps()); + if (chunks[i]->is_mine()) themax = std::max(themax, chunks[i]->s->max_eps()); return max_to_all(themax); } @@ -954,7 +954,7 @@ double structure_chunk::max_eps() const { direction d = component_direction(c); if (chi1inv[c][d]) for (size_t i = 0; i < gv.ntot(); i++) - themax = max(themax, 1 / chi1inv[c][d][i]); + themax = std::max(themax, 1 / chi1inv[c][d][i]); } return themax; } diff --git a/src/vec.cpp b/src/vec.cpp index c7951768b..c704749dd 100644 --- a/src/vec.cpp +++ b/src/vec.cpp @@ -131,7 +131,7 @@ component first_field_component(field_type ft) { vec min(const vec &vec1, const vec &vec2) { vec m(vec1.dim); LOOP_OVER_DIRECTIONS(vec1.dim, d) { - m.set_direction(d, min(vec1.in_direction(d), vec2.in_direction(d))); + m.set_direction(d, std::min(vec1.in_direction(d), vec2.in_direction(d))); } return m; } @@ -139,7 +139,7 @@ vec min(const vec &vec1, const vec &vec2) { vec max(const vec &vec1, const vec &vec2) { vec m(vec1.dim); LOOP_OVER_DIRECTIONS(vec1.dim, d) { - m.set_direction(d, max(vec1.in_direction(d), vec2.in_direction(d))); + m.set_direction(d, std::max(vec1.in_direction(d), vec2.in_direction(d))); } return m; } @@ -147,7 +147,7 @@ vec max(const vec &vec1, const vec &vec2) { ivec min(const ivec &ivec1, const ivec &ivec2) { ivec m(ivec1.dim); LOOP_OVER_DIRECTIONS(ivec1.dim, d) { - m.set_direction(d, min(ivec1.in_direction(d), ivec2.in_direction(d))); + m.set_direction(d, std::min(ivec1.in_direction(d), ivec2.in_direction(d))); } return m; } @@ -155,7 +155,7 @@ ivec min(const ivec &ivec1, const ivec &ivec2) { ivec max(const ivec &ivec1, const ivec &ivec2) { ivec m(ivec1.dim); LOOP_OVER_DIRECTIONS(ivec1.dim, d) { - m.set_direction(d, max(ivec1.in_direction(d), ivec2.in_direction(d))); + m.set_direction(d, std::max(ivec1.in_direction(d), ivec2.in_direction(d))); } return m; } @@ -195,7 +195,7 @@ double volume::full_volume() const { double volume::diameter() const { double diam = 0.0; - LOOP_OVER_DIRECTIONS(dim, d) { diam = max(diam, in_direction(d)); } + LOOP_OVER_DIRECTIONS(dim, d) { diam = std::max(diam, in_direction(d)); } return diam; } @@ -203,8 +203,8 @@ volume volume::intersect_with(const volume &a) const { if (a.dim != dim) meep::abort("Can't intersect volumes of dissimilar dimensions.\n"); volume result(dim); LOOP_OVER_DIRECTIONS(dim, d) { - double minval = max(in_direction_min(d), a.in_direction_min(d)); - double maxval = min(in_direction_max(d), a.in_direction_max(d)); + double minval = std::max(in_direction_min(d), a.in_direction_min(d)); + double maxval = std::min(in_direction_max(d), a.in_direction_max(d)); if (minval > maxval) return volume(zero_vec(dim), zero_vec(dim)); result.set_direction_min(d, minval); result.set_direction_max(d, maxval); @@ -215,8 +215,8 @@ volume volume::intersect_with(const volume &a) const { bool volume::intersects(const volume &a) const { if (a.dim != dim) meep::abort("Can't intersect volumes of dissimilar dimensions.\n"); LOOP_OVER_DIRECTIONS(dim, d) { - double minval = max(in_direction_min(d), a.in_direction_min(d)); - double maxval = min(in_direction_max(d), a.in_direction_max(d)); + double minval = std::max(in_direction_min(d), a.in_direction_min(d)); + double maxval = std::min(in_direction_max(d), a.in_direction_max(d)); if (minval > maxval) return false; } return true; @@ -757,8 +757,8 @@ bool grid_volume::intersect_with(const grid_volume &vol_in, grid_volume *interse int temp_num[3] = {0, 0, 0}; ivec new_io(dim); LOOP_OVER_DIRECTIONS(dim, d) { - int minval = max(little_corner().in_direction(d), vol_in.little_corner().in_direction(d)); - int maxval = min(big_corner().in_direction(d), vol_in.big_corner().in_direction(d)); + int minval = std::max(little_corner().in_direction(d), vol_in.little_corner().in_direction(d)); + int maxval = std::min(big_corner().in_direction(d), vol_in.big_corner().in_direction(d)); if (minval >= maxval) return false; temp_num[d % 3] = (maxval - minval) / 2; new_io.set_direction(d, minval); @@ -825,7 +825,7 @@ vec grid_volume::loc_at_resolution(ptrdiff_t index, double res) const { const direction d = (direction)dd; if (has_boundary(High, d)) { const double dist = boundary_location(High, d) - boundary_location(Low, d); - const int nhere = max(1, (int)floor(dist * res + 0.5)); + const int nhere = std::max(1, (int)floor(dist * res + 0.5)); where.set_direction(d, origin.in_direction(d) + ((index % nhere) + 0.5) * (1.0 / res)); index /= nhere; } @@ -839,7 +839,7 @@ size_t grid_volume::ntot_at_resolution(double res) const { if (has_boundary(High, (direction)d)) { const double dist = boundary_location(High, (direction)d) - boundary_location(Low, (direction)d); - mytot *= max(size_t(1), (size_t)(dist * res + 0.5)); + mytot *= std::max(size_t(1), (size_t)(dist * res + 0.5)); } return mytot; } @@ -1019,7 +1019,7 @@ void grid_volume::find_best_split(int desired_chunks, bool fragment_cost, std::complex costs = get_split_costs(d, split_point, fragment_cost); double left_cost = real(costs), right_cost = imag(costs); double total_cost = left_cost + right_cost; - double split_measure = max(left_cost / (desired_chunks / 2), right_cost / (desired_chunks - (desired_chunks / 2))); + double split_measure = std::max(left_cost / (desired_chunks / 2), right_cost / (desired_chunks - (desired_chunks / 2))); // Give a 30% preference to the longest axis, as a heuristic to prefer lower communication costs // when the split_measure is somewhat close. TODO: use a data-driven communication cost function. if (d == longest_axis) split_measure *= 0.7; diff --git a/tests/h5test.cpp b/tests/h5test.cpp index 75842fe81..bc681780c 100644 --- a/tests/h5test.cpp +++ b/tests/h5test.cpp @@ -11,6 +11,8 @@ #include "config.h" using namespace meep; using std::complex; +using std::max; +using std::min; const double xsize = 2.0; const double ysize = 2.0; @@ -157,9 +159,9 @@ bool check_2d(double eps(const vec &), double a, int splitting, symfunc Sf, doub double err = compare(h5data[idx], get_reim(f.get_field(cs, loc) * ph, reim), name, i0, i1, 0); - err_max = max(err, err_max); - data_min = min(data_min, h5data[idx]); - data_max = max(data_max, h5data[idx]); + err_max = max(err, err_max); + data_min = min(data_min, h5data[idx]); + data_max = max(data_max, h5data[idx]); } } delete[] h5data; @@ -269,8 +271,8 @@ bool check_3d(double eps(const vec &), double a, int splitting, symfunc Sf, comp double err = compare(h5data[idx], get_reim(f.get_field(cs, loc) * ph, reim), name, i0, i1, i2); err_max = max(err, err_max); - data_min = min(data_min, h5data[idx]); - data_max = max(data_max, h5data[idx]); + data_min = min(data_min, h5data[idx]); + data_max = max(data_max, h5data[idx]); } } } @@ -348,8 +350,8 @@ bool check_2d_monitor(double eps(const vec &), double a, int splitting, symfunc for (int i = 0; i < f.t; ++i) { double err = compare(h5data[i], get_reim(mon[i], reim), name, i, 0, 0); err_max = max(err, err_max); - data_min = min(data_min, h5data[i]); - data_max = max(data_max, h5data[i]); + data_min = min(data_min, h5data[i]); + data_max = max(data_max, h5data[i]); } delete[] h5data; }