Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gwu479/Summa-Actors
  • numerical_simulations_lab/actors/Summa-Actors
2 results
Show changes
Showing
with 631 additions and 1143 deletions
#pragma once
extern "C" {
void getVarSizes(int* num_var_types, int* num_bpar_vars, int* num_bvar_vars);
void initVarType(void* var_type_lookup);
void fillVarTypeLists( int* num_bpar_vars, int* num_bvar_vars,
void* bpar_struct_var_type_list, void* bvar_struct_var_type_list, int* err);
int getNumHRU(int* indx_gru);
}
\ No newline at end of file
#pragma once
......@@ -2,13 +2,47 @@
#include "caf/all.hpp"
#include "fortran_data_types.hpp"
#include "auxilary.hpp"
#include "timing_info.hpp"
#include <chrono>
#include "settings_functions.hpp"
#include <string>
#include "message_atoms.hpp"
#include "global.hpp"
/*********************************************
* HRU Actor Fortran Functions
*********************************************/
extern "C" {
// Initialize HRU data_structures
void initHRU(int* indxGRU, int* num_steps, void* hru_data, int* err);
void setupHRUParam( int* indxGRU, int* indxHRU, void* hru_data, double* upArea, int* err);
// Setup summa_readRestart File if this option has been chosen
void summa_readRestart(int* indxGRU, int* indxHRU, void* hru_data, double* dtInit, int* err);
// Run the model for one timestep
void RunPhysics(int* id, int* stepIndex, void* hru_data, double* dt, int* dt_int_factor, int* err);
void hru_writeOutput(int* index_hru, int* index_gru, int* timestep, int* output_step, void* hru_data, int* err);
void setTimeZoneOffset(int* iFile, void* hru_data, int* err);
void HRU_readForcing(int* index_gru, int* iStep, int* iRead, int* iFile, void* hru_data, int* err);
void get_sundials_tolerances(void* hru_data, double* relTol, double* absTol);
void set_sundials_tolerances(void* hru_data, double* relTol, double* absTol);
void setIDATolerances(void* hru_data, double* relTolTempCas, double* absTolTempCas, double* relTolTempVeg,
double* absTolTempVeg, double* relTolWatVeg, double* absTolWatVeg, double* relTolTempSoilSnow,
double* absTolTempSoilSnow, double* relTolWatSnow, double* absTolWatSnow, double* relTolMatric,
double* absTolMatric, double* relTolAquifr, double* absTolAquifr);
}
/*********************************************
* HRU Actor state variables
*********************************************/
namespace caf {
struct hru_state {
// Actor References
......@@ -21,94 +55,49 @@ struct hru_state {
int indxGRU; // index for gru part of derived types in FORTRAN
int refGRU; // The actual ID of the GRU we are
// Variables for output/forcing structures
int outputStrucSize;
int outputStep;
int stepsInCurrentFFile;
int forcingFileStep;
int currentForcingFile = 1;
// statistics structures
void *handle_forcStat = new_handle_var_dlength(); // model forcing data
void *handle_progStat = new_handle_var_dlength(); // model prognostic (state) variables
void *handle_diagStat = new_handle_var_dlength(); // model diagnostic variables
void *handle_fluxStat = new_handle_var_dlength(); // model fluxes
void *handle_indxStat = new_handle_var_dlength(); // model indices
void *handle_bvarStat = new_handle_var_dlength(); // basin-average variables
// primary data structures (scalars)
void *handle_timeStruct = new_handle_var_i(); // model time data
void *handle_forcStruct = new_handle_var_d(); // model forcing data
void *handle_attrStruct = new_handle_var_d(); // local attributes for each HRU
void *handle_typeStruct = new_handle_var_i(); // local classification of soil veg etc. for each HRU
void *handle_idStruct = new_handle_var_i8();
// primary data structures (variable length vectors)
void *handle_indxStruct = new_handle_var_ilength(); // model indices
void *handle_mparStruct = new_handle_var_dlength(); // model parameters
void *handle_progStruct = new_handle_var_dlength(); // model prognostic (state) variables
void *handle_diagStruct = new_handle_var_dlength(); // model diagnostic variables
void *handle_fluxStruct = new_handle_var_dlength(); // model fluxes
// basin-average structures
void *handle_bparStruct = new_handle_var_d(); // basin-average parameters
void *handle_bvarStruct = new_handle_var_dlength(); // basin-average variables
// ancillary data structures
void *handle_dparStruct = new_handle_var_d(); // default model parameters
// Local hru data
void *handle_ncid = new_handle_var_i(); // output file ids
void *handle_statCounter = new_handle_var_i();
void *handle_outputTimeStep = new_handle_var_i();
void *handle_resetStats = new_handle_flagVec();
void *handle_finalizeStats = new_handle_flagVec();
void *handle_oldTime = new_handle_var_i();
void *handle_refTime = new_handle_var_i();
void *handle_finshTime = new_handle_var_i();
void *handle_startTime = new_handle_var_i();
// Misc Variables
int timestep = 1; // Current Timestep of HRU simulation
int computeVegFlux; // flag to indicate if we are computing fluxes over vegetation
double dt_init; // used to initialize the length of the sub-step for each HRU
double upArea; // area upslope of each HRU
int num_steps = 0; // number of time steps
int forcingStep; // index of current time step in current forcing file
int iFile; // index of current forcing file from forcing file list
int dt_init_factor = 1; // factor of dt_init (coupled_em)
bool printOutput;
int outputFrequency;
// Julian Day variables
double fracJulDay;
double tmZoneOffsetFracDay;
int yearLength;
int err = 0; // error conotrol
TimingInfo hru_timing;
// Variables for forcing structures
int stepsInCurrentFFile; // number of time steps in current forcing file
int num_steps_until_write; // number of time steps until we pause for FA_Actor to write
// HRU data structures (formerly summa_type)
void *hru_data = new_handle_hru_type();
// Misc Variables
int timestep = 1; // Current Timestep of HRU simulation
int forcingStep = 1; // index of current time step in current forcing file
int num_steps = 0; // number of time steps
int iFile = 1; // index of current forcing file from forcing file list
int dt_init_factor = 1; // factor of dt_init (coupled_em)
int output_structure_step_index = 1; // index of current time step in output structure
double dt_init; // used to initialize the length of the sub-step for each HRU
double upArea; // area upslope of each HRU
int err = 0;
// Sundials variables
double rtol = -9999; // -9999 uses default
double atol = -9999; // -9999 uses default
// Settings
HRU_Actor_Settings hru_actor_settings;
~hru_state() {
delete_handle_hru_type(hru_data);
}
};
behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
std::string configPath,
caf::actor file_access_actor, int outputStrucSize, caf::actor parent);
HRU_Actor_Settings hru_actor_settings, caf::actor file_access_actor,
caf::actor parent);
/**
Function to initalize the HRU for running
*/
/*********************************************
* Functions for the HRU Actor
*********************************************/
/** Function to initalize the HRU for running */
void Initialize_HRU(stateful_actor<hru_state>* self);
/**
Function runs all of the hru time_steps
*/
/** Function runs all of the hru time_steps */
int Run_HRU(stateful_actor<hru_state>* self);
bool check_HRU(stateful_actor<hru_state>* self, int err);
void initalizeTimeVars(stateful_actor<hru_state>* self);
void finalizeTimeVars(stateful_actor<hru_state>* self);
void deallocateHRUStructures(stateful_actor<hru_state>* self);
void printOutput(stateful_actor<hru_state>* self);
}
\ No newline at end of file
#pragma once
extern "C" {
// Initialize HRU data_structures
void summaActors_initialize(
int* indxGRU, int* num_steps,
// Statistics Structures
void* forcStat, void* progStat, void* diagStat, void* fluxStat, void* indxStat, void* bvarStat,
// Primary Data Structures (scalars)
void* timeStruct, void* forcStruct, void* attrStruct, void* typeStruct, void* idStruct,
// primary data structures (variable length vectors)
void* indxStruct, void* mparStruct, void* progStruct, void* diagStruct, void* fluxStruct,
// basin-average structures
void* bparStruct, void* bvarStruct,
// ancillary data structures
void* dparStruct,
// local HRU data
void* startTime, void* finshTime, void* refTime, void* oldTime, int* err);
// SetupParam for HRU
void SetupParam(
int* indxGRU, int* indxHRU,
// primary data structures (scalars)
void* attrStruct, void* typeStruct, void* idStruct,
// primary data structures (variable length vectors)
void* mparStruct, void* bparStruct, void* bvarStruct, void* dparStruct,
// local HRU data
void* startTime, void* oldTime,
// miscellaneous
double* upArea, int* err);
// Setup Restart File if this option has been chosen
void Restart(
int* indxGRU, int* indxHRU,
// primary data structures (variable length vectors)
void* indxStruct, void* mparStruct, void* progStruct, void* diagStruct, void* fluxStruct,
// basin-average structures
void* bvarStruct,
// misc
double* dtInit, int* err);
// Read Forcing for HRU
void Forcing(
int* indxGRU, int* stepIndex,
void* timeStruct, void* forcStruct,
int* iFile, int* forcingStep,
double* fracJulDay, double* tmZoneOffsetFracDay, int* yearLength,
int* err);
// Run the model for one timestep
void RunPhysics(
int* id, int* stepIndex,
// primary data structures (scalars)
void* timeStruct, void* forcStruct, void* attrStruct, void* typeStruct,
// primary data structures (variable length vectors)
void* indxStruct, void* mparStruct, void* progStruct, void* diagStruct, void* fluxStruct,
// basin-average structures
void* bvarStruct,
double* fracJulDay, double* tmZoneOffsetFracDay, int* yearLength,
// misc
int* flag, double* dt, int* dt_int_factor, int* err);
// Write output to the output structure
void WriteOutput(
int* indHRU, int* indxGRU, int* indexStep,
// statistics structures
void* forcStat, void* progStat, void* diagStat, void* fluxStat, void* indxStat, void* bvarStat,
// primary data structures (scalars)
void* timeStruct, void* forcStruct, void* attrStruct, void* typeStruct,
// primary data structures (variable length vectors)
void* indxStruct, void* mparStruct, void* progStruct, void* diagStruct, void* fluxStruct,
// basin-average structures
void* bparStruct, void* bvarStruct,
// local vars
void* statCounter, void* outputTimeStep, void* resetStats, void* finalizeStats,
void* finshTime, void* oldTime, int* outputStep, int* err);
void DeallocateStructures(
void* handle_forcStat, void* handle_progStat, void* handle_diagStat, void* handle_fluxStat,
void* handle_indxStat, void* handle_bvarStat, void* handle_timeStruct, void* handle_forcStruct,
void* handle_attrStruct, void* handle_typeStruct, void* handle_idStruct, void* handle_indxStruct,
void* handle_mparStruct, void* handle_progStruct, void* handle_diagStruct, void* handle_fluxStruct,
void* handle_bparStruct, void* handle_bvarStruct, void* handle_dparStruct,
void* handle_startTime, void* handle_finishTime,
void* handle_refTime, void* handle_oldTime,
void* handle_ncid,
void* handle_statCounter,
void* handle_outputTimeStep,
void* handle_resetStats,
void* handle_finalizeStats,
int* err);
void Write_Param_C(
int* indxGRU, int* indxHRU,
void* handle_attrStruct, void* handle_typeStruct, void* handle_mparStruct, void* handle_bparStruct,
int* err);
}
\ No newline at end of file
#pragma once
#include "caf/all.hpp"
#include <iostream>
#include <fstream>
/*
* Determine the state of the GRU
*/
enum class gru_state {
running,
failed,
succeeded
};
int is_success(const gru_state& state);
/**
* Class that holds information about the running GRUs. This class is held by the job actor
* The GRU/HRU actors that carry out the simulation are held by the GRU class
*/
class GRU {
private:
int global_gru_index; // The index of the GRU in the netcdf file
int local_gru_index; // The index of the GRU within this job
caf::actor gru_actor; // The actor for the GRU
// Modifyable Parameters
int dt_init_factor; // The initial dt for the GRU
double rel_tol; // The relative tolerance for the GRU
double abs_tol; // The absolute tolerance for the GRU
// Status Information
int attempts_left; // The number of attempts left for the GRU to succeed
gru_state state; // The state of the GRU
// Timing Information
double run_time = 0.0; // The total time to run the GRU
double init_duration = 0.0; // The time to initialize the GRU
double forcing_duration = 0.0; // The time to read the forcing data
double run_physics_duration = 0.0; // The time to run the physics
double write_output_duration = 0.0; // The time to write the output
public:
// Constructor
GRU(int global_gru_index, int local_gru_index, caf::actor gru_actor, int dt_init_factor,
double rel_tol, double abs_tol, int max_attempts);
// Deconstructor
~GRU();
// Getters
int getGlobalGRUIndex();
int getLocalGRUIndex();
caf::actor getGRUActor();
double getRunTime();
double getInitDuration();
double getForcingDuration();
double getRunPhysicsDuration();
double getWriteOutputDuration();
double getRelTol();
double getAbsTol();
double getAttemptsLeft();
gru_state getStatus();
bool isFailed();
// Setters
void setRunTime(double run_time);
void setInitDuration(double init_duration);
void setForcingDuration(double forcing_duration);
void setRunPhysicsDuration(double run_physics_duration);
void setWriteOutputDuration(double write_output_duration);
void setRelTol(double rel_tol);
void setAbsTol(double abs_tol);
void setSuccess();
void setFailed();
void setRunning();
void decrementAttemptsLeft();
void setGRUActor(caf::actor gru_actor);
};
#pragma once
#include "caf/all.hpp"
#include <iostream>
#include <fstream>
class GRUinfo {
private:
int refGRU; // This will be the same as the refGRU
int indxGRU;
caf::actor GRU;
// Variable to update
int dt_init;
// Completed Information
int currentAttempt;
int maxAttempts;
bool completed;
bool failed;
// Timing information for the GRU
double runTime;
double initDuration;
double forcingDuration;
double runPhysicsDuration;
double writeOutputDuration;
public:
// Constructor
GRUinfo(int refGRU, int indxGRU, caf::actor gru, int dt_init, int maxAttempts);
// Deconstructor
~GRUinfo();
int getRefGRU();
int getIndxGRU();
int getDt_init();
caf::actor getActor();
void updateGRU(caf::actor gru);
void updateFailed();
void updateCompletedToTrue();
void updateDt_init();
void updateCurrentAttempt();
bool isMaxAttemptsReached();
bool isFailed();
bool isCompleted();
void doneRun(double runTime, double initDuration, double forcingDuration,
double runPhysicsDuration, double writeOutputDuration);
void writeSuccess(std::string fileName);
void writeFail(std::string fileName);
void printOutput();
};
\ No newline at end of file
#pragma once
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "GRUinfo.hpp"
#include "GRU.hpp"
#include "timing_info.hpp"
#include "settings_functions.hpp"
#include "global.hpp"
#include "json.hpp"
#include "hru_actor.hpp"
#include "message_atoms.hpp"
#include "file_access_actor.hpp"
#include <unistd.h>
#include <limits.h>
/*********************************************
* Job Actor Fortran Functions
*********************************************/
extern "C" {
void job_init_fortran(char const* file_manager, int* start_gru_index, int* num_gru, int* num_hru, int* err);
void deallocateJobActor(int* err);
}
/*********************************************
* Job Actor state variables
*********************************************/
namespace caf {
using chrono_time = std::chrono::time_point<std::chrono::system_clock>;
// Holds information about the GRUs
struct GRU_Container {
std::vector<GRU*> gru_list;
chrono_time gru_start_time; // Vector of start times for each GRU
int num_gru_done = 0;
int num_gru_failed = 0; // number of grus that are waiting to be restarted
int num_gru_in_run_domain = 0; // number of grus we are currently solving for
int run_attempts_left = 1; // current run attempt for all grus
};
struct job_state {
// Actor References
caf::actor file_access_actor; // actor reference for the file_access_actor
caf::actor parent; // actor reference to the top-level SummaActor
// Job Parameters
int startGRU; // Starting GRU for this job
int numGRU; // Number of GRUs for this job
std::string configPath;
int start_gru; // Starting GRU for this job
int num_gru; // Number of GRUs for this job
int num_hru;
int max_run_attempts = 1; // Max number of attempts to solve a GRU
std::string fileManager; // Path of the fileManager.txt file
GRU_Container gru_container;
// Variables for GRU monitoring
int dt_init_start_factor = 1; // Initial Factor for dt_init (coupled_em)
int maxRunAttempts = 3; // Max number of attemtps to solve a GRU
std::vector<GRUinfo*> GRUList; // List of all GRUs under this job actor
int numGRUDone = 0; // The number of GRUs that have completed
int GRUInit = 0; // Number of GRUs initalized
int err = 0; // Error Code
int numGRUFailed = 0; // Number of GRUs that have failed
int outputStrucSize;
int dt_init_start_factor = 1; // Initial Factor for dt_init (coupled_em)
int num_gru_done = 0; // The number of GRUs that have completed
int num_gru_failed = 0; // Number of GRUs that have failed
// Timing Variables
TimingInfo job_timing;
// Output File Names for Timings
bool outputCSV;
std::string csvOut;
std::string csvPath;
std::string successOutputFile;
std::string failedOutputFile = "failedHRU";
std::string fileAccessActorStats = "fileAccessActor.csv";
std::string hostname;
};
// settings for all child actors (save in case we need to recover)
File_Access_Actor_Settings file_access_actor_settings;
Job_Actor_Settings job_actor_settings;
HRU_Actor_Settings hru_actor_settings;
behavior job_actor(stateful_actor<job_state>* self, int startGRU, int numGRU,
std::string configPath, int outputStrucSize, actor parent);
};
int parseSettings(stateful_actor<job_state>* self, std::string configPath);
void initJob(stateful_actor<job_state>* self);
/** The Job Actor */
behavior job_actor(stateful_actor<job_state>* self,
int start_gru, int num_gru,
File_Access_Actor_Settings file_access_actor_settings,
Job_Actor_Settings job_actor_settings,
HRU_Actor_Settings hru_actor_settings,
actor parent);
void initalizeGRU(stateful_actor<job_state>* self);
void runGRUs(stateful_actor<job_state>* self);
/*********************************************
* Functions for the Job Actor
*********************************************/
void restartFailures(stateful_actor<job_state>* self);
/** Get the information for the GRUs that will be written to the netcdf file */
std::vector<serializable_netcdf_gru_actor_info> getGruNetcdfInfo(int max_run_attempts,
std::vector<GRU*> &gru_list);
void handleGRUError(stateful_actor<job_state>* self, caf::actor src);
} // end namespace
\ No newline at end of file
#pragma once
extern "C" {
void initGlobals(char const*str1, int* totalGRUs, int* totalHRUs,
int* numGRUs, int* numHRUs, int* startGRUIndex, int* err);
void cleanUpJobActor(int* err);
}
\ No newline at end of file
#pragma once
#include "caf/all.hpp"
#include <string>
class Batch {
private:
int batch_id_;
int start_hru_;
int num_hru_;
double run_time_;
double read_time_;
double write_time_;
bool assigned_to_actor_;
bool solved_;
public:
Batch(int batch_id = -1, int start_hru = -1, int num_hru = -1);
// Getters
int getBatchID();
int getStartHRU();
int getNumHRU();
double getRunTime();
double getReadTime();
double getWriteTime();
bool isAssigned();
bool isSolved();
std::string getBatchInfoString();
// Setters
void updateRunTime(double run_time);
void updateReadTime(double read_time);
void updateWriteTime(double write_time);
void updateAssigned(bool boolean);
void updateSolved(bool boolean);
void printBatchInfo();
void writeBatchToFile(std::string csv_output, std::string hostname);
std::string toString();
void assignToActor(std::string hostname, caf::actor assigned_actor);
template <class Inspector>
friend bool inspect(Inspector& inspector, Batch& batch) {
return inspector.object(batch).fields(
inspector.field("batch_id", batch.batch_id_),
inspector.field("start_hru", batch.start_hru_),
inspector.field("num_hru", batch.num_hru_),
inspector.field("run_time", batch.run_time_),
inspector.field("read_time", batch.read_time_),
inspector.field("write_time", batch.write_time_),
inspector.field("assigned_to_actor", batch.assigned_to_actor_),
inspector.field("solved", batch.solved_));
}
};
\ No newline at end of file
#include "caf/all.hpp"
#pragma once
#include "client.hpp"
class Batch_Container {
private:
int start_hru_;
int total_hru_count_;
int num_hru_per_batch_;
int batches_remaining_;
std::vector<Batch> batch_list_;
// Assemble the total number of HRUs given by the user into batches.
void assembleBatches();
public:
// Creating the batch_manager will also create the batches
// with the two parameters that are passed in.
Batch_Container(int start_hru = 1, int total_hru_count = 0,
int num_hru_per_batch = 0);
// returns the size of the batch list
int getBatchesRemaining();
int getTotalBatches();
// Find an unsolved batch, set it to assigned and return it.
std::optional<Batch> getUnsolvedBatch();
// Update the batch status to solved and write the output to a file.
void updateBatch_success(Batch successful_batch, std::string output_csv, std::string hostname);
// Update the batch status but do not write the output to a file.
void updateBatch_success(Batch successful_batch);
// Update batch by id
void updateBatch_success(int batch_id, double run_time, double read_time,
double write_time);
// Update the batch to assigned = true
void setBatchAssigned(Batch batch);
// Update the batch to assigned = false
void setBatchUnassigned(Batch batch);
// Check if there are batches left to solve
bool hasUnsolvedBatches();
// TODO: Needs implementation
void updateBatch_failure(Batch failed_batch);
std::string getAllBatchInfoString();
double getTotalReadTime();
double getTotalWriteTime();
/**
* A client has found to be disconnected. Unassign all batches
* that were assigned to the disconnected client. The client id
* is passed in as a parameter
*/
void updatedBatch_disconnectedClient(int client_id);
/**
* Create the csv file for the completed batches.
*/
void inititalizeCSVOutput(std::string csv_output_name);
/**
* @brief Print the batches from the batch list
*
*/
void printBatches();
std::string getBatchesAsString();
/**
* @brief Find the batch with the batch_id parameter
* update the batches assigned actor member variable to false
*
*/
void updateBatchStatus_LostClient(int batch_id);
template <class Inspector>
friend bool inspect(Inspector& inspector, Batch_Container& batch_container) {
return inspector.object(batch_container).fields(
inspector.field("total_hru_count", batch_container.total_hru_count_),
inspector.field("num_hru_per_batch", batch_container.num_hru_per_batch_),
inspector.field("batches_remaining", batch_container.batches_remaining_),
inspector.field("batch_list", batch_container.batch_list_));
}
};
\ No newline at end of file
#pragma once
#include "caf/all.hpp"
#include <vector>
#include <string>
enum batch_status {
unassigned,
assigned,
solved,
failed
};
class Batch {
private:
int batch_id;
int start_hru;
int num_hru;
double run_time;
double read_time;
double write_time;
std::string assigned_host;
caf::actor assigned_actor;
batch_status status;
public:
Batch(int batch_id, int start_hru, int num_hru);
void printBatchInfo();
batch_status getBatchStatus();
int getBatchID();
int getStartHRU();
int getNumHRU();
void solvedBatch(double run_time, double read_time, double write_time);
void assignedBatch(std::string hostname, caf::actor actor_ref);
void updateRunTime(double run_time);
void writeBatchToFile(std::string file_name);
};
class Batch_Manager {
private:
std::vector<Batch> batch_list;
std::vector<Batch> solved_batches;
std::vector<Batch> failed_batches;
public:
};
\ No newline at end of file
#pragma once
#include "caf/all.hpp"
#include "batch_manager.hpp"
#include <optional>
#include "batch.hpp"
class Client {
private:
int id;
int batches_solved;
bool connected;
caf::actor client_actor;
std::string hostname;
Batch* current_batch;
int id;
int batches_solved;
std::optional<Batch> current_batch;
public:
Client(int id, caf::actor client_actor, std::string hostname);
Client(int id = -1, caf::actor client_actor = nullptr, std::string hostname = "");
// ####################################################################
// Getters
// ####################################################################
caf::actor getActor();
int getID();
std::string getHostname();
std::optional<Batch> getBatch();
// ####################################################################
// Setters
// ####################################################################
void setBatch(std::optional<Batch> batch);
// ####################################################################
// Methods
// ####################################################################
std::string toString();
// Serialization so CAF can send an object of this class to another actor
template <class Inspector>
friend bool inspect(Inspector& inspector, Client& client) {
return inspector.object(client).fields(
inspector.field("client_actor",client.client_actor),
inspector.field("hostname",client.hostname),
inspector.field("id",client.id),
inspector.field("batches_solved",client.batches_solved),
inspector.field("current_batch",client.current_batch));
}
};
\ No newline at end of file
#pragma once
#include "caf/all.hpp"
#include <vector>
#include "batch.hpp"
#include "client.hpp"
#include <optional>
class Client_Container {
private:
std::vector<Client> client_list;
int id_counter;
public:
Client_Container();
// ####################################################################
// Getters
// ####################################################################
int getNumClients();
std::vector<Client> getClientList();
std::optional<Client> getClient(caf::actor_addr client_ref);
// ####################################################################
// Setters
// ####################################################################
void setBatchForClient(caf::actor client_ref, std::optional<Batch> batch);
// ####################################################################
// Methods
// ####################################################################
// add a new client to the client_list
void addClient(caf::actor client_actor, std::string hostname);
// remove a client from the client_list
void removeClient(Client client);
// return a client that is not solving a batch or return an empty optional
std::optional<Client> getIdleClient();
// Check if the client list is empty
bool isEmpty();
// pops client at the end of the list
Client removeClient_fromBack();
// return printable string
std::string toString();
template <class Inspector>
friend bool inspect(Inspector& inspector, Client_Container& client_container) {
return inspector.object(client_container).fields(
inspector.field("client_list", client_container.client_list),
inspector.field("id_counter", client_container.id_counter));
}
};
......@@ -3,7 +3,8 @@
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "timing_info.hpp"
#include "settings_functions.hpp"
#include "batch_container.hpp"
#include <chrono>
#include <string>
#include <vector>
......@@ -25,20 +26,30 @@ struct summa_actor_state {
// Program Parameters
int startGRU; // starting GRU for the simulation
int numGRU; // number of GRUs to compute
std::string configPath;// path to the fileManager.txt file
// Information about the jobs
int fileGRU; // number of GRUs in the file
std::string configPath; // path to the fileManager.txt file
int numFailed = 0; // Number of jobs that have failed
// 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
caf::actor parent;
// Batches
Batch_Container batch_container;
int current_batch_id;
// settings for all child actors (save in case we need to recover)
Summa_Actor_Settings summa_actor_settings;
File_Access_Actor_Settings file_access_actor_settings;
Job_Actor_Settings job_actor_settings;
HRU_Actor_Settings hru_actor_settings;
};
behavior summa_actor(stateful_actor<summa_actor_state>* self, int startGRU, int numGRU, std::string configPath, actor parent);
behavior summa_actor(stateful_actor<summa_actor_state>* self,
int startGRU, int numGRU,
Summa_Actor_Settings summa_actor_settings,
File_Access_Actor_Settings file_access_actor_settings,
Job_Actor_Settings job_actor_settings,
HRU_Actor_Settings hru_actor_settings, actor parent);
void spawnJob(stateful_actor<summa_actor_state>* self);
......
#pragma once
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "summa_server.hpp"
#include <string>
#include <unistd.h>
#include <limits.h>
namespace caf {
// Inital behaviour that waits to connect to the lead server
behavior summa_backup_server_init(stateful_actor<summa_server_state>* self, Distributed_Settings distributed_settings,
Summa_Actor_Settings summa_actor_settings, File_Access_Actor_Settings file_access_actor_settings,
Job_Actor_Settings job_actor_settings, HRU_Actor_Settings hru_actor_settings);
// Function that is called ot connect to the lead server
void connecting_backup(stateful_actor<summa_server_state>* self, const std::string& host, uint16_t port);
behavior summa_backup_server(stateful_actor<summa_server_state>* self, const actor& server_actor);
}
\ No newline at end of file
......@@ -2,23 +2,48 @@
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "settings_functions.hpp"
#include "batch.hpp"
#include "summa_actor.hpp"
#include "message_atoms.hpp"
#include <string>
#include <optional>
#include <unistd.h>
#include <limits.h>
namespace caf {
struct summa_client_state {
strong_actor_ptr current_server;
strong_actor_ptr current_server = nullptr;
actor current_server_actor;
std::vector<strong_actor_ptr> servers;
std::string hostname;
std::optional<std::string> config_path;
actor summa_actor_ref;
uint16_t port;
int batch_id;
int client_id; // id held by server
bool running = false; // initalized to false - flipped to true when client returns behavior summa_client
// tuple is the actor ref and hostname of the backup server
std::vector<std::tuple<caf::actor, std::string>> backup_servers_list;
Batch current_batch;
bool saved_batch = false;
Summa_Actor_Settings summa_actor_settings;
File_Access_Actor_Settings file_access_actor_settings;
Job_Actor_Settings job_actor_settings;
HRU_Actor_Settings hru_actor_settings;
};
behavior summa_client(stateful_actor<summa_client_state>* self, std::optional<std::string> config_path);
behavior unconnected(stateful_actor<summa_client_state>*);
behavior summa_client_init(stateful_actor<summa_client_state>* self);
behavior summa_client(stateful_actor<summa_client_state>* self);
void connecting(stateful_actor<summa_client_state>*, const std::string& host, uint16_t port);
behavior running(stateful_actor<summa_client_state>*, const actor& summa_server);
void findLeadServer(stateful_actor<summa_client_state>* self, strong_actor_ptr serv);
}
\ No newline at end of file
......@@ -2,29 +2,86 @@
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "batch_manager.hpp"
#include "batch.hpp"
#include "batch_container.hpp"
#include "client.hpp"
#include "client_container.hpp"
#include "settings_functions.hpp"
#include "global.hpp"
#include "message_atoms.hpp"
#include <string>
#include <optional>
#include <thread>
#include <chrono>
#include <iostream>
namespace caf {
struct summa_server_state {
int total_hru_count;
int num_clients;
int num_hru_per_batch;
int batches_remaining = 0;
int batches_solved = 0;
std::string config_path;
std::vector<Batch> batch_list;
std::vector<Batch> solved_batches;
std::vector<Batch> failed_batches;
std::vector<Client> client_list;
std::string csv_output_name;
strong_actor_ptr current_server; // if server is a backup then this will be set to the lead server
actor current_server_actor;
std::string hostname;
std::string csv_file_path;
std::string csv_output_name = "/batch_results.csv";
Client_Container client_container;
Batch_Container batch_container;
// Actor Reference, Hostname
std::vector<std::tuple<caf::actor, std::string>> backup_servers_list;
// Settings Structures
Distributed_Settings distributed_settings;
Summa_Actor_Settings summa_actor_settings;
File_Access_Actor_Settings file_access_actor_settings;
Job_Actor_Settings job_actor_settings;
HRU_Actor_Settings hru_actor_settings;
};
behavior summa_server(stateful_actor<summa_server_state>* self, std::string config_path);
int assembleBatches(stateful_actor<summa_server_state>* self);
std::optional<int> getUnsolvedBatchID(stateful_actor<summa_server_state>* self);
}
\ No newline at end of file
// Summa Server setup behaviour - initializes the state for the server
behavior summa_server_init(stateful_actor<summa_server_state>* self,
Distributed_Settings distributed_settings,
Summa_Actor_Settings summa_actor_settings,
File_Access_Actor_Settings file_access_actor_settings,
Job_Actor_Settings job_actor_settings,
HRU_Actor_Settings hru_actor_settings);
// Summa Server behaviour - handles messages from clients
behavior summa_server(stateful_actor<summa_server_state>* self);
// Summa Server backup behaviour - handles the exit messages for clients
behavior summa_server_exit(stateful_actor<summa_server_state>* self);
// Creates the csv file that holds the results of the batches
void initializeCSVOutput(std::string csv_output_path);
// Send all connected actors the updated backup servers list
void sendAllBackupServersList(stateful_actor<summa_server_state>* self);
// Look for the lost backup server in the backup servers list and remove it
void findAndRemoveLostBackupServer(stateful_actor<summa_server_state>* self, actor_addr lost_backup_server);
// Check for an idle client to send the failed or next batch we find that is not assigned
void checkForIdleClients(stateful_actor<summa_server_state>* self);
void notifyBackupServersOfRemovedClient(stateful_actor<summa_server_state>* self, Client client);
// Finds the batch the lost client was working on and reassigns it to another client if available
// If no client is available then the batch is added back to the list to be reassigned later
void resolveLostClient(stateful_actor<summa_server_state>* self, Client client);
// Removes the backup server from the list of backup servers
// All connected actors are then notified of the change
void resolveLostBackupServer(stateful_actor<summa_server_state>* self, const down_msg& dm);
// Convience function to keep code clean - just does what you think it does
void printRemainingBatches(stateful_actor<summa_server_state>* self);
} // namespace caf
#!/bin/bash
#############
## File in the path that SUMMA-Actors top level directory is located in
###############
SUMMA_ACTORS=/home/kklenk/Summa-Projects/Summa-Actors # top level directory
apptainer exec --bind $SUMMA_ACTORS:/Summa-Actors summa_actors.sif /Summa-Actors/build/build_summa_actors_container.sh
\ No newline at end of file
#### parent directory of the 'build' directory ####
ROOT_DIR = /Summa-Actors
#### Compilers ####
FC = gfortran # Fortran
CC = g++ # C++
#### Includes AND Libraries ####
INCLUDES = -I/usr/include -I/usr/local/include
LIBRARIES = -L/usr/lib -L/usr/local/lib -lnetcdff -lopenblas
ACTORS_INCLUDES = -I/usr/include -I/usr/local/include
ACTORS_LIBRARIES = -L/usr/lib -L/usr/local/lib -L/Summa-Actors/bin -lcaf_core -lcaf_io -lsumma -lopenblas -lnetcdff
# Production runs
FLAGS_NOAH = -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_COMM = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_SUMMA = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_ACTORS = -O3 -Wfatal-errors -std=c++17
# Debug runs
# FLAGS_NOAH = -g -O0 -ffree-form -ffree-line-length-none -fmax-errors=0 -fbacktrace -Wno-unused -Wno-unused-dummy-argument -fPIC
# FLAGS_COMM = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC
# FLAGS_SUMMA = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC
# FLAGS_ACTORS = -g -O0 -Wall -std=c++17
#========================================================================
# PART 1: Define directory paths
#========================================================================
# Core directory that contains source code
F_KORE_DIR = $(ROOT_DIR)/build/source
# Location of the compiled modules
MOD_PATH = $(ROOT_DIR)/build
# Define the directory for the executables
EXE_PATH = $(ROOT_DIR)/bin
####################################################################################################
###################################### Assemble Fortran Files ######################################
####################################################################################################
# Define directories
DRIVER_DIR = $(F_KORE_DIR)/driver
HOOKUP_DIR = $(F_KORE_DIR)/hookup
NETCDF_DIR = $(F_KORE_DIR)/netcdf
DSHARE_DIR = $(F_KORE_DIR)/dshare
NUMREC_DIR = $(F_KORE_DIR)/numrec
NOAHMP_DIR = $(F_KORE_DIR)/noah-mp
ENGINE_DIR = $(F_KORE_DIR)/engine
ACTORS_DIR = $(F_KORE_DIR)/actors
JOB_ACTOR_DIR = $(ACTORS_DIR)/job_actor
FILE_ACCESS_DIR = $(ACTORS_DIR)/file_access_actor
HRU_ACTOR_DIR = $(ACTORS_DIR)/hru_actor
# utilities
SUMMA_NRUTIL= \
nrtype.f90 \
f2008funcs.f90 \
nr_utility.f90
NRUTIL = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_NRUTIL))
# Numerical recipes procedures
# NOTE: all numerical recipes procedures are now replaced with free versions
SUMMA_NRPROC= \
expIntegral.f90 \
spline_int.f90
NRPROC = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_NRPROC))
# Hook-up modules (set files and directory paths)
SUMMA_HOOKUP= \
ascii_util.f90 \
summaActors_FileManager.f90
HOOKUP = $(patsubst %, $(HOOKUP_DIR)/%, $(SUMMA_HOOKUP))
# Data modules
SUMMA_DATAMS= \
multiconst.f90 \
var_lookup.f90 \
data_types.f90 \
globalData.f90 \
flxMapping.f90 \
get_ixname.f90 \
popMetadat.f90 \
outpt_stat.f90
DATAMS = $(patsubst %, $(DSHARE_DIR)/%, $(SUMMA_DATAMS))
# utility modules
SUMMA_UTILMS= \
time_utils.f90 \
mDecisions.f90 \
snow_utils.f90 \
soil_utils.f90 \
updatState.f90 \
matrixOper.f90
UTILMS = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_UTILMS))
# Model guts
SUMMA_MODGUT= \
MODGUT = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_MODGUT))
# Solver
SUMMA_SOLVER= \
vegPhenlgy.f90 \
diagn_evar.f90 \
stomResist.f90 \
groundwatr.f90 \
vegSWavRad.f90 \
vegNrgFlux.f90 \
ssdNrgFlux.f90 \
vegLiqFlux.f90 \
snowLiqFlx.f90 \
soilLiqFlx.f90 \
bigAquifer.f90 \
computFlux.f90 \
computResid.f90 \
computJacob.f90 \
eval8summa.f90 \
summaSolve.f90 \
systemSolv.f90 \
varSubstep.f90 \
opSplittin.f90 \
coupled_em.f90
SOLVER = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_SOLVER))
# Interface code for Fortran-C++
SUMMA_INTERFACE= \
cppwrap_datatypes.f90 \
cppwrap_auxiliary.f90 \
cppwrap_metadata.f90 \
INTERFACE = $(patsubst %, $(ACTORS_DIR)/global/%, $(SUMMA_INTERFACE))
SUMMA_FILEACCESS_INTERFACE = \
initOutputStruc.f90 \
deallocateOutputStruc.f90 \
cppwrap_fileAccess.f90
FILEACCESS_INTERFACE = $(patsubst %, $(FILE_ACCESS_DIR)/%, $(SUMMA_FILEACCESS_INTERFACE))
SUMMA_JOB_INTERFACE = \
cppwrap_job.f90
JOB_INTERFACE = $(patsubst %, $(JOB_ACTOR_DIR)/%, $(SUMMA_JOB_INTERFACE))
SUMMA_HRU_INTERFACE = \
cppwrap_hru.f90
HRU_INTERFACE = $(patsubst %, $(HRU_ACTOR_DIR)/%, $(SUMMA_HRU_INTERFACE))
# Define routines for SUMMA preliminaries
SUMMA_PRELIM= \
conv_funcs.f90 \
sunGeomtry.f90 \
convE2Temp.f90 \
allocspaceActors.f90 \
alloc_file_access.f90\
checkStruc.f90 \
childStruc.f90 \
ffile_info.f90 \
read_attribute.f90 \
read_pinit.f90 \
pOverwrite.f90 \
read_paramActors.f90 \
paramCheck.f90 \
check_icondActors.f90 \
# allocspace.f90
PRELIM = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_PRELIM))
SUMMA_NOAHMP= \
module_model_constants.F \
module_sf_noahutl.F \
module_sf_noahlsm.F \
module_sf_noahmplsm.F
NOAHMP = $(patsubst %, $(NOAHMP_DIR)/%, $(SUMMA_NOAHMP))
# Define routines for the SUMMA model runs
SUMMA_MODRUN = \
indexState.f90 \
getVectorz.f90 \
updateVars.f90 \
var_derive.f90 \
read_forcingActors.f90 \
access_forcing.f90\
access_write.f90 \
derivforce.f90 \
snowAlbedo.f90 \
canopySnow.f90 \
tempAdjust.f90 \
snwCompact.f90 \
layerMerge.f90 \
layerDivide.f90 \
volicePack.f90 \
qTimeDelay.f90
MODRUN = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_MODRUN))
# Define NetCDF routines
# OutputStrucWrite is not a netcdf subroutine and should be
# moved
SUMMA_NETCDF = \
netcdf_util.f90 \
def_output.f90 \
outputStrucWrite.f90 \
writeOutput.f90 \
read_icondActors.f90
NETCDF = $(patsubst %, $(NETCDF_DIR)/%, $(SUMMA_NETCDF))
# ... stitch together common programs
COMM_ALL = $(NRUTIL) $(NRPROC) $(HOOKUP) $(DATAMS) $(UTILMS)
# ... stitch together SUMMA programs
SUMMA_ALL = $(NETCDF) $(PRELIM) $(MODRUN) $(SOLVER)
# Define the driver routine
SUMMA_DRIVER= \
summaActors_type.f90 \
summaActors_util.f90 \
summaActors_globalData.f90 \
summaActors_init.f90 \
SummaActors_setup.f90 \
summaActors_restart.f90 \
summaActors_forcing.f90 \
SummaActors_modelRun.f90 \
summaActors_alarms.f90 \
summaActors_wOutputStruc.f90
DRIVER = $(patsubst %, $(DRIVER_DIR)/%, $(SUMMA_DRIVER))
####################################################################################################
###################################### Assemble Fortran Files ######################################
####################################################################################################
####################################################################################################
######################################## Assemble C++ Files ########################################
####################################################################################################
INCLUDE_DIR = /Summa-Actors/build/includes
SOURCE_DIR = /Summa-Actors/build/source/actors
GLOBAL_INCLUDES = -I$(INCLUDE_DIR)/global
GLOBAL = $(SOURCE_DIR)/global/global.cpp
TIMEINFO = $(SOURCE_DIR)/global/timing_info.cpp
SUMMA_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/summa_actor
SUMMA_ACTOR = $(SOURCE_DIR)/summa_actor/summa_actor.cpp
SUMMA_CLIENT = $(SOURCE_DIR)/summa_actor/summa_client.cpp
SUMMA_SERVER = $(SOURCE_DIR)/summa_actor/summa_server.cpp
BATCH_MANGER = $(SOURCE_DIR)/summa_actor/batch_manager.cpp
CLIENT_MANAGER = $(SOURCE_DIR)/summa_actor/client.cpp
JOB_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/job_actor
JOB_ACTOR = $(SOURCE_DIR)/job_actor/job_actor.cpp
GRUinfo = $(SOURCE_DIR)/job_actor/GRUinfo.cpp
FILE_ACCESS_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/file_access_actor
FILE_ACCESS_ACTOR = $(SOURCE_DIR)/file_access_actor/file_access_actor.cpp
FORCING_FILE_INFO = $(SOURCE_DIR)/file_access_actor/forcing_file_info.cpp
OUTPUT_MANAGER = $(SOURCE_DIR)/file_access_actor/output_manager.cpp
HRU_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/hru_actor
HRU_ACTOR = $(SOURCE_DIR)/hru_actor/hru_actor.cpp
MAIN = $(F_KORE_DIR)/actors/main.cpp
ACTOR_TEST = $(F_KORE_DIR)/testing/testing_main.cc
####################################################################################################
######################################## Assemble C++ Files ########################################
####################################################################################################
#========================================================================
# PART 3: compilation
#======================================================================
all: fortran cpp
fortran: compile_noah compile_comm compile_summa link clean_fortran
cpp: compile_globals compile_hru_actor compile_file_access_actor compile_job_actor compile_summa_actor \
compile_summa_client compile_summa_server compile_main link_cpp clean_cpp
test: actors_test actors_testLink actorsClean
###################################################################################################################
############################################## COMPILE SUMMA-Fortran ##############################################
###################################################################################################################
compile_noah:
$(FC) $(FLAGS_NOAH) -c $(NRUTIL) $(NOAHMP)
# compile common routines
compile_comm:
$(FC) $(FLAGS_COMM) -c $(COMM_ALL) $(INCLUDES)
# compile SUMMA routines
compile_summa:
$(FC) $(FLAGS_SUMMA) -c $(SUMMA_ALL) $(DRIVER) $(INTERFACE) $(JOB_INTERFACE) $(FILEACCESS_INTERFACE) $(HRU_INTERFACE) $(INCLUDES)
# generate library
link:
$(FC) -shared *.o -o libsumma.so
mv libsumma.so $(ROOT_DIR)/bin
# Remove object files
clean_fortran:
rm -f *.o *.mod soil_veg_gen_parm__genmod.f90
###################################################################################################################
############################################## COMPILE SUMMA-Fortran ##############################################
###################################################################################################################
###################################################################################################################
################################################ COMPILE SUMMA-C++ ################################################
###################################################################################################################
compile_globals:
$(CC) $(FLAGS_ACTORS) -c $(GLOBAL) $(TIMEINFO) $(GLOBAL_INCLUDES)
compile_hru_actor:
$(CC) $(FLAGS_ACTORS) -c $(HRU_ACTOR) $(HRU_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES)
compile_file_access_actor:
$(CC) $(FLAGS_ACTORS) -c $(FILE_ACCESS_ACTOR) $(FORCING_FILE_INFO) $(OUTPUT_MANAGER) \
$(FILE_ACCESS_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES)
compile_job_actor:
$(CC) $(FLAGS_ACTORS) -c $(JOB_ACTOR) $(GRUinfo) $(JOB_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES) \
$(FILE_ACCESS_ACTOR_INCLUDES) $(HRU_ACTOR_INCLUDES)
compile_summa_actor:
$(CC) $(FLAGS_ACTORS) -c $(SUMMA_ACTOR) $(SUMMA_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES) \
$(JOB_ACTOR_INCLUDES)
compile_summa_client:
$(CC) $(FLAGS_ACTORS) -c $(SUMMA_CLIENT) $(SUMMA_ACTOR_INCLUDES) $(GLOBAL_INCLUDES)
compile_summa_server:
$(CC) $(FLAGS_ACTORS) -c $(SUMMA_SERVER) $(BATCH_MANGER) $(CLIENT_MANAGER) $(SUMMA_ACTOR_INCLUDES) $(GLOBAL_INCLUDES)
compile_main:
$(CC) $(FLAGS_ACTORS) -c $(MAIN) $(GLOBAL_INCLUDES) $(SUMMA_ACTOR_INCLUDES) $(JOB_ACTOR_INCLUDES)
link_cpp:
$(CC) $(FLAGS_ACTORS) -o summaMain *.o $(ACTORS_LIBRARIES)
mv summaMain $(ROOT_DIR)/bin
clean_cpp:
rm *.o
###################################################################################################################
################################################ COMPILE SUMMA-C++ ################################################
###################################################################################################################
###################################################################################################################
################################################## COMPILE TESTS ##################################################
###################################################################################################################
actors_test:
$(CC) $(FLAGS_ACTORS) -c $(ACTOR_TEST) -std=c++17 $(ACTORS_INCLUDES)
actors_testLink:
$(CC) -o summaTest *.o $(ACTORS_LIBRARIES)
clean_lib:
rm *.so
#### parent directory of the 'build' directory ####
ROOT_DIR = /Summa-Actors
#### Compilers ####
FC = gfortran # Fortran
CC = g++ # C++
#### Includes AND Libraries ####
INCLUDES = -I/usr/include -I/usr/local/include
LIBRARIES = -L/usr/local/lib -lnetcdff -lopenblas
ACTORS_INCLUDES = -I/usr/local/include -I/usr/local/include
ACTORS_LIBRARIES = -L/usr/local/lib -L$(ROOT_DIR)/bin -lcaf_core -lcaf_io -lsumma -lopenblas -lnetcdff
# Production runs
FLAGS_NOAH = -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_COMM = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_SUMMA = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_ACTORS = -O3 -Wfatal-errors -std=c++17
# # Debug runs
# FLAGS_NOAH = -g -O0 -ffree-form -ffree-line-length-none -fmax-errors=0 -fbacktrace -Wno-unused -Wno-unused-dummy-argument -fPIC
# FLAGS_COMM = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC
# FLAGS_SUMMA = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC
# FLAGS_ACTORS = -g -O0 -Wall -std=c++17
#========================================================================
# PART 1: Define directory paths
#========================================================================
# Core directory that contains source code
F_KORE_DIR = $(ROOT_DIR)/build/source
# Location of the compiled modules
MOD_PATH = $(ROOT_DIR)/build
# Define the directory for the executables
EXE_PATH = $(ROOT_DIR)/bin
####################################################################################################
###################################### Assemble Fortran Files ######################################
####################################################################################################
# Define directories
DRIVER_DIR = $(F_KORE_DIR)/driver
HOOKUP_DIR = $(F_KORE_DIR)/hookup
NETCDF_DIR = $(F_KORE_DIR)/netcdf
DSHARE_DIR = $(F_KORE_DIR)/dshare
NUMREC_DIR = $(F_KORE_DIR)/numrec
NOAHMP_DIR = $(F_KORE_DIR)/noah-mp
ENGINE_DIR = $(F_KORE_DIR)/engine
ACTORS_DIR = $(F_KORE_DIR)/actors
JOB_ACTOR_DIR = $(ACTORS_DIR)/job_actor
FILE_ACCESS_DIR = $(ACTORS_DIR)/file_access_actor
HRU_ACTOR_DIR = $(ACTORS_DIR)/hru_actor
# utilities
SUMMA_NRUTIL= \
nrtype.f90 \
f2008funcs.f90 \
nr_utility.f90
NRUTIL = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_NRUTIL))
# Numerical recipes procedures
# NOTE: all numerical recipes procedures are now replaced with free versions
SUMMA_NRPROC= \
expIntegral.f90 \
spline_int.f90
NRPROC = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_NRPROC))
# Hook-up modules (set files and directory paths)
SUMMA_HOOKUP= \
ascii_util.f90 \
summaActors_FileManager.f90
HOOKUP = $(patsubst %, $(HOOKUP_DIR)/%, $(SUMMA_HOOKUP))
# Data modules
SUMMA_DATAMS= \
multiconst.f90 \
var_lookup.f90 \
data_types.f90 \
globalData.f90 \
flxMapping.f90 \
get_ixname.f90 \
popMetadat.f90 \
outpt_stat.f90
DATAMS = $(patsubst %, $(DSHARE_DIR)/%, $(SUMMA_DATAMS))
# utility modules
SUMMA_UTILMS= \
time_utils.f90 \
mDecisions.f90 \
snow_utils.f90 \
soil_utils.f90 \
updatState.f90 \
matrixOper.f90
UTILMS = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_UTILMS))
# Model guts
SUMMA_MODGUT= \
MODGUT = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_MODGUT))
# Solver
SUMMA_SOLVER= \
vegPhenlgy.f90 \
diagn_evar.f90 \
stomResist.f90 \
groundwatr.f90 \
vegSWavRad.f90 \
vegNrgFlux.f90 \
ssdNrgFlux.f90 \
vegLiqFlux.f90 \
snowLiqFlx.f90 \
soilLiqFlx.f90 \
bigAquifer.f90 \
computFlux.f90 \
computResid.f90 \
computJacob.f90 \
eval8summa.f90 \
summaSolve.f90 \
systemSolv.f90 \
varSubstep.f90 \
opSplittin.f90 \
coupled_em.f90
SOLVER = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_SOLVER))
# Interface code for Fortran-C++
SUMMA_INTERFACE= \
cppwrap_datatypes.f90 \
cppwrap_auxiliary.f90 \
cppwrap_metadata.f90 \
INTERFACE = $(patsubst %, $(ACTORS_DIR)/global/%, $(SUMMA_INTERFACE))
SUMMA_FILEACCESS_INTERFACE = \
initOutputStruc.f90 \
deallocateOutputStruc.f90 \
cppwrap_fileAccess.f90
FILEACCESS_INTERFACE = $(patsubst %, $(FILE_ACCESS_DIR)/%, $(SUMMA_FILEACCESS_INTERFACE))
SUMMA_JOB_INTERFACE = \
cppwrap_job.f90
JOB_INTERFACE = $(patsubst %, $(JOB_ACTOR_DIR)/%, $(SUMMA_JOB_INTERFACE))
SUMMA_HRU_INTERFACE = \
cppwrap_hru.f90
HRU_INTERFACE = $(patsubst %, $(HRU_ACTOR_DIR)/%, $(SUMMA_HRU_INTERFACE))
# Define routines for SUMMA preliminaries
SUMMA_PRELIM= \
conv_funcs.f90 \
sunGeomtry.f90 \
convE2Temp.f90 \
allocspaceActors.f90 \
alloc_file_access.f90\
checkStruc.f90 \
childStruc.f90 \
ffile_info.f90 \
read_attribute.f90 \
read_pinit.f90 \
pOverwrite.f90 \
read_paramActors.f90 \
paramCheck.f90 \
check_icondActors.f90 \
# allocspace.f90
PRELIM = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_PRELIM))
SUMMA_NOAHMP= \
module_model_constants.F \
module_sf_noahutl.F \
module_sf_noahlsm.F \
module_sf_noahmplsm.F
NOAHMP = $(patsubst %, $(NOAHMP_DIR)/%, $(SUMMA_NOAHMP))
# Define routines for the SUMMA model runs
SUMMA_MODRUN = \
indexState.f90 \
getVectorz.f90 \
updateVars.f90 \
var_derive.f90 \
read_forcingActors.f90 \
access_forcing.f90\
access_write.f90 \
derivforce.f90 \
snowAlbedo.f90 \
canopySnow.f90 \
tempAdjust.f90 \
snwCompact.f90 \
layerMerge.f90 \
layerDivide.f90 \
volicePack.f90 \
qTimeDelay.f90
MODRUN = $(patsubst %, $(ENGINE_DIR)/%, $(SUMMA_MODRUN))
# Define NetCDF routines
# OutputStrucWrite is not a netcdf subroutine and should be
# moved
SUMMA_NETCDF = \
netcdf_util.f90 \
def_output.f90 \
outputStrucWrite.f90 \
writeOutput.f90 \
read_icondActors.f90
NETCDF = $(patsubst %, $(NETCDF_DIR)/%, $(SUMMA_NETCDF))
# ... stitch together common programs
COMM_ALL = $(NRUTIL) $(NRPROC) $(HOOKUP) $(DATAMS) $(UTILMS)
# ... stitch together SUMMA programs
SUMMA_ALL = $(NETCDF) $(PRELIM) $(MODRUN) $(SOLVER)
# Define the driver routine
SUMMA_DRIVER= \
summaActors_type.f90 \
summaActors_util.f90 \
summaActors_globalData.f90 \
summaActors_init.f90 \
SummaActors_setup.f90 \
summaActors_restart.f90 \
summaActors_forcing.f90 \
SummaActors_modelRun.f90 \
summaActors_alarms.f90 \
summaActors_wOutputStruc.f90
DRIVER = $(patsubst %, $(DRIVER_DIR)/%, $(SUMMA_DRIVER))
####################################################################################################
###################################### Assemble Fortran Files ######################################
####################################################################################################
####################################################################################################
######################################## Assemble C++ Files ########################################
####################################################################################################
INCLUDE_DIR = $(ROOT_DIR)/build/includes
SOURCE_DIR = $(ROOT_DIR)/build/source/actors
GLOBAL_INCLUDES = -I$(INCLUDE_DIR)/global
GLOBAL = $(SOURCE_DIR)/global/global.cpp
TIMEINFO = $(SOURCE_DIR)/global/timing_info.cpp
SUMMA_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/summa_actor
SUMMA_ACTOR = $(SOURCE_DIR)/summa_actor/summa_actor.cpp
SUMMA_CLIENT = $(SOURCE_DIR)/summa_actor/summa_client.cpp
SUMMA_SERVER = $(SOURCE_DIR)/summa_actor/summa_server.cpp
BATCH_MANGER = $(SOURCE_DIR)/summa_actor/batch_manager.cpp
CLIENT_MANAGER = $(SOURCE_DIR)/summa_actor/client.cpp
JOB_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/job_actor
JOB_ACTOR = $(SOURCE_DIR)/job_actor/job_actor.cpp
GRUinfo = $(SOURCE_DIR)/job_actor/GRUinfo.cpp
FILE_ACCESS_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/file_access_actor
FILE_ACCESS_ACTOR = $(SOURCE_DIR)/file_access_actor/file_access_actor.cpp
FORCING_FILE_INFO = $(SOURCE_DIR)/file_access_actor/forcing_file_info.cpp
OUTPUT_MANAGER = $(SOURCE_DIR)/file_access_actor/output_manager.cpp
HRU_ACTOR_INCLUDES = -I$(INCLUDE_DIR)/hru_actor
HRU_ACTOR = $(SOURCE_DIR)/hru_actor/hru_actor.cpp
MAIN = $(F_KORE_DIR)/actors/main.cpp
ACTOR_TEST = $(F_KORE_DIR)/testing/testing_main.cc
####################################################################################################
######################################## Assemble C++ Files ########################################
####################################################################################################
#========================================================================
# PART 3: compilation
#======================================================================
all: fortran cpp
fortran: compile_noah compile_comm compile_summa link clean_fortran
cpp: compile_globals compile_hru_actor compile_file_access_actor compile_job_actor compile_summa_actor \
compile_summa_client compile_summa_server compile_main link_cpp clean_cpp
test: actors_test actors_testLink actorsClean
###################################################################################################################
############################################## COMPILE SUMMA-Fortran ##############################################
###################################################################################################################
compile_noah:
$(FC) $(FLAGS_NOAH) -c $(NRUTIL) $(NOAHMP)
# compile common routines
compile_comm:
$(FC) $(FLAGS_COMM) -c $(COMM_ALL) $(INTERFACE) $(INCLUDES)
# compile SUMMA routines
compile_summa:
$(FC) $(FLAGS_SUMMA) -c $(SUMMA_ALL) $(DRIVER) $(JOB_INTERFACE) $(FILEACCESS_INTERFACE) $(HRU_INTERFACE) $(INCLUDES)
# generate library
link:
$(FC) -shared *.o -o libsumma.so
mv libsumma.so $(ROOT_DIR)/bin
# Remove object files
clean_fortran:
rm -f *.o *.mod soil_veg_gen_parm__genmod.f90
###################################################################################################################
############################################## COMPILE SUMMA-Fortran ##############################################
###################################################################################################################
###################################################################################################################
################################################ COMPILE SUMMA-C++ ################################################
###################################################################################################################
compile_globals:
$(CC) $(FLAGS_ACTORS) -c $(GLOBAL) $(TIMEINFO) $(GLOBAL_INCLUDES)
compile_hru_actor:
$(CC) $(FLAGS_ACTORS) -c $(HRU_ACTOR) $(HRU_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES)
compile_file_access_actor:
$(CC) $(FLAGS_ACTORS) -c $(FILE_ACCESS_ACTOR) $(FORCING_FILE_INFO) $(OUTPUT_MANAGER) \
$(FILE_ACCESS_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES)
compile_job_actor:
$(CC) $(FLAGS_ACTORS) -c $(JOB_ACTOR) $(GRUinfo) $(JOB_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES) \
$(FILE_ACCESS_ACTOR_INCLUDES) $(HRU_ACTOR_INCLUDES)
compile_summa_actor:
$(CC) $(FLAGS_ACTORS) -c $(SUMMA_ACTOR) $(SUMMA_ACTOR_INCLUDES) $(GLOBAL_INCLUDES) $(ACTORS_INCLUDES) \
$(JOB_ACTOR_INCLUDES)
compile_summa_client:
$(CC) $(FLAGS_ACTORS) -c $(SUMMA_CLIENT) $(SUMMA_ACTOR_INCLUDES) $(GLOBAL_INCLUDES)
compile_summa_server:
$(CC) $(FLAGS_ACTORS) -c $(SUMMA_SERVER) $(BATCH_MANGER) $(CLIENT_MANAGER) $(SUMMA_ACTOR_INCLUDES) $(GLOBAL_INCLUDES)
compile_main:
$(CC) $(FLAGS_ACTORS) -c $(MAIN) $(GLOBAL_INCLUDES) $(SUMMA_ACTOR_INCLUDES) $(JOB_ACTOR_INCLUDES)
link_cpp:
$(CC) $(FLAGS_ACTORS) -o summaMain *.o $(ACTORS_LIBRARIES)
mv summaMain $(ROOT_DIR)/bin
clean_cpp:
rm *.o
###################################################################################################################
################################################ COMPILE SUMMA-C++ ################################################
###################################################################################################################
###################################################################################################################
################################################## COMPILE TESTS ##################################################
###################################################################################################################
actors_test:
$(CC) $(FLAGS_ACTORS) -c $(ACTOR_TEST) -std=c++17 $(ACTORS_INCLUDES)
actors_testLink:
$(CC) -o summaTest *.o $(ACTORS_LIBRARIES)
clean_lib:
rm *.so