| 430 | |
| 431 | |
| 432 | void bsp_job_node_0 ( |
| 433 | bsp_context& context, |
| 434 | double& min_value, |
| 435 | double& optimal_x |
| 436 | ) |
| 437 | { |
| 438 | double left = -100; |
| 439 | double right = 100; |
| 440 | |
| 441 | min_value = std::numeric_limits<double>::infinity(); |
| 442 | double interval_width = std::abs(right-left); |
| 443 | |
| 444 | // This is doing a BSP based grid search for the minimum of f(). Here we |
| 445 | // do 100 iterations where we keep shrinking the grid size. |
| 446 | for (int i = 0; i < 100; ++i) |
| 447 | { |
| 448 | context.broadcast(left); |
| 449 | context.broadcast(right); |
| 450 | |
| 451 | for (unsigned int k = 1; k < context.number_of_nodes(); ++k) |
| 452 | { |
| 453 | std::pair<double,double> val; |
| 454 | context.receive(val); |
| 455 | if (val.second < min_value) |
| 456 | { |
| 457 | min_value = val.second; |
| 458 | optimal_x = val.first; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | interval_width *= 0.5; |
| 463 | left = optimal_x - interval_width/2; |
| 464 | right = optimal_x + interval_width/2; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | |
| 469 | void bsp_job_other_nodes ( |
nothing calls this directly
no test coverage detected