Commit c40866d5 authored by Christof Metzger-Kraus's avatar Christof Metzger-Kraus
Browse files

fixing #176

parent fce875d6
......@@ -23,9 +23,8 @@
#include "boost/smart_ptr.hpp"
#include "boost/algorithm/string.hpp"
#ifdef BOOST_FILESYSTEM
#include "boost/filesystem/operations.hpp"
#endif
#include "boost/filesystem.hpp"
#include "boost/filesystem/operations.hpp"
// access to OPAL lib
#include "opal.h"
......@@ -41,12 +40,15 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
, constraints_(constraints)
, comm_(comm)
{
namespace fs = boost::filesystem;
if(getenv("SIMTMPDIR") == NULL) {
std::cout << "Environment variable SIMTMPDIR not defined!"
<< std::endl;
simTmpDir_ = getenv("PWD");
} else
simTmpDir_ = getenv("SIMTMPDIR");
simulationName_ = name;
// prepare design variables given by the optimizer for generating the
......@@ -64,7 +66,7 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
userVariables_.insert(
std::pair<std::string, std::string>(parameter.first, value.str()));
}
/*
This is a copy from Comm/Splitter/ManyMasterSplit.h
in order to calculate the leader which is the unique ID in case
......@@ -78,7 +80,7 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
unsigned num_coworkers_worker_ = 0;
num_coworkers_worker_ = args->getArg<size_t>("num-coworkers");
unsigned group_start = 0;
unsigned worker_group = ((my_rank % world_size) - 2) / num_coworkers_worker_;
......@@ -91,8 +93,8 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
std::string hash = HashNameGenerator::generate(dict);
std::ostringstream tmp;
tmp.precision(15);
tmp << simTmpDir_ << "/" << hash << "_" << leader_;
tmp << simTmpDir_ << "/" << hash << "_" << leader_;
simulationDirName_ = tmp.str();
......@@ -104,6 +106,12 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
std::string tmplFile = tmplDir + "/" + simulationName_ + ".tmpl";
// data file is assumed to be located in the root directory
std::string dataFile = simulationName_ + ".data";
if (!fs::exists(dataFile))
throw OptPilotException("OpalSimulation::OpalSimulation", "The data file '" + dataFile + "' doesn't exist");
if (!fs::exists(tmplFile))
throw OptPilotException("OpalSimulation::OpalSimulation", "The template file '" + tmplFile + "' doesn't exit");
gs_.reset(new GenerateOpalSimulation(tmplFile, dataFile, userVariables_));
}
......@@ -147,7 +155,7 @@ void OpalSimulation::setupSimulation() {
"Environment variable FIELDMAPS not defined!");
}
std::string fieldmapPath = getenv("FIELDMAPS");
struct dirent **files;
int count = scandir(fieldmapPath.c_str(), &files, 0, alphasort);
......@@ -201,7 +209,7 @@ void OpalSimulation::restoreOut() {
void OpalSimulation::run() {
// make sure input file is not already existing
MPI_Barrier(comm_);
if( hasResultsAvailable() ) return;
......@@ -411,7 +419,7 @@ bool OpalSimulation::getVariableDictionary(variableDictionary_t& dictionary,
} catch(OptPilotException &e) {
std::cout << "Exception while parsing SDDS file: "
<< e.what() << std::endl;
//XXX: in this case we mark the bunch as invalid since
// broken stat files can crash opt (why do they
// exist?)
......@@ -422,7 +430,7 @@ bool OpalSimulation::getVariableDictionary(variableDictionary_t& dictionary,
// get all the required variable values from the stat file
for(std::string req_var : req_vars) {
if(dictionary.count(req_var) != 0) continue;
try {
double value = 0.0;
sddsr->getValue(-1 /*atTime*/, req_var, value);
......@@ -458,4 +466,4 @@ void OpalSimulation::cleanUp() {
}
#endif
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment