ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/rt/RcontribSimulManager.cpp
(Generate patch)

Comparing ray/src/rt/RcontribSimulManager.cpp (file contents):
Revision 2.13 by greg, Thu Oct 16 23:14:31 2025 UTC vs.
Revision 2.14 by greg, Fri Oct 17 01:15:53 2025 UTC

# Line 52 | Line 52 | struct RowAssignment {
52          uint32                  ac;             // accumulation count
53   };
54  
55 + static const char       ROW_DONE[] = "ROW FINISHED\n";
56 +
57   // Get format identifier
58   const char *
59   formstr(int f)
# Line 625 | Line 627 | RcontribSimulManager::ComputeRecord(const FVECT orig_d
627                  return 0;
628          }
629          if (nkids > 0) {                        // in parent process?
630 <                int     k = GetChild();         // updates output rows
631 <                if (k < 0) return -1;           // can't really happen
630 >                int     k = GetChild(false);    // updates output rows
631 >                if (k < 0) return -1;           // someone died?
632                  RowAssignment   rass;
633                  rass.row = kidRow[k] = rInPos++;
634                  rass.ac = accum;
# Line 671 | Line 673 | RcontribSimulManager::GetChild(bool forceWait)
673                  return -1;
674                                                  // take inventory
675          int     pn, n = 0;
676 <        fd_set  writeset, errset;
677 <        FD_ZERO(&writeset); FD_ZERO(&errset);
676 >        fd_set  readset, errset;
677 >        FD_ZERO(&readset); FD_ZERO(&errset);
678          for (pn = nkids; pn--; ) {
679                  if (kidRow[pn] < 0) {           // child already ready?
680                          if (forceWait) continue;
681                          return pn;              // good enough
682                  }
683 <                FD_SET(kid[pn].w, &writeset);   // will check on this one
684 <                FD_SET(kid[pn].w, &errset);
685 <                if (kid[pn].w >= n)
686 <                        n = kid[pn].w + 1;
683 >                FD_SET(kid[pn].r, &readset);    // will check on this one
684 >                FD_SET(kid[pn].r, &errset);
685 >                if (kid[pn].r >= n)
686 >                        n = kid[pn].r + 1;
687          }
688          if (!n)                                 // every child is idle?
689                  return -1;
690                                                  // wait on "busy" child(ren)
691 <        while ((n = select(n, NULL, &writeset, &errset, NULL)) <= 0)
691 >        while ((n = select(n, &readset, NULL, &errset, NULL)) <= 0)
692                  if (errno != EINTR) {
693                          error(SYSTEM, "select call failed in GetChild()");
694                          return -1;
695                  }
696 +        char    buf[sizeof(ROW_DONE)] = "X";
697          pn = -1;                                // get flags set by select
698          for (n = nkids; n--; )
699                  if (kidRow[n] >= 0 &&
700 <                                FD_ISSET(kid[n].w, &writeset) |
701 <                                FD_ISSET(kid[n].w, &errset)) {
700 >                                FD_ISSET(kid[n].r, &readset) |
701 >                                FD_ISSET(kid[n].r, &errset)) {
702 >                                                // check for error
703 >                        if (FD_ISSET(kid[n].r, &errset) ||
704 >                                        read(kid[n].r, buf, sizeof(ROW_DONE)) <= 0 ||
705 >                                        memcmp(buf, ROW_DONE, sizeof(ROW_DONE)))
706 >                                return -1;
707                                                  // update output row counts
708 <                        if (!FD_ISSET(kid[n].w, &errset))
709 <                                UpdateRowsDone(kidRow[n]);
702 <                        kidRow[n] = -1;         // flag it available
708 >                        UpdateRowsDone(kidRow[n]);
709 >                        kidRow[n] = -1;         // flag child available
710                          pn = n;
711                  }
712          return pn;
# Line 750 | Line 757 | RcontribSimulManager::RunChild()
757  
758                  if (ComputeRecord(vecList) <= 0)
759                          exit(1);
760 +                                                // signal this row is done
761 +                if (write(1, ROW_DONE, sizeof(ROW_DONE)) != sizeof(ROW_DONE))
762 +                        exit(1);
763          }
764          if (nr) {
765                  error(SYSTEM, "read error in child process");
# Line 775 | Line 785 | RcontribSimulManager::StartKids(int n2go)
785          fflush(stdout);                         // shouldn't use, anyway
786          while (nkids < n2go) {
787                  kid[nkids] = sp_inactive;
778                kid[nkids].w = dup(1);
779                kid[nkids].flags |= PF_FILT_OUT;
788                  int     rv = open_process(&kid[nkids], NULL);
789                  if (!rv) {                      // in child process?
790 <                        while (nkids-- > 0)
790 >                        while (nkids-- > 0) {
791 >                                close(kid[nkids].r);
792                                  close(kid[nkids].w);
793 +                        }
794                          free(kid); free(kidRow);
795                          kid = NULL; kidRow = NULL;
796                          RunChild();             // should never return

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)