577 |
|
migration_step(MIGRATION *mig, double *src_rem, double *dst_rem, const float *pmtx) |
578 |
|
{ |
579 |
|
static double *src_cost = NULL; |
580 |
< |
int n_alloc = 0; |
580 |
> |
static int n_alloc = 0; |
581 |
|
const double maxamt = .1; /* 2./(mtx_nrows(mig)*mtx_ncols(mig)); */ |
582 |
|
double amt = 0; |
583 |
|
struct { |
699 |
|
static void |
700 |
|
await_children(int n) |
701 |
|
{ |
702 |
+ |
int exit_status = 0; |
703 |
+ |
|
704 |
|
if (n > nchild) |
705 |
|
n = nchild; |
706 |
|
while (n-- > 0) { |
711 |
|
break; |
712 |
|
} |
713 |
|
--nchild; |
714 |
< |
if (status) { |
714 |
> |
if (status) { /* something wrong */ |
715 |
|
if ((status = WEXITSTATUS(status))) |
716 |
< |
exit(status); |
716 |
> |
exit_status = status; |
717 |
> |
else |
718 |
> |
exit_status += !exit_status; |
719 |
|
fprintf(stderr, "%s: subprocess died\n", progname); |
720 |
< |
exit(1); |
720 |
> |
n = nchild; /* wait for the rest */ |
721 |
|
} |
722 |
|
} |
723 |
+ |
if (exit_status) |
724 |
+ |
exit(exit_status); |
725 |
|
} |
726 |
|
|
727 |
|
/* Start child process if multiprocessing selected */ |
756 |
|
static MIGRATION * |
757 |
|
create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) |
758 |
|
{ |
759 |
< |
const double end_thresh = 0.02/(from_rbf->nrbf*to_rbf->nrbf); |
759 |
> |
const double end_thresh = 0.1/(from_rbf->nrbf*to_rbf->nrbf); |
760 |
> |
const double rel_thresh = 0.0001; |
761 |
|
float *pmtx; |
762 |
|
MIGRATION *newmig; |
763 |
|
double *src_rem, *dst_rem; |
764 |
< |
double total_rem = 1.; |
764 |
> |
double total_rem = 1., move_amt; |
765 |
|
int i; |
766 |
|
/* check if exists already */ |
767 |
|
for (newmig = from_rbf->ejl; newmig != NULL; |
791 |
|
src_rem[i] = rbf_volume(&from_rbf->rbfa[i]) / from_rbf->vtotal; |
792 |
|
for (i = to_rbf->nrbf; i--; ) |
793 |
|
dst_rem[i] = rbf_volume(&to_rbf->rbfa[i]) / to_rbf->vtotal; |
794 |
< |
/* move a bit at a time */ |
795 |
< |
while (total_rem > end_thresh) { |
796 |
< |
total_rem -= migration_step(newmig, src_rem, dst_rem, pmtx); |
794 |
> |
do { /* move a bit at a time */ |
795 |
> |
move_amt = migration_step(newmig, src_rem, dst_rem, pmtx); |
796 |
> |
total_rem -= move_amt; |
797 |
|
#ifdef DEBUG |
798 |
|
if (!nchild) |
799 |
|
/* fputc('.', stderr); */ |
800 |
|
fprintf(stderr, "%.9f remaining...\r", total_rem); |
801 |
|
#endif |
802 |
< |
} |
802 |
> |
} while ((total_rem > end_thresh) & (move_amt > rel_thresh*total_rem)); |
803 |
|
#ifdef DEBUG |
804 |
< |
if (!nchild) fputs("done.\n", stderr); |
804 |
> |
if (!nchild) fputs("\ndone.\n", stderr); |
805 |
|
#endif |
806 |
|
|
807 |
|
free(pmtx); /* free working arrays */ |