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.11 by greg, Thu Jan 2 16:16:49 2025 UTC vs.
Revision 2.18 by greg, Fri Oct 24 18:37:05 2025 UTC

# Line 52 | Line 52 | struct RowAssignment {
52          uint32                  ac;             // accumulation count
53   };
54  
55 < // Get format identifier
56 < const char *
57 < formstr(int f)
58 < {
59 <        switch (f) {
60 <        case 'a': return("ascii");
61 <        case 'f': return("float");
62 <        case 'd': return("double");
63 <        case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT);
64 <        }
65 <        return("unknown");
66 < }
55 > static const char       ROW_DONE[] = "ROW FINISHED\n";
56  
57 < // Our default data share function
58 < RdataShare *
70 < defDataShare(const char *name, RCOutputOp op, size_t siz)
71 < {
72 <        return new RdataShareMap(name, RSDOflags[op], siz);
73 < }
74 <
75 < // Allocate rcontrib accumulator
76 < RcontribMod *
57 > // allocate rcontrib accumulator
58 > static RcontribMod *
59   NewRcMod(const char *prms, const char *binexpr, int ncbins)
60   {
61 +        if (binexpr && !*binexpr) binexpr = NULL;
62          if (!prms) prms = "";
63          if ((ncbins > 1) & !binexpr) {
64                  error(USER, "missing bin expression");
# Line 110 | Line 93 | NewRcMod(const char *prms, const char *binexpr, int nc
93          return mp;
94   }
95  
96 < // Free an RcontribMod
96 > // Free an RcontribMod (public for RcontribSimulManager constructor)
97   void
98   FreeRcMod(void *p)
99   {
# Line 120 | Line 103 | FreeRcMod(void *p)
103          efree(p);
104   }
105  
106 + // Get format identifier
107 + const char *
108 + formstr(int f)
109 + {
110 +        switch (f) {
111 +        case 'a': return("ascii");
112 +        case 'f': return("float");
113 +        case 'd': return("double");
114 +        case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT);
115 +        }
116 +        return("unknown");
117 + }
118 +
119 + // Standard file data share function
120 + RdataShare *
121 + fileDataShare(const char *name, RCOutputOp op, size_t siz)
122 + {
123 +        if (op == RCOrecover && access(name, R_OK|W_OK) < 0) {
124 +                sprintf(errmsg, "cannot recover from '%s'", name);
125 +                error(SYSTEM, errmsg);
126 +                return NULL;
127 +        }
128 +        return new RdataShareFile(name, RSDOflags[op], siz);
129 + }
130 +
131 + // Memory-mapped data share function
132 + RdataShare *
133 + mapDataShare(const char *name, RCOutputOp op, size_t siz)
134 + {
135 +        if (op == RCOrecover && access(name, R_OK|W_OK) < 0) {
136 +                sprintf(errmsg, "cannot recover from '%s'", name);
137 +                error(SYSTEM, errmsg);
138 +                return NULL;
139 +        }
140 +        return new RdataShareMap(name, RSDOflags[op], siz);
141 + }
142 +
143   // Set output format ('f', 'd', or 'c')
144   bool
145   RcontribSimulManager::SetDataFormat(int ty)
# Line 215 | Line 235 | RcontribSimulManager::AddModifier(const char *modn, co
235                  error(WARNING, "ignoring bad call to AddModifier()");
236                  return false;
237          }
238 +        if (*outspec == '!') {
239 +                error(USER, "command output not supported by RcontribSimulManager");
240 +                return false;
241 +        }
242          if (!nChan) {                           // initial call?
243                  if ((xres < 0) | (yres <= 0)) {
244                          error(USER, "xres, yres must be set before first modifier");
# Line 373 | Line 397 | RcontribSimulManager::PrepOutput()
397                          if (rd < 0)
398                                  return -1;
399                          if (rd >= op->nRows) {
400 <                                if (remWarnings >= 0) {
400 >                                if (remWarnings > 0) {
401                                          sprintf(errmsg, "recovered output '%s' is complete",
402                                                          op->GetName());
403                                          error(WARNING, --remWarnings ? errmsg : "etc...");
# Line 602 | Line 626 | putModContrib(const LUENT *lp, void *p)
626                  }
627                  } break;
628          default:
629 <                error(CONSISTENCY, "unsupported output type in sendModContrib()");
629 >                error(CONSISTENCY, "unsupported output type in putModContrib()");
630                  return -1;
631          }
632                                                  // clear for next tally
# Line 621 | Line 645 | RcontribSimulManager::ComputeRecord(const FVECT orig_d
645                  return 0;
646          }
647          if (nkids > 0) {                        // in parent process?
648 <                int     k = GetChild();         // updates output rows
649 <                if (k < 0) return -1;           // can't really happen
648 >                int     k = GetChild(false);    // updates output rows
649 >                if (k < 0) return -1;           // someone died?
650                  RowAssignment   rass;
651                  rass.row = kidRow[k] = rInPos++;
652                  rass.ac = accum;
# Line 667 | Line 691 | RcontribSimulManager::GetChild(bool forceWait)
691                  return -1;
692                                                  // take inventory
693          int     pn, n = 0;
694 <        fd_set  writeset, errset;
695 <        FD_ZERO(&writeset); FD_ZERO(&errset);
694 >        fd_set  readset, errset;
695 >        FD_ZERO(&readset); FD_ZERO(&errset);
696          for (pn = nkids; pn--; ) {
697                  if (kidRow[pn] < 0) {           // child already ready?
698                          if (forceWait) continue;
699                          return pn;              // good enough
700                  }
701 <                FD_SET(kid[pn].w, &writeset);   // will check on this one
702 <                FD_SET(kid[pn].w, &errset);
703 <                if (kid[pn].w >= n)
704 <                        n = kid[pn].w + 1;
701 >                FD_SET(kid[pn].r, &readset);    // will check on this one
702 >                FD_SET(kid[pn].r, &errset);
703 >                if (kid[pn].r >= n)
704 >                        n = kid[pn].r + 1;
705          }
706          if (!n)                                 // every child is idle?
707                  return -1;
708                                                  // wait on "busy" child(ren)
709 <        while ((n = select(n, NULL, &writeset, &errset, NULL)) <= 0)
709 >        while ((n = select(n, &readset, NULL, &errset, NULL)) <= 0)
710                  if (errno != EINTR) {
711                          error(SYSTEM, "select call failed in GetChild()");
712                          return -1;
713                  }
714 +        char    buf[sizeof(ROW_DONE)] = "X";
715          pn = -1;                                // get flags set by select
716          for (n = nkids; n--; )
717                  if (kidRow[n] >= 0 &&
718 <                                FD_ISSET(kid[n].w, &writeset) |
719 <                                FD_ISSET(kid[n].w, &errset)) {
718 >                                FD_ISSET(kid[n].r, &readset) |
719 >                                FD_ISSET(kid[n].r, &errset)) {
720 >                                                // check for error
721 >                        if (FD_ISSET(kid[n].r, &errset) ||
722 >                                        read(kid[n].r, buf, sizeof(ROW_DONE)) <= 0 ||
723 >                                        memcmp(buf, ROW_DONE, sizeof(ROW_DONE)))
724 >                                return -1;
725                                                  // update output row counts
726 <                        if (!FD_ISSET(kid[n].w, &errset))
727 <                                UpdateRowsDone(kidRow[n]);
698 <                        kidRow[n] = -1;         // flag it available
726 >                        UpdateRowsDone(kidRow[n]);
727 >                        kidRow[n] = -1;         // flag child available
728                          pn = n;
729                  }
730          return pn;
# Line 733 | Line 762 | RcontribSimulManager::RunChild()
762                          error(CONSISTENCY, "bad accumulator count in child");
763                          exit(1);
764                  }
765 <                if (rass.ac > accum)
766 <                        vecList = (FVECT *)erealloc(vecList,
767 <                                                sizeof(FVECT)*2*rass.ac);
765 >                if (rass.ac > accum) {
766 >                        efree(vecList);
767 >                        vecList = (FVECT *)emalloc(sizeof(FVECT)*2*rass.ac);
768 >                }
769                  accum = rass.ac;
770                  rInPos = rass.row;
771  
# Line 745 | Line 775 | RcontribSimulManager::RunChild()
775  
776                  if (ComputeRecord(vecList) <= 0)
777                          exit(1);
778 +                                                // signal this row is done
779 +                if (write(1, ROW_DONE, sizeof(ROW_DONE)) != sizeof(ROW_DONE))
780 +                        exit(1);
781          }
782          if (nr) {
783                  error(SYSTEM, "read error in child process");
# Line 770 | Line 803 | RcontribSimulManager::StartKids(int n2go)
803          fflush(stdout);                         // shouldn't use, anyway
804          while (nkids < n2go) {
805                  kid[nkids] = sp_inactive;
773                kid[nkids].w = dup(1);
774                kid[nkids].flags |= PF_FILT_OUT;
806                  int     rv = open_process(&kid[nkids], NULL);
807                  if (!rv) {                      // in child process?
808 <                        while (nkids-- > 0)
808 >                        while (nkids-- > 0) {
809 >                                close(kid[nkids].r);
810                                  close(kid[nkids].w);
811 +                        }
812                          free(kid); free(kidRow);
813                          kid = NULL; kidRow = NULL;
814                          RunChild();             // should never return

Diff Legend

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