struct leib_struct time_leibniz(long int n, int nthreads, enum leib_enum flag){ TimeStamp clk; clk.tic(); struct leib_struct ans; int chunk = 10; switch(flag){ case LEIB: ans.pi = leibniz(n); break; case PLL: ans.pi = parallel(n, nthreads); break; case PLLX: ans.pi = parallel(n, nthreads); break; case FOR: ans.pi = ompfor(n); break; case FORCHUNK: ans.pi = ompforchunk(n, chunk); break; case PLLFOR: ans.pi = parallelfor(n, nthreads); break; case SCTN: ans.pi = section(n); break; default: assrt(0 == 1); } ans.cycles = clk.toc(); return ans; }
int main() try { const int xmax = 1200; const int ymax = 600; const int x_orig = 100; const int y_orig = ymax - 100; const Point orig(x_orig,y_orig); const int r_min = 0; const int r_max = 20; const int x_scale = 20; const int y_scale = 200; Point tl(300,50); Simple_window win(tl,xmax,ymax,""); const int xlength = xmax - 200; const int ylength = ymax - 200; Axis x(Axis::x,Point(100,y_orig),xlength,xlength/x_scale,"1 == 20 pixels"); x.set_color(Color::red); win.attach(x); Axis y(Axis::y,Point(x_orig,500),ylength,ylength/y_scale,"1 == 200 pixels"); y.set_color(Color::red); win.attach(y); Open_polyline opl; opl.add(Point(orig.x,orig.y-y_scale)); win.attach(opl); for (int i = 1; i<=50; ++i) { ostringstream ss; ss << "Leibniz series, element " << i; win.set_label(ss.str()); int x = opl.point(i-1).x + x_scale; int y = orig.y - leibniz(i) * y_scale; opl.add(Point(x,y)); win.wait_for_button(); } } catch (exception& e) { cerr << "exception: " << e.what() << endl; keep_window_open(); } catch (...) { cerr << "exception\n"; keep_window_open(); }
int main() { Simple_window win {Point{100, 100}, 800, 600, "Exercise 5"}; const Point orig {300, 300}; constexpr int x_length = 400; constexpr int y_length = 400; const string x_label = "1 == 20 pixels"; const string y_label = "1 == 20 pixels"; constexpr int num_notches = 20; Axis xa {Axis::x, Point{orig.x - x_length / 2, orig.y}, x_length, num_notches, x_label}; Axis ya {Axis::y, Point{orig.x, orig.y + y_length / 2}, y_length, num_notches, y_label}; xa.set_color(Color::red); ya.set_color(Color::red); xa.label.move(-130, -20); constexpr int r_min = -10; constexpr int r_max = 11; constexpr int num_points = 400; constexpr double x_scale = 20; constexpr double y_scale = 20; win.attach(xa); win.attach(ya); for (int n = 1; n < 50; ++n) { ostringstream ss; ss << "Leibniz series approximation; n == " << n; win.set_label(ss.str()); Function leib {[n](double x) { return leibniz(n); }, r_min, r_max, orig, num_points, x_scale, y_scale}; win.attach(leib); win.wait_for_button(); win.detach(leib); } }