Skip to content

Commit 4007b94

Browse files
Wire in new classes into workflow; add tests
1 parent 4401ca7 commit 4007b94

File tree

10 files changed

+367
-957
lines changed

10 files changed

+367
-957
lines changed

IDAWin/SundialsSolverInterface.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,45 @@
1010
#include <iomanip>
1111
#include <sstream>
1212
#include <VCELL/GitDescribe.h>
13+
#include <VCELL/SimulationMessaging.h>
14+
#include "StoppedByUserException.h"
1315

1416
#define CVODE_SOLVER "CVODE"
1517
#define IDA_SOLVER "IDA"
1618

19+
void errExit(int returnCode, const std::string &errorMsg);
20+
1721
void activateSolver(std::ifstream& inputFileStream, FILE* outputFile, int taskID) {
18-
VCellSolver* targetSolver = VCellSolverFactory::produceVCellSolver(inputFileStream, taskID);
19-
targetSolver->solve(nullptr, true, outputFile, VCellSundialsSolver::checkStopRequested);
22+
try {
23+
VCellSolver* targetSolver = VCellSolverFactory::produceVCellSolver(inputFileStream, taskID);
24+
targetSolver->solve(nullptr, true, outputFile, VCellSundialsSolver::checkStopRequested);
25+
} catch (const char *ex) {
26+
errExit(-1, ex);
27+
} catch (std::string &ex) {
28+
errExit(-2, ex);
29+
} catch (StoppedByUserException&) {
30+
errExit(0, "Execution Stopped By User");
31+
} catch (VCell::Exception &ex) {
32+
errExit(-3, ex.getMessage());
33+
} catch (const std::exception& err) {
34+
errExit(-4, err.what());
35+
} catch (...) {
36+
errExit(-5, "unknown error");
37+
}
38+
39+
// cleanup
40+
if (SimulationMessaging::getInstVar() != nullptr) {
41+
SimulationMessaging::getInstVar()->waitUntilFinished();
42+
delete SimulationMessaging::getInstVar();
43+
}
44+
}
45+
46+
void errExit(int returnCode, const std::string &errorMsg) {
47+
#ifdef USE_MESSAGING
48+
if (returnCode && SimulationMessaging::getInstVar() && !SimulationMessaging::getInstVar()->isStopRequested()) {
49+
SimulationMessaging::getInstVar()->setWorkerEvent(JobEvent::JOB_FAILURE, errorMsg.c_str());
50+
}
51+
#endif
52+
std::cerr << errorMsg << std::endl;
2053
}
2154

IDAWin/SundialsSolverStandalone.cpp

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Messaging
2-
#ifdef USE_MESSAGING
2+
33
#include <VCELL/SimulationMessaging.h>
44
#include <memory.h>
5-
#endif
65
// Standard Includes
76
#include <iomanip>
87
#include <fstream>
@@ -18,7 +17,6 @@
1817
#define IDA_SOLVER "IDA"
1918

2019
int parseAndRunWithArgParse(int argc, char *argv[]);
21-
void errExit(int returnCode, std::string &errorMsg);
2220

2321
int main(int argc, char *argv[]) {
2422
std::cout << std::setprecision(20);
@@ -58,46 +56,15 @@ int parseAndRunWithArgParse(int argc, char *argv[]) {
5856
throw std::runtime_error("Could not open output file[" + outputFilePath + "] for writing.");
5957
}
6058
activateSolver(inputFileStream, outputFile, taskID);
61-
62-
} catch (const char *ex) {
63-
errMsg += ex;
64-
returnCode = -1;
65-
} catch (std::string &ex) {
66-
errMsg += ex;
67-
returnCode = -1;
68-
} catch (StoppedByUserException&) {
69-
returnCode = 0; // stopped by user;
70-
} catch (VCell::Exception &ex) {
71-
errMsg += ex.getMessage();
72-
returnCode = -1;
73-
} catch (const std::exception& err) {
74-
errMsg += err.what();
75-
returnCode = -1;
59+
} catch (const std::runtime_error& err) {
60+
std::cerr << err.what() << std::endl;
61+
returnCode = 5;
7662
} catch (...) {
77-
errMsg += "unknown error";
78-
returnCode = -1;
63+
std::cerr << "Unknown exception thrown." << std::endl;
64+
returnCode = 255;
7965
}
8066

8167
if (outputFile != NULL) { fclose(outputFile); }
8268
if (inputFileStream.is_open()) { inputFileStream.close(); }
83-
errExit(returnCode, errMsg);
8469
return returnCode;
8570
}
86-
87-
void errExit(int returnCode, std::string &errorMsg) {
88-
#ifdef USE_MESSAGING
89-
if (returnCode != 0) {
90-
if (SimulationMessaging::getInstVar() != nullptr && !SimulationMessaging::getInstVar()->isStopRequested()) {
91-
SimulationMessaging::getInstVar()->setWorkerEvent(new WorkerEvent(JOB_FAILURE, errorMsg.c_str()));
92-
}
93-
}
94-
#endif
95-
96-
if (returnCode != 0) std::cerr << errorMsg << std::endl;
97-
#ifdef USE_MESSAGING
98-
else if (SimulationMessaging::getInstVar() != nullptr) {
99-
SimulationMessaging::getInstVar()->waitUntilFinished();
100-
delete SimulationMessaging::getInstVar();
101-
}
102-
#endif
103-
}

IDAWin/VCellCVodeSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ void VCellCVodeSolver::cvodeSolve(bool bPrintProgress, FILE* outputFile, void (*
501501
}
502502
}
503503
#ifdef USE_MESSAGING
504-
SimulationMessaging::getInstVar()->setWorkerEvent(new WorkerEvent(JOB_COMPLETED, 1, Time));
504+
SimulationMessaging::getInstVar()->setWorkerEvent(JobEvent::JOB_COMPLETED, 1, Time);
505505
#endif
506506
}
507507

IDAWin/VCellIDASolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ void VCellIDASolver::idaSolve(bool bPrintProgress, FILE* outputFile, void (*chec
719719
}
720720
}
721721
#ifdef USE_MESSAGING
722-
SimulationMessaging::getInstVar()->setWorkerEvent(new WorkerEvent(JOB_COMPLETED, 1, Time));
722+
SimulationMessaging::getInstVar()->setWorkerEvent(JobEvent::JOB_COMPLETED, 1, Time);
723723
#endif
724724
}
725725

IDAWin/VCellSolverFactory.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ VCellSolverInputBreakdown VCellSolverFactory::parseInputFile(std::ifstream& inpu
6060
inputBreakdown.solverType = determineSolverType(solverName);
6161
} else if (nextToken == "JMS_PARAM_BEGIN") {
6262
loadJMSInfo(inputFileStream, taskID);
63-
#ifdef USE_MESSAGING
64-
SimulationMessaging::getInstVar()->start(); // start the thread
65-
#endif
63+
// #ifdef USE_MESSAGING
64+
// SimulationMessaging::getInstVar()->start(); // start the thread
65+
// #endif
6666
}
6767
else if (nextToken == "STARTING_TIME") { inputFileStream >> inputBreakdown.timeCourseSettings.STARTING_TIME; }
6868
else if (nextToken == "ENDING_TIME") { inputFileStream >> inputBreakdown.timeCourseSettings.ENDING_TIME; }
@@ -430,7 +430,7 @@ static void loadJMSInfo(std::istream &ifsInput, int taskID) {
430430
// We'll still parse the section, as we can still execute the simulation; we'll just toss the values!
431431
std::cerr << "WARNING: Input file expects messaging capabilities; this build does not support JMS messaging!" << std::endl;
432432
#endif
433-
433+
434434
std::string broker;
435435
std::string smqUserName;
436436
std::string password;

IDAWin/VCellSundialsSolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void VCellSundialsSolver::printProgress(double currTime, double &lastPercentile,
124124

125125
if (currTime == STARTING_TIME) { // print 0%
126126
#ifdef USE_MESSAGING
127-
SimulationMessaging::getInstVar()->setWorkerEvent(new WorkerEvent(JOB_PROGRESS, lastPercentile, currTime));
127+
SimulationMessaging::getInstVar()->setWorkerEvent(JobEvent::JOB_PROGRESS, lastPercentile, currTime);
128128
#else
129129
printf("[[[progress:%lg%%]]]", lastPercentile*100.0);
130130
fflush(stdout);
@@ -146,8 +146,8 @@ void VCellSundialsSolver::printProgress(double currTime, double &lastPercentile,
146146
if (lastPercentile != newPercentile) {
147147
#ifdef USE_MESSAGING
148148
SimulationMessaging::getInstVar()->
149-
setWorkerEvent(new WorkerEvent(JOB_PROGRESS, newPercentile, currTime));
150-
SimulationMessaging::getInstVar()->setWorkerEvent(new WorkerEvent(JOB_DATA, newPercentile, currTime));
149+
setWorkerEvent(JobEvent::JOB_PROGRESS, newPercentile, currTime);
150+
SimulationMessaging::getInstVar()->setWorkerEvent(JobEvent::JOB_DATA, newPercentile, currTime);
151151
#else
152152
printf("[[[progress:%lg%%]]]", newPercentile*100.0);
153153
printf("[[[data:%lg]]]", currTime);

0 commit comments

Comments
 (0)