Skip to content
Snippets Groups Projects
Commit ae950bad authored by KyleKlenk's avatar KyleKlenk
Browse files

added functionallity to change settings by

Json File for the SummaActor and JobActor
parent c13358b5
No related branches found
No related tags found
No related merge requests found
......@@ -55,13 +55,6 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
(self->state.end - self->state.start).count();
},
// [=](file_information, int outputStrucSize, int stepsInCurrentFFile) {
// self->state.outputStrucSize = outputStrucSize;
// self->state.stepsInCurrentFFile = stepsInCurrentFFile;
// self->state.outputStep = 1;
// self->send(self, run_hru_v, self->state.stepsInCurrentFFile);
// },
[=](done_write) {
self->state.start = std::chrono::high_resolution_clock::now();
......
......@@ -15,6 +15,7 @@
#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include "json.hpp"
struct job_state {
// Actor References
......@@ -24,6 +25,8 @@ struct job_state {
// Job Parameters
int startGRU; // Starting GRU for this job
int numGRU; // Number of GRUs for this job
std::string configPath;
std::string fileManager; // Path of the fileManager.txt file
// Variables for GRU monitoring
......@@ -42,13 +45,17 @@ struct job_state {
double duration;
// Output File Names for Timings
std::string successOutputFile = "/scratch/gwf/gwf_cmt/kck540/summaActors/csvFiles/SuccessHRU";
bool outputCSV;
std::string csvOut;
std::string csvPath;
std::string successOutputFile = "SuccessHRU";
std::string failedOutputFile = "failedHRU";
std::string fileAccessActorStats = "fileAccessActor.csv";
};
int parseSettings(stateful_actor<job_state>* self, std::string configPath);
void initJob(stateful_actor<job_state>* self);
void initalizeGRU(stateful_actor<job_state>* self);
......
......@@ -4,7 +4,7 @@
#include "Job.h"
using namespace caf;
using json = nlohmann::json;
/**
* @brief First Actor that is spawned that is not the Coordinator Actor.
......@@ -13,15 +13,26 @@ using namespace caf;
* @return behavior
*/
behavior job_actor(stateful_actor<job_state>* self, int startGRU, int numGRU,
std::string fileManager, int outputStrucSize, std::string csvOut, caf::actor parent) {
std::string configPath, int outputStrucSize, caf::actor parent) {
self->state.start = std::chrono::high_resolution_clock::now();
// Set Job Variables
self->state.startGRU = startGRU;
self->state.numGRU = numGRU;
self->state.fileManager = fileManager;
self->state.configPath = configPath;
self->state.parent = parent;
self->state.outputStrucSize = outputStrucSize;
self->state.csvOut = csvOut;
if (parseSettings(self, configPath) == -1) {
aout(self) << "ERROR WITH JSON SETTINGS FILE!!!\n";
self->quit();
} else {
aout(self) << "SETTINGS FOR JOB_ACTOR\n" <<
"File Manager Path = " << self->state.fileManager << "\n" <<
"outputCSV = " << self->state.outputCSV << "\n";
if (self->state.outputCSV) {
aout(self) << "csvPath = " << self->state.csvPath << "\n";
}
}
// Initalize global variables
initJob(self);
......@@ -67,7 +78,11 @@ behavior job_actor(stateful_actor<job_state>* self, int startGRU, int numGRU,
aout(self) << "GRU " << indxGRU << " Done\n";
self->state.GRUList[indxGRU - 1]->doneRun(totalDuration, initDuration, forcingDuration,
runPhysicsDuration, writeOutputDuration);
self->state.GRUList[indxGRU - 1]->writeSuccess(self->state.successOutputFile);
if (self->state.outputCSV) {
self->state.GRUList[indxGRU - 1]->writeSuccess(self->state.successOutputFile);
}
self->state.numGRUDone++;
// Check if we are done
......@@ -119,14 +134,61 @@ behavior job_actor(stateful_actor<job_state>* self, int startGRU, int numGRU,
};
}
int parseSettings(stateful_actor<job_state>* self, std::string configPath) {
json settings;
std::string SummaActorsSettigs = "/Summa_Actors_Settings.json";
std::ifstream settings_file(configPath + SummaActorsSettigs);
settings_file >> settings;
settings_file.close();
if (settings.find("JobActor") != settings.end()) {
json JobActorConfig = settings["JobActor"];
// Find the File Manager Path
if (JobActorConfig.find("FileManagerPath") != JobActorConfig.end()) {
self->state.fileManager = JobActorConfig["FileManagerPath"];
} else {
aout(self) << "Error Finding FileManagerPath - Exiting as this is needed\n";
return -1;
}
// Find if we want to outputCSV
if (JobActorConfig.find("outputCSV") != JobActorConfig.end()) {
self->state.outputCSV = JobActorConfig["outputCSV"];
} else {
aout(self) << "Error Finding outputCSV in JSON file - Reverting to Default Value\n";
self->state.outputCSV = false;
}
// Output Path of CSV
if (self->state.outputCSV) {
if (JobActorConfig.find("csvPath") != JobActorConfig.end()) {
self->state.csvPath = JobActorConfig["csvPath"];
} else {
aout(self) << "Error Finding csvPath in JSON file = Reverting to Default Value \n";
self->state.outputCSV = false; // we just choose not to output a csv
}
}
return 0;
} else {
aout(self) << "Error Finding JobActor in JSON file - Exiting as there is no path for the fileManger\n";
return -1;
}
}
void initJob(stateful_actor<job_state>* self) {
std::ofstream file;
self->state.successOutputFile += std::to_string(self->state.startGRU) += self->state.csvOut +=".csv";
file.open(self->state.successOutputFile, std::ios_base::out);
file << "GRU" << "," << "totalDuration" << "," << "initDuration" << "," <<
"forcingDuration" << "," << "runPhysicsDuration" << "," << "writeOutputDuration" <<
"," << "dt_init" << "," << "numAttemtps" << "\n";
file.close();
if (self->state.outputCSV) {
std::ofstream file;
self->state.successOutputFile += std::to_string(self->state.startGRU) += ".csv";
file.open(self->state.successOutputFile, std::ios_base::out);
file << "GRU" << "," << "totalDuration" << "," << "initDuration" << "," <<
"forcingDuration" << "," << "runPhysicsDuration" << "," << "writeOutputDuration" <<
"," << "dt_init" << "," << "numAttemtps" << "\n";
file.close();
}
int totalGRUs = 0;
int totalHRUs = 0;
......
......@@ -4,24 +4,27 @@
#include "SummaManager.h"
using namespace caf;
using json = nlohmann::json;
/**
* Top Level Actor for Summa. This actor recieves the number of GRUs to compute from main and
* divides them into jobs that compute one at a time.
*
* @param startGRU - starting GRU for the simulation
* @param numGRU - total number of GRUs to compute
* @param fileManager - location of file information for SUMMA
* @param configPath - location of file information for SUMMA
* @return behavior
*/
behavior summa_actor(stateful_actor<summa_manager>* self, int startGRU, int numGRU, std::string fileManager, std::string csvOut) {
behavior summa_actor(stateful_actor<summa_manager>* self, int startGRU, int numGRU, std::string configPath) {
self->state.start = std::chrono::high_resolution_clock::now();
// Set Variables
self->state.startGRU = startGRU;
self->state.numGRU = numGRU;
self->state.fileManager = fileManager;
self->state.csvOut = csvOut;
self->state.configPath = configPath;
parseSettings(self, configPath);
aout(self) << "SETTINGS FOR SUMMA_ACTOR\n";
aout(self) << "Output Structure Size = " << self->state.outputStrucSize << "\n";
aout(self) << "Max GRUs Per Job = " << self->state.maxGRUPerJob << "\n";
// Create the job_actor and start SUMMA
spawnJob(self);
......@@ -56,7 +59,7 @@ void spawnJob(stateful_actor<summa_manager>* self) {
if (self->state.numGRU > self->state.maxGRUPerJob) {
// spawn the job actor
self->state.currentJob = self->spawn(job_actor, self->state.startGRU, self->state.maxGRUPerJob,
self->state.fileManager, self->state.outputStrucSize, self->state.csvOut, self);
self->state.configPath, self->state.outputStrucSize, self);
// Update GRU count
self->state.numGRU = self->state.numGRU - self->state.maxGRUPerJob;
......@@ -65,11 +68,44 @@ void spawnJob(stateful_actor<summa_manager>* self) {
} else {
self->state.currentJob = self->spawn(job_actor, self->state.startGRU, self->state.numGRU,
self->state.fileManager, self->state.outputStrucSize, self->state.csvOut, self);
self->state.configPath, self->state.outputStrucSize, self);
self->state.numGRU = 0;
}
}
void parseSettings(stateful_actor<summa_manager>* self, std::string configPath) {
json settings;
std::string SummaActorsSettings = "/Summa_Actors_Settings.json";
std::ifstream settings_file(configPath + SummaActorsSettings);
settings_file >> settings;
settings_file.close();
if (settings.find("SummaActor") != settings.end()) {
json SummaActorConfig = settings["SummaActor"];
// Find the desired OutputStrucSize
if (SummaActorConfig.find("OuputStrucureSize") != SummaActorConfig.end()) {
self->state.outputStrucSize = SummaActorConfig["OuputStrucureSize"];
} else {
aout(self) << "Error Finding OutputStructureSize in JOSN - Reverting to default value\n";
self->state.outputStrucSize = 250;
}
// Find the desired maxGRUPerJob size
if (SummaActorConfig.find("maxGRUPerJob") != SummaActorConfig.end()) {
self->state.maxGRUPerJob = SummaActorConfig["maxGRUPerJob"];
} else {
aout(self) << "Error Finding maxGRUPerJob in JOSN - Reverting to default value\n";
self->state.maxGRUPerJob = 500;
}
} else {
aout(self) << "Error Finding SummaActor in JSON - Reverting to default values\n";
self->state.outputStrucSize = 250;
self->state.maxGRUPerJob = 500;
}
}
#endif
\ No newline at end of file
......@@ -7,6 +7,8 @@
#include <iostream>
#include <chrono>
#include <string>
#include "json.hpp"
#include <fstream>
......@@ -18,13 +20,13 @@ struct summa_manager {
// Program Parameters
int startGRU; // starting GRU for the simulation
int numGRU; // number of GRUs to compute
std::string fileManager;// path to the fileManager.txt file
std::string configPath;// path to the fileManager.txt file
// Information about the jobs
int maxGRUPerJob = 500; // maximum number of GRUs a job can compute at once
int numFailed = 0; // Number of jobs that have failed
int outputStrucSize = 500;
std::string csvOut;
// Values Set By Summa_Actors_Settings.json
int maxGRUPerJob; // maximum number of GRUs a job can compute at once
int outputStrucSize;
caf::actor currentJob; // Reference to the current job actor
......@@ -34,4 +36,6 @@ struct summa_manager {
* @brief Function to spawn a job actor
*/
void spawnJob(stateful_actor<summa_manager>* self);
void parseSettings(stateful_actor<summa_manager>* self, std::string configPath);
#endif
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -15,15 +15,13 @@ class config : public actor_system_config {
public:
int startGRU = -1;
int countGRU = -1;
std::string fileManager = ""; // master file
std::string csvOut = "";
std::string configPath = ""; // master file
config() {
opt_group{custom_options_, "global"}
.add(startGRU, "gru,g", "Starting GRU Index")
.add(countGRU, "countGRU,c", "Total Number of GRUs")
.add(fileManager, "master,m", "Path name of master file")
.add(csvOut, "csv,v", "nameOfCSV");
.add(countGRU, "numGRU,n", "Total Number of GRUs")
.add(configPath, "config,c", "Path name of the config directory");
}
};
......@@ -32,23 +30,23 @@ void caf_main(actor_system& sys, const config& cfg) {
if (cfg.startGRU == -1) {
aout(self) << "Starting GRU was not defined!! " <<
"startGRU is set with the \"-g\" option\n";
aout(self) << "EXAMPLE: ./summaMain -g 1 -c 10 -m file/manager/location \n";
aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
return;
}
if (cfg.countGRU == -1) {
aout(self) << "Number of GRUs was not defined!! " <<
"countGRU is set with the \"-c\" option\n";
aout(self) << "EXAMPLE: ./summaMain -g 1 -c 10 -m file/manager/location \n";
"countGRU is set with the \"-n\" option\n";
aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
return;
}
if (cfg.fileManager == "") {
if (cfg.configPath == "") {
aout(self) << "File Manager was not defined!! " <<
"fileManger is set with the \"-m\" option\n";
aout(self) << "EXAMPLE: ./summaMain -g 1 -c 10 -m file/manager/location \n";
"fileManger is set with the \"-c\" option\n";
aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
return;
}
// start SUMMA
auto summa = sys.spawn(summa_actor, cfg.startGRU, cfg.countGRU, cfg.fileManager, cfg.csvOut);
auto summa = sys.spawn(summa_actor, cfg.startGRU, cfg.countGRU, cfg.configPath);
}
CAF_MAIN(id_block::summa)
\ No newline at end of file
{
"SummaActor": {
"OuputStrucureSize": 250,
"maxGRUPerJob": 500
},
"JobActor": {
"FileManagerPath": "/project/gwf/gwf_cmt/kck540/domain_NorthAmerica/settings/SUMMA/fileManager.txt",
"outputCSV": false,
"csvPath": ""
}
}
\ No newline at end of file
controlVersion 'SUMMA_FILE_MANAGER_V3.0.0' ! file manager version
simStartTime '1979-01-01 00:00' !
simEndTime '1988-12-31 23:00' !
tmZoneInfo 'utcTime' !
settingsPath '/project/gwf/gwf_cmt/kck540/domain_NorthAmerica/settings/SUMMA/' !
forcingPath '/project/gwf/gwf_cmt/kck540/domain_NorthAmerica/forcing/SummaChunkedData/' !
outputPath '/scratch/gwf/gwf_cmt/kck540/SummaOutput/SummaActors/netcdf/Mar-23-2022/' !
forcingFreq 'month' ! the frequeny of forcing files (month, year)
forcingStart '1979-01-01'
decisionsFile 'modelDecisions.txt' ! Relative to settingsPath
outputControlFile 'outputControl.txt' ! Relative to settingsPath
globalHruParamFile 'localParamInfo.txt' ! Relative to settingsPath
globalGruParamFile 'basinParamInfo.txt' ! Relative to settingsPatho
attributeFile 'attributes.nc' ! Relative to settingsPath
trialParamFile 'trialParams.nc' ! Relative to settingsPath
forcingListFile 'forcingFileList.txt' ! Relative to settingsPath
initConditionFile 'coldState.nc' ! Relative to settingsPath
outFilePrefix 'SummaActors' !
vegTableFile 'TBL_VEGPARM.TBL' ! Relative to settingsPath
soilTableFile 'TBL_SOILPARM.TBL' ! Relative to settingsPath
generalTableFile 'TBL_GENPARM.TBL' ! Relative to settingsPath
noahmpTableFile 'TBL_MPTABLE.TBL' ! Relative to settingsPath
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment