ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rcomb.c
(Generate patch)

Comparing ray/src/util/rcomb.c (file contents):
Revision 2.17 by greg, Thu May 23 17:13:52 2024 UTC vs.
Revision 2.18 by greg, Thu May 23 19:29:41 2024 UTC

# Line 3 | Line 3 | static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   * General component matrix combiner, operating on a row at a time.
6 + *
7 + * Multi-processing mode under Unix creates children that each work
8 + * on one input row at a time, fed by the single parent.  Output to
9 + * a shared stdout is assured because each child waits for parent
10 + * to be ready with next input row before it outputs the previous result.
11 + * The assumption (checked in spawn_children()) is that the parent
12 + * will remain blocked until the child it is feeding has finished
13 + * flushing the previous row to stdout.  The final output row is
14 + * less guaranteed to be in order, so the parent sleeps for a few seconds
15 + * between each child pipe closure, in hopes that this allows enough
16 + * time for row output to finish in each process.
17   */
18  
19   #include <math.h>
# Line 552 | Line 563 | spawned_children(int np)
563                  np = 1;
564          } else
565   #endif
566 <        if ((in_nrows > 0) & (np > in_nrows))
567 <                np = in_nrows;
566 >        if ((in_nrows > 0) & (np*4 > in_nrows))
567 >                np = in_nrows/4;
568                                  /* we'll be doing a row at a time */
569          for (i = 0; i < nmats; i++) {
570                  mop[i].imx.nrows = 1;
# Line 580 | Line 591 | spawned_children(int np)
591          mop[nmats].imx.nrows = 1;
592          if (!rmx_prepare(&mop[nmats].imx))
593                  goto memerror;
594 <        if (np <= 1) {          /* single process return point */
594 >        if (np <= 1) {          /* single process return */
595   #ifdef getc_unlocked
596                  for (i = 0; i < nmats; i++)
597                          flockfile(mop[i].infp);
# Line 626 | Line 637 | spawned_children(int np)
637                          fclose(mop[i].infp);    /* ! pclose() */
638                  mop[i].infp = stdin;
639                  mop[i].imx.dtype = DTdouble;
640 +                mop[i].imx.pflags &= ~RMF_SWAPIN;
641          }
642          return(0);              /* child return */
643   memerror:
# Line 670 | Line 682 | parent_loop()
682              if (fflush(ofp) == EOF)
683                  return(0);
684          }
685 <        for (i = 0; i < nchildren; i++) {
686 <                sleep(2);                       /* try to maintain order */
685 >        for (i = 0; i < nchildren; i++) {       /* maintain output order */
686 >                sleep(1+(mop[nmats].rmp->ncols*mop[nmats].rmp->ncomp >> 15));
687                  fclose(outfp[i]);
688          }
689          free(outfp);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines