Skip to content

Commit

Permalink
fixed a bug where threads would run ahead and cause a segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeneghini committed Jan 21, 2024
1 parent 1a3a1f8 commit c506fc5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/MIDSX/Core/computational_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,35 @@ int ComputationalDomain::getNumVoxelGrids() const {


void ComputationalDomain::initializeCompDomain(const std::string &json_file_path) {
json json_object;
// Check if the file is a JSON
if (!isJSON(json_file_path)) {
throw std::runtime_error("The file provided is not a JSON file.");
}

// Check if the file exists and is readable
std::filesystem::path json_absolute_path = std::filesystem::absolute(json_file_path);
std::string json_directory_path = json_absolute_path.parent_path().string();
if (isJSON(json_file_path)) {
// create json object
if (!std::filesystem::exists(json_absolute_path) || !std::filesystem::is_regular_file(json_absolute_path)) {
throw std::runtime_error("JSON file does not exist or is not accessible.");
}

// Create json object
json json_object;
try {
std::ifstream json_file(json_file_path);
if (!json_file.is_open()) {
throw std::runtime_error("Failed to open JSON file.");
}

json_file >> json_object;
setCompProperties(json_object);
setVoxelGrids(json_object, json_directory_path);
}
else {
throw std::runtime_error("The file provided is not a JSON file.");
} catch (const std::exception& e) {
throw std::runtime_error("Error parsing JSON file: " + std::string(e.what()));
}
}

// Further processing
std::string json_directory_path = json_absolute_path.parent_path().string();
setCompProperties(json_object);
setVoxelGrids(json_object, json_directory_path);
}
bool ComputationalDomain::isJSON(const std::string &file_path) {
return file_path.find(".json") != std::string::npos;
}
Expand Down
1 change: 1 addition & 0 deletions src/MIDSX/Core/run_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void runSimulation(PhotonSource& source, PhysicsEngine& physics_engine,
physics_engine.addVolumeTallies(std::move(volume_tallies));
physics_engine.initializeVoxelData();
}
#pragma omp barrier // wait for all threads to finish initialization
#pragma omp for
for (int i = 0; i < N_photons; i++) {
Photon photon = source.generatePhoton();
Expand Down

0 comments on commit c506fc5

Please sign in to comment.