Skip to content

Commit 11e0ece

Browse files
Made messaging vs non-messaging more flexible
1 parent 2aea19f commit 11e0ece

File tree

5 files changed

+24
-71
lines changed

5 files changed

+24
-71
lines changed

IDAWin/SundialsSolverInterface.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,6 @@
1515
#define IDA_SOLVER "IDA"
1616

1717
void activateSolver(std::ifstream& inputFileStream, FILE* outputFile, int taskID) {
18-
// std::string solver;
19-
//
20-
// while (!inputFileStream.eof()) { // Note break statement if "SOLVER" encountered
21-
// std::string nextToken;
22-
// inputFileStream >> nextToken;
23-
// if (nextToken.empty()) continue;
24-
// if (nextToken[0] == '#') getline(inputFileStream, nextToken);
25-
// else if (nextToken == "JMS_PARAM_BEGIN") {
26-
// loadJMSInfo(inputFileStream, taskID);
27-
// #ifdef USE_MESSAGING
28-
// SimulationMessaging::getInstVar()->start(); // start the thread
29-
// #endif
30-
// } else if (nextToken == "SOLVER") {
31-
// inputFileStream >> solver;
32-
// break;
33-
// }
34-
// }
35-
// #ifdef USE_MESSAGING
36-
// // should only happen during testing for solver compiled with messaging but run locally.
37-
// if (SimulationMessaging::getInstVar() == nullptr) { SimulationMessaging::create(); }
38-
// #endif
39-
//
40-
// if (solver.empty()) { throw "Solver not defined "; }
41-
// VCellSundialsSolver *vss = nullptr;
42-
//
43-
// if (solver == IDA_SOLVER) {
44-
// vss = new VCellIDASolver();
45-
// } else if (solver == CVODE_SOLVER) {
46-
// vss = new VCellCVodeSolver();
47-
// } else {
48-
// std::stringstream ss;
49-
// ss << "Solver " << solver << " not defined!";
50-
// throw ss.str();
51-
// }
52-
//
53-
// vss->solve(nullptr, true, outputFile, VCellSundialsSolver::checkStopRequested);
54-
// delete vss;
55-
56-
// Check if we have messaging and a taskID of -1; if so; fail now.
57-
58-
#ifdef USE_MESSAGING
59-
if (taskID < 0) {
60-
throw std::runtime_error("task id of value: " + std::to_string(taskID) + " not acceptable when this library is built with messaging");
61-
}
62-
#endif
63-
6418
VCellSolver* targetSolver = VCellSolverFactory::produceVCellSolver(inputFileStream, taskID);
6519
targetSolver->solve(nullptr, true, outputFile, VCellSundialsSolver::checkStopRequested);
6620
}

IDAWin/SundialsSolverStandalone.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int parseAndRunWithArgParse(int argc, char *argv[]) {
3636
argumentParser.add_argument("input").help("path to directory with input files.").store_into(inputFilePath);
3737
argumentParser.add_argument("output").help("path to directory for output files.").store_into(outputFilePath);
3838
#ifdef USE_MESSAGING
39-
argumentParser.add_argument("-tid").help("path to solver to run.").store_into(taskID);
39+
argumentParser.add_argument("-tid").help("id of the job").store_into(taskID);
4040
#endif
4141

4242
try {

IDAWin/VCellSolverFactory.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ VCellSolverInputBreakdown VCellSolverFactory::parseInputFile(std::ifstream& inpu
103103
else throw VCell::Exception("Unexpected token \"" + nextToken + "\" in the input file!");
104104

105105
}
106+
107+
108+
#ifdef USE_MESSAGING
109+
// Since messaging assumes we have a job requiring messaging, we should initialize a "default" messaging handler
110+
if (NULL == SimulationMessaging::getInstVar()) SimulationMessaging::create();
111+
#endif
106112
return inputBreakdown;
107113
}
108114

@@ -191,7 +197,7 @@ static void readEvents(std::istream &inputStream, VCellSolverInputBreakdown& inp
191197
//eventComponents.eventAssignments.emplace_back(varIndex, assignmentExpression); // should try this in the future, more descriptive
192198
}
193199
break;
194-
} else { throw VCell::Exception("Unexpected token \"" + token + "\" in the input file!"); }
200+
} else { throw VCell::Exception("Unexpected event token \"" + token + "\" in the input file!"); }
195201
}
196202
inputBreakdown.eventSettings.EVENTS.push_back(std::move(eventComponents));
197203
}
@@ -421,13 +427,10 @@ static void collectSteadyStateTerms(std::ifstream& inputFileStream, VCellSolverI
421427

422428
static void loadJMSInfo(std::istream &ifsInput, int taskID) {
423429
#ifndef USE_MESSAGING
424-
return; // Only useful for messaging; let's not waste time!
425-
#else
426-
427-
if (taskID < 0) {
428-
SimulationMessaging::create();
429-
return; // No need to do any parsing
430-
}
430+
// We'll still parse the section, as we can still execute the simulation; we'll just toss the values!
431+
std::cerr << "WARNING: Input file expects messaging capabilities; this build does not support JMS messaging!" << std::endl;
432+
#endif
433+
431434
std::string broker;
432435
std::string smqUserName;
433436
std::string password;
@@ -459,6 +462,7 @@ static void loadJMSInfo(std::istream &ifsInput, int taskID) {
459462
else if (nextToken == "JOB_INDEX") ifsInput >> jobIndex;
460463
}
461464

465+
#ifdef USE_MESSAGING
462466
SimulationMessaging::create(broker.c_str(), smqUserName.c_str(),
463467
password.c_str(), qName.c_str(), topicName.c_str(),
464468
vCellUsername.c_str(), simKey, jobIndex, taskID);

conan-profiles/CI-CD/MacOS-AMD64_profile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ build_type=Release
44
compiler=apple-clang
55
compiler.cppstd=20
66
compiler.libcxx=libc++
7-
compiler.version=17
7+
compiler.version=17cd
88
os=Macos

tests/unit/smoke_test.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@
1616

1717
void compare(const std::filesystem::path& file1, const std::filesystem::path& file2, float tolerance);
1818

19-
20-
TEST(SmokeTest, MessagingRequiresJobID) {
21-
#ifndef USE_MESSAGING
22-
return; // no need to test this
23-
#endif
19+
TEST(SmokeTest, UserProvidesFilesWithoutJMS) {
20+
constexpr int taskID = -1, hashID = 1489333437;
2421
const std::filesystem::path RESOURCE_DIRECTORY{RESOURCE_DIR};
25-
const std::filesystem::path OUTPUT_TARGET{RESOURCE_DIRECTORY /"SimID_1489333437_0_.ida",};
22+
const std::filesystem::path OUTPUT_TARGET{RESOURCE_DIRECTORY /std::format("SimID_{}_0_.ida", hashID)};
2623
const std::array NECESSARY_FILES{
27-
RESOURCE_DIRECTORY /"SimID_1489333437_0_.cvodeInput",
28-
RESOURCE_DIRECTORY /"SimID_1489333437_0_.ida.expected"
24+
RESOURCE_DIRECTORY /std::format("SimID_{}_0_.cvodeInput", hashID),
25+
RESOURCE_DIRECTORY /std::format("SimID_{}_0_.ida.expected", hashID)
2926
};
3027
for (const auto& file : NECESSARY_FILES) {
3128
assert(std::filesystem::exists(file));
@@ -39,16 +36,14 @@ TEST(SmokeTest, MessagingRequiresJobID) {
3936
throw std::runtime_error("Could not open output file[" + OUTPUT_TARGET.string() + "] for writing.");
4037
}
4138

42-
EXPECT_THROW(activateSolver(inputFileStream, outputFile, -1), std::runtime_error);
39+
activateSolver(inputFileStream, outputFile, taskID);
4340
fclose(outputFile);
41+
42+
compare(OUTPUT_TARGET, NECESSARY_FILES[1], 1e-7);
4443
}
4544

46-
TEST(SmokeTest, ConfirmExecution) {
47-
#ifdef USE_MESSAGING
48-
const int taskID = 2025, hashID = 256118677;
49-
#else
50-
const int taskID = -1, hashID = 1489333437;
51-
#endif
45+
TEST(SmokeTest, UserProvidesFilesWithJMS) {
46+
constexpr int taskID = 2025, hashID = 256118677;
5247
const std::filesystem::path RESOURCE_DIRECTORY{RESOURCE_DIR};
5348
const std::filesystem::path OUTPUT_TARGET{RESOURCE_DIRECTORY /std::format("SimID_{}_0_.ida", hashID)};
5449
const std::array NECESSARY_FILES{

0 commit comments

Comments
 (0)