| 175 | } |
| 176 | |
| 177 | cpp::Instance makeLocalSpheres( |
| 178 | const int mpiRank, const int mpiWorldSize, box3f &bounds) |
| 179 | { |
| 180 | const float sphereRadius = 0.1; |
| 181 | std::vector<vec3f> spheres(50); |
| 182 | |
| 183 | // To simulate loading a shared dataset all ranks generate the same |
| 184 | // sphere data. |
| 185 | std::random_device rd; |
| 186 | std::mt19937 rng(rd()); |
| 187 | |
| 188 | const vec3i grid = computeGrid(mpiWorldSize); |
| 189 | const vec3i brickId(mpiRank % grid.x, |
| 190 | (mpiRank / grid.x) % grid.y, |
| 191 | mpiRank / (grid.x * grid.y)); |
| 192 | |
| 193 | // The grid is over the [-1, 1] box |
| 194 | const vec3f brickSize = vec3f(2.0) / vec3f(grid); |
| 195 | const vec3f brickLower = brickSize * brickId - vec3f(1.f); |
| 196 | const vec3f brickUpper = brickSize * brickId - vec3f(1.f) + brickSize; |
| 197 | |
| 198 | bounds.lower = brickLower; |
| 199 | bounds.upper = brickUpper; |
| 200 | |
| 201 | // Generate spheres within the box padded by the radius, so we don't need |
| 202 | // to worry about ghost bounds |
| 203 | std::uniform_real_distribution<float> distX( |
| 204 | brickLower.x + sphereRadius, brickUpper.x - sphereRadius); |
| 205 | std::uniform_real_distribution<float> distY( |
| 206 | brickLower.y + sphereRadius, brickUpper.y - sphereRadius); |
| 207 | std::uniform_real_distribution<float> distZ( |
| 208 | brickLower.z + sphereRadius, brickUpper.z - sphereRadius); |
| 209 | |
| 210 | for (auto &s : spheres) { |
| 211 | s.x = distX(rng); |
| 212 | s.y = distY(rng); |
| 213 | s.z = distZ(rng); |
| 214 | } |
| 215 | |
| 216 | cpp::Geometry sphereGeom("sphere"); |
| 217 | sphereGeom.setParam("radius", sphereRadius); |
| 218 | sphereGeom.setParam("sphere.position", cpp::CopiedData(spheres)); |
| 219 | sphereGeom.commit(); |
| 220 | |
| 221 | vec3f color(0.f, 0.f, (mpiRank + 1.f) / mpiWorldSize); |
| 222 | cpp::Material material("obj"); |
| 223 | material.setParam("kd", color); |
| 224 | material.commit(); |
| 225 | |
| 226 | cpp::GeometricModel model(sphereGeom); |
| 227 | model.setParam("material", material); |
| 228 | model.commit(); |
| 229 | |
| 230 | cpp::Group group; |
| 231 | group.setParam("geometry", cpp::CopiedData(model)); |
| 232 | group.commit(); |
| 233 | |
| 234 | cpp::Instance instance(group); |
no test coverage detected