| 5 |
|
* General component matrix combiner, operating on a row at a time. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
#include <signal.h> |
| 9 |
|
#include <math.h> |
| 10 |
|
#include "platform.h" |
| 11 |
|
#include "rtprocess.h" |
| 57 |
|
SUBPROC *cproc = NULL; /* child process array */ |
| 58 |
|
int nchildren = 0; /* # of child processes */ |
| 59 |
|
int inchild = -1; /* our child ID (-1: parent) */ |
| 60 |
+ |
int gpid = -1; /* group process ID (parent) */ |
| 61 |
+ |
int nr_out = 0; /* # of rows output by kids */ |
| 62 |
|
|
| 63 |
|
static int checksymbolic(ROPMAT *rop); |
| 64 |
|
|
| 65 |
+ |
static void |
| 66 |
+ |
on_sigio(int dummy) |
| 67 |
+ |
{ |
| 68 |
+ |
nr_out++; /* happens when child outputs row */ |
| 69 |
+ |
signal(SIGIO, on_sigio); /* reset to maximize portability */ |
| 70 |
+ |
} |
| 71 |
+ |
|
| 72 |
|
static int |
| 73 |
|
split_input(ROPMAT *rop) |
| 74 |
|
{ |
| 596 |
|
#endif |
| 597 |
|
return(0); |
| 598 |
|
} |
| 599 |
+ |
gpid = setpgrp(); /* set group process ID */ |
| 600 |
+ |
signal(SIGIO, on_sigio); |
| 601 |
|
fflush(stdout); /* flush header & spawn children */ |
| 602 |
|
cproc = (SUBPROC *)malloc(sizeof(SUBPROC)*np); |
| 603 |
|
if (!cproc) |
| 668 |
|
break; |
| 669 |
|
for (i = 0; i < nmats; i++) |
| 670 |
|
if (!rmx_write_data(mop[i].imx.mtx, mop[i].imx.ncomp, |
| 671 |
< |
mop[i].imx.ncols, DTdouble, ofp)) |
| 671 |
> |
mop[i].imx.ncols, DTdouble, ofp)) |
| 672 |
|
return(0); |
| 673 |
|
if (fflush(ofp) == EOF) |
| 674 |
|
return(0); |
| 772 |
|
return(0); |
| 773 |
|
} |
| 774 |
|
rmx_free(mres); mres = NULL; |
| 775 |
< |
if (inchild >= 0) { |
| 776 |
< |
i = getc(stdin); /* child waits for turn to output */ |
| 777 |
< |
if (i != EOF) ungetc(i, stdin); |
| 766 |
< |
} |
| 775 |
> |
if (inchild >= 0) /* children share stdout */ |
| 776 |
> |
while (nr_out < cur_row) |
| 777 |
> |
pause(); /* wait for our turn */ |
| 778 |
|
if (!rmx_write_data(res->rmp->mtx, res->rmp->ncomp, |
| 779 |
|
res->rmp->ncols, res->rmp->dtype, stdout)) |
| 780 |
|
return(0); |
| 781 |
< |
if (inchild >= 0 && fflush(stdout) == EOF) |
| 782 |
< |
return(0); |
| 781 |
> |
if (inchild >= 0) { /* flush and notify group */ |
| 782 |
> |
if (fflush(stdout) == EOF) |
| 783 |
> |
return(0); |
| 784 |
> |
killpg(gpid, SIGIO); /* increments everyone's nr_out */ |
| 785 |
> |
} |
| 786 |
|
} |
| 787 |
|
return(inchild >= 0 || fflush(stdout) != EOF); |
| 788 |
|
memerror: |