41 double zmin,
double zmax,
42 double *zminac,
double *zmaxac,
43 double *gmin,
double *gmax,
44 double *c1min,
double *c1max,
45 double *c2min,
double *c2max,
49 double dnorm,
int threads)
51 int some_thread_failed = 0;
58 double ***matrix =
NULL;
69 matrix = (
double ***)G_malloc(
sizeof(
double **) * threads);
70 indx = (
int **)G_malloc(
sizeof(
int *) * threads);
71 b = (
double **)G_malloc(
sizeof(
double *) * threads);
72 A = (
double **)G_malloc(
sizeof(
double *) * threads);
74 for (i_cnt = 0; i_cnt < threads; i_cnt++) {
82 for (i_cnt = 0; i_cnt < threads; i_cnt++) {
89 for (i_cnt = 0; i_cnt < threads; i_cnt++) {
96 for (i_cnt = 0; i_cnt < threads; i_cnt++) {
98 (params->
KMAX2 + 2) * (params->
KMAX2 + 2) + 1))) {
105 cut_tree(tree, all_leafs, &i);
108#pragma omp parallel firstprivate( \
109 tid, i, j, zmin, zmax, tree, totsegm, offset1, dnorm, smseg, ertot, \
110 params, info, all_leafs, bitmask, b, indx, matrix, data_local, A) \
111 shared(cursegm, threads, some_thread_failed, zminac, zmaxac, gmin, gmax, \
112 c1min, c1max, c2min, c2max) default(none)
114#pragma omp for schedule(dynamic)
115 for (i_cnt = 0; i_cnt < totsegm; i_cnt++) {
118 tid = omp_get_thread_num();
121 double xmn, xmx, ymn, ymx, distx, disty, distxp, distyp, temp1,
124 double ew_res, ns_res;
128 struct triple target_point;
129 int npoints, point_index, k;
131 double xmm, ymm,
err, pointz;
142 if (all_leafs[i_cnt] ==
NULL) {
143 some_thread_failed = -1;
146 if (all_leafs[i_cnt]->data ==
NULL) {
147 some_thread_failed = -1;
154 distx = (((
struct quaddata *)(all_leafs[i_cnt]->
data))->n_cols *
157 disty = (((
struct quaddata *)(all_leafs[i_cnt]->
data))->n_rows *
175 pr = pow(2., (xmx - xmn) / smseg - 1.);
176 MINPTS = params->
kmin *
177 (pr / (1 + params->
kmin * pr / params->
KMAX2));
183 xmn - distx, ymn - disty, xmx + distx, ymx + disty, 0, 0, 0,
188 while ((npt < MINPTS) || (npt > params->
KMAX2)) {
190 G_warning(_(
"Taking too long to find points for "
192 "please change the region to area where "
194 "Continuing calculations..."));
198 if (npt > params->
KMAX2)
204 distx = distxp - fabs(distx - temp1) * 0.5;
207 disty = distyp - fabs(disty - temp2) * 0.5;
216 disty = fabs(disty - temp1) * 0.5 + distyp;
217 distx = fabs(distx - temp2) * 0.5 + distxp;
225 data_local[tid]->
x_orig = xmn - distx;
226 data_local[tid]->
y_orig = ymn - disty;
227 data_local[tid]->
xmax = xmx + distx;
228 data_local[tid]->
ymax = ymx + disty;
234 if (totsegm != 0 && tid == 0) {
252 data_local[tid]->
x_orig = xmn;
253 data_local[tid]->
y_orig = ymn;
254 data_local[tid]->
xmax = xmx;
255 data_local[tid]->
ymax = ymx;
259 if (!(point = (
struct triple *)G_malloc(
263 some_thread_failed = -1;
272 for (i = 0; i < data_local[tid]->
n_points; i++) {
274 (data_local[tid]->
points[i].
x -
275 data_local[tid]->
x_orig) /
278 (data_local[tid]->
points[i].
y -
279 data_local[tid]->
y_orig) /
282 point[i].x = data_local[tid]->
points[i].
x;
283 point[i].y = data_local[tid]->
points[i].
y;
284 point[i].z = data_local[tid]->
points[i].
z;
305 matrix[tid], indx[tid],
307 some_thread_failed = -1;
311 for (i = 0; i < data_local[tid]->
n_points; i++) {
312 b[tid][i + 1] = data_local[tid]->
points[i].
z;
322 ertot, zmin, dnorm, &target_point);
329 for (point_index = 0; point_index < npoints;
333 target_point.
x = point[point_index].x;
334 target_point.
y = point[point_index].y;
335 target_point.
z = point[point_index].z;
337 xx = target_point.
x * dnorm + data_local[tid]->
x_orig +
339 yy = target_point.
y * dnorm + data_local[tid]->
y_orig +
344 xx <= data_local[tid]->
xmax + params->
x_orig &&
346 yy <= data_local[tid]->
ymax + params->
y_orig) {
349 for (k = 0; k < npoints; k++) {
350 if (k != point_index) {
351 data_local[tid]->
points[j].
x = point[k].x;
352 data_local[tid]->
points[j].
y = point[k].y;
353 data_local[tid]->
points[j].
z = point[k].z;
361 params, data_local[tid]->
points,
362 data_local[tid]->
n_points - 1, matrix[tid],
363 indx[tid], A[tid]) < 0) {
364 some_thread_failed = -1;
368 for (i = 0; i < data_local[tid]->
n_points - 1;
370 b[tid][i + 1] = data_local[tid]->
points[i].
z;
382 target_point.
x = data_local[tid]->
points[point_index].
x;
383 target_point.
y = data_local[tid]->
points[point_index].
y;
384 target_point.
z = data_local[tid]->
points[point_index].
z;
388 pointz = target_point.
z;
390 zmin, dnorm, &target_point);
392 err = target_point.
z;
393 target_point.
z = pointz + zmin;
394 xmm = target_point.
x;
395 ymm = target_point.
y;
400 xmm <= data_local[tid]->
xmax + params->
x_orig &&
402 ymm <= data_local[tid]->
ymax + params->
y_orig) {
423 if (params->
grid_calc(params, data_local[tid],
424 bitmask, zmin, zmax, zminac,
425 zmaxac, gmin, gmax, c1min,
426 c1max, c2min, c2max, ertot,
427 b[tid], offset1, dnorm) < 0) {
428 some_thread_failed = -1;
437 if (totsegm < cursegm) {
438 G_debug(1,
"%d %d", totsegm, cursegm);
441 if (totsegm != 0 && tid == 0) {
455 for (i_cnt = 0; i_cnt < threads; i_cnt++) {
468 if (some_thread_failed != 0) {
int IL_interp_segments_2d_parallel(struct interp_params *params, struct tree_info *info, struct multtree *tree, struct BM *bitmask, double zmin, double zmax, double *zminac, double *zmaxac, double *gmin, double *gmax, double *c1min, double *c1max, double *c2min, double *c2max, double *ertot, int totsegm, off_t offset1, double dnorm, int threads)