RRTNode *nn = nodes[0];
float mcost = (*cost)(nn, node);
unsigned int i;
+ // TODO fix see, user-defined reductions
#pragma omp parallel for
for (i = 0; i < nodes.size(); i++) {
if ((*cost)(nodes[i], node) < mcost) {
float (*cost)(RRTNode *, RRTNode *))
{
int iy = floor(node->y() / IYSTEP) + floor(IYSIZE / 2);
- RRTNode *nn = nullptr;
- float mc = 9999;
+ struct mcnn nn;
+ nn.nn = nullptr;
+ nn.mc = 9999;
unsigned int i = 0; // vector step
unsigned int j = 0; // array step
int iyj = 0;
- while (mc > j * IYSTEP) {
+ while (nn.mc > j * IYSTEP) {
iyj = (int) (iy + j);
if (iyj >= IYSIZE)
iyj = IYSIZE - 1;
- #pragma omp parallel for
+ #pragma omp parallel for reduction(minn: nn)
for (i = 0; i < nodes[iyj].size(); i++) {
- if ((*cost)(nodes[iyj][i], node) < mc) {
- mc = (*cost)(nodes[iyj][i], node);
- nn = nodes[iyj][i];
+ if ((*cost)(nodes[iyj][i], node) < nn.mc) {
+ nn.mc = (*cost)(nodes[iyj][i], node);
+ nn.nn = nodes[iyj][i];
}
}
if (j > 0) {
iyj = (int) (iy - j);
if (iyj < 0)
iyj = 0;
- #pragma omp parallel for
+ #pragma omp parallel for reduction(minn: nn)
for (i = 0; i < nodes[iyj].size(); i++) {
- if ((*cost)(nodes[iyj][i], node) < mc) {
- mc = (*cost)(nodes[iyj][i], node);
- nn = nodes[iyj][i];
+ if ((*cost)(nodes[iyj][i], node) < nn.mc) {
+ nn.mc = (*cost)(nodes[iyj][i], node);
+ nn.nn = nodes[iyj][i];
}
}
}
j++;
}
- return nn;
+ return nn.nn;
}
#include "rrtbase.h"
#include "rrtnode.h"
+struct mcnn { // min-cost nearest neighbour
+ float mc;
+ RRTNode *nn;
+};
+#pragma omp declare reduction \
+ (minn: struct mcnn: omp_out = \
+ omp_in.mc < omp_out.mc ? omp_in : omp_out) \
+ initializer \
+ (omp_priv(omp_orig))
+
RRTNode *nn1(
std::vector<RRTNode *> &nodes,
RRTNode *node,