diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-10-05 12:02:17 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-10-05 12:02:17 -0400 |
| commit | 1728c04205136644b345ec8a6f8a406138eb7e08 (patch) | |
| tree | 28526c00cf7e83bf178640d02f992c149dd6cd50 | |
| parent | b2d3054379f1691600c0e36163b42d14972ede40 (diff) | |
| download | balls-1728c04205136644b345ec8a6f8a406138eb7e08.zip | |
create balls in parallel
| -rw-r--r-- | balls.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -6,6 +6,7 @@ #include "balls.h" using namespace std; +using namespace oneapi::tbb; #define VMAX_INIT 0.05 /* max initial velocity [m/frame] */ @@ -142,22 +143,17 @@ reshape(int w, int h) { vector<Ball> makeBalls(unsigned int n) { vector<Ball> balls(n); - vector<Point> ps = noOverlapCircles(n); - unsigned int i; + vector<Point> positions = noOverlapCircles(n); - for (i = 0; i < n; i++) { + parallel_for(size_t(0), balls.size(), [&balls, positions] (size_t i) { cout << "Creating ball " << i << "\n"; - balls[i].p = ps[i]; - + balls[i].p = positions[i]; balls[i].v.x = randDouble(-VMAX_INIT, VMAX_INIT); balls[i].v.y = randDouble(-VMAX_INIT, VMAX_INIT); - balls[i].r = randDouble(RMIN, RMAX); - balls[i].m = mass(balls[i].r); - balls[i].color = randColor(); - } + }); return balls; } |