Skip to content

Commit

Permalink
feat: Improved error-handling in base simulation manager classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Nov 13, 2024
1 parent 8fca372 commit a40a218
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
40 changes: 10 additions & 30 deletions src/rt/RtraceSimulManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: RtraceSimulManager.cpp,v 2.21 2024/11/09 00:10:49 greg Exp $";
static const char RCSid[] = "$Id: RtraceSimulManager.cpp,v 2.22 2024/11/13 02:43:51 greg Exp $";
#endif
/*
* RtraceSimulManager.cpp
Expand Down Expand Up @@ -196,33 +196,18 @@ RadSimulManager::SetThreadCount(int nt)
return NThreads();
}

// Assign ray to subthread (fails if NThreads()<2)
bool
RadSimulManager::SplitRay(RAY *r)
{
if (!ray_pnprocs || ThreadsAvailable() < 1)
return false;

return (ray_psend(r) > 0);
}

// Process a ray (in subthread), optional result
bool
int
RadSimulManager::ProcessRay(RAY *r)
{
if (!Ready()) return false;

if (!ray_pnprocs) { // single-threaded mode?
samplendx++;
rayvalue(r);
return true;
return 1;
}
int rv = ray_pqueue(r);
if (rv < 0) {
error(WARNING, "ray tracing process(es) died");
return false;
}
return (rv > 0);
return ray_pqueue(r);
}

// Wait for next result (or fail)
Expand All @@ -249,15 +234,6 @@ RadSimulManager::Cleanup(bool everything)
return 0;
}

// How many threads are currently unoccupied?
int
RadSimulManager::ThreadsAvailable() const
{
if (!ray_pnprocs) return 1;

return ray_pnidle;
}

// Global pointer to simulation manager for trace call-back (only one)
static const RtraceSimulManager * ourRTsimMan = NULL;

Expand Down Expand Up @@ -405,8 +381,12 @@ RtraceSimulManager::EnqueueBundle(const FVECT orig_direc[], int n, RNUMBER rID0)
if (ray_fifo_in(&res) < 0)
return -1;
sendRes = false;
} else
sendRes &= ProcessRay(&res);
} else {
int rv = ProcessRay(&res);
if (rv < 0)
return -1;
sendRes &= (rv > 0);
}
} else if (ThreadsAvailable() < NThreads() &&
FlushQueue() < 0)
return -1;
Expand Down
17 changes: 10 additions & 7 deletions src/rt/RtraceSimulManager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* RCSid $Id: RtraceSimulManager.h,v 2.16 2024/10/23 23:40:41 greg Exp $ */
/* RCSid $Id: RtraceSimulManager.h,v 2.17 2024/11/13 02:43:51 greg Exp $ */
/*
* RtraceSimulManager.h
*
Expand Down Expand Up @@ -27,8 +27,9 @@ class RadSimulManager {
char * header; // header (less intro and format)
int hlen; // header string length
protected:
// Assign ray to subthread (fails if NThreads()<2)
bool SplitRay(RAY *r);
bool SplitRay(RAY *r) {
return (ray_pnprocs && ray_psend(r) > 0);
}
public:
RadSimulManager(const char *octn = NULL) {
header = NULL; hlen = 0;
Expand Down Expand Up @@ -65,13 +66,15 @@ class RadSimulManager {
return ray_pnprocs + !ray_pnprocs;
}
/// How many threads are currently unoccupied?
int ThreadsAvailable() const;
int ThreadsAvailable() const {
return ray_pnprocs ? ray_pnidle : 1;
}
/// Are we ready?
bool Ready() const {
return (octname && nobjects > 0);
}
/// Process a ray (in subthread), optional result
bool ProcessRay(RAY *r);
int ProcessRay(RAY *r);
/// Wait for next result (or fail)
bool WaitResult(RAY *r);
/// Close octree, free data, return status
Expand Down Expand Up @@ -120,13 +123,13 @@ class RtraceSimulManager : public RadSimulManager {
int EnqueueBundle(const FVECT orig_direc[], int n,
RNUMBER rID0 = 0);
/// Enqueue a single ray w/ optional ray ID
bool EnqueueRay(const FVECT org, const FVECT dir,
int EnqueueRay(const FVECT org, const FVECT dir,
RNUMBER rID = 0) {
if (dir == org+1)
return(EnqueueBundle((const FVECT *)org, 1, rID) > 0);
FVECT orgdir[2];
VCOPY(orgdir[0], org); VCOPY(orgdir[1], dir);
return(EnqueueBundle(orgdir, 1, rID) > 0);
return EnqueueBundle(orgdir, 1, rID);
}
/// Set/change cooked ray callback
void SetCookedCall(RayReportCall *cb, void *cd = NULL) {
Expand Down

0 comments on commit a40a218

Please # to comment.