Skip to content

Commit

Permalink
Merge branch 'master' into simgrid_master
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Nov 18, 2023
2 parents bca09b3 + 6c7f109 commit 3dd6886
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 10 deletions.
53 changes: 53 additions & 0 deletions include/wrench/tools/wfcommons/WfCommonsWorkflowParser.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,59 @@ namespace wrench {
bool enforce_num_cores = false,
bool ignore_avg_cpu = false,
bool show_warnings = false);


/**
* @brief Create an abstract workflow based on a JSON file in the WfFormat (version 1.4) from WfCommons. This method
* makes executive decisions when information in the JSON file is incomplete and/or contradictory. Pass true
* as the last argument to see all warnings on stderr.
*
*
* @param json_string: the JSON string
* @param reference_flop_rate: a reference compute speed (in flops/sec), assuming a task's computation is purely flops.
* This is needed because JSON files specify task execution times in seconds,
* but the WRENCH simulation needs some notion of "amount of computation" to
* apply reasonable scaling. (Because the XML platform description specifies host
* compute speeds in flops/sec). The times in the JSON file are thus assumed to be
* obtained on an machine with flop rate reference_flop_rate. NOTE: This is only used
* if the JSON file does not provide information regarding the machine on which a task
* was executed. In this case, the machine speed information is used.
* @param ignore_machine_specs: If true, always use the above reference_flop_rate instead of using the machine speed information
* if provided in the JSON file. (default if false)
* @param redundant_dependencies: Workflows provided by WfCommons
* sometimes include control/data dependencies between tasks that are already induced by
* other control/data dependencies (i.e., they correspond to transitive
* closures or existing edges in the workflow graphs). Passing redundant_dependencies=true
* force these "redundant" dependencies to be added as edges in the workflow. Passing
* redundant_dependencies=false will ignore these "redundant" dependencies. Most users
* would likely pass "false".
* @param ignore_cycle_creating_dependencies: if true, simply ignore dependencies that would make the workflow graph
* acyclic. If false, throw an exception if the workflow graph would be made acyclic by
* adding a dependency.
* @param min_cores_per_task: If the JSON file does not specify a number of cores for a task, the minimum number of
* cores on which the task can run is set to this value. (default is 1)
* @param max_cores_per_task: If the JSON file does not specify a number of cores for a task, the maximum number of
* cores on which the task can run is set to this value. (default is 1)
* @param enforce_num_cores: Use the min_cores_per_task and max_cores_per_task values even if the JSON file specifies
* a number of cores for a task. (default is false)
* @param ignore_avg_cpu: In WfCommons tasks can include a avgCPU field. If this field is provided, it is used to determine
* the fraction of the task's execution time that corresponds to CPU usage, which is then used
* to compute the task's work in flop. If set to true, then the task's execution time reported in the
* JSON will be assumed to be 100% CPU work. (default is false)
* @param show_warnings: Show all warnings. (default is false)
* @return a workflow
*/

static std::shared_ptr<Workflow> createWorkflowFromJSONString(const std::string &json_string,
const std::string &reference_flop_rate,
bool ignore_machine_specs = false,
bool redundant_dependencies = false,
bool ignore_cycle_creating_dependencies = false,
unsigned long min_cores_per_task = 1,
unsigned long max_cores_per_task = 1,
bool enforce_num_cores = false,
bool ignore_avg_cpu = false,
bool show_warnings = false);
};

}// namespace wrench
Expand Down
2 changes: 2 additions & 0 deletions include/wrench/workflow/Workflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace wrench {

public:
static std::shared_ptr<Workflow> createWorkflow();
std::string getName() const;
void clear();

/**
Expand Down Expand Up @@ -117,6 +118,7 @@ namespace wrench {
friend class Simulation;
friend class WorkflowTask;

std::string name;
bool update_top_bottom_levels_dynamically;

Workflow();
Expand Down
10 changes: 10 additions & 0 deletions src/wrench/workflow/Workflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,17 @@ namespace wrench {
* @brief Constructor
*/
Workflow::Workflow() {
static int workflow_number = 0;
this->update_top_bottom_levels_dynamically = true;
this->name = "workflow_" + std::to_string(workflow_number++);
}

/**
* @brief Name getter
* @return The workflow's name
*/
std::string Workflow::getName() const {
return this->name;
}

/**
Expand Down
45 changes: 35 additions & 10 deletions tools/wfcommons/src/WfCommonsWorkflowParser.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,40 @@ namespace wrench {
bool ignore_avg_cpu,
bool show_warnings) {
std::ifstream file;
nlohmann::json j;
// handle exceptions when opening the json file
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try {
file.open(filename);
std::stringstream buffer;
buffer << file.rdbuf();
return WfCommonsWorkflowParser::createWorkflowFromJSONString(
buffer.str(), reference_flop_rate, ignore_machine_specs,
redundant_dependencies,
ignore_cycle_creating_dependencies,
min_cores_per_task,
max_cores_per_task,
enforce_num_cores,
ignore_avg_cpu,
show_warnings);
} catch (const std::ifstream::failure &e) {
throw std::invalid_argument("WfCommonsWorkflowParser::createWorkflowFromJson(): Invalid Json file");
}
}

/**
* Documentation in .h file
*/
std::shared_ptr<Workflow> WfCommonsWorkflowParser::createWorkflowFromJSONString(const std::string &json_string,
const std::string &reference_flop_rate,
bool ignore_machine_specs,
bool redundant_dependencies,
bool ignore_cycle_creating_dependencies,
unsigned long min_cores_per_task,
unsigned long max_cores_per_task,
bool enforce_num_cores,
bool ignore_avg_cpu,
bool show_warnings) {

std::set<std::string> ignored_auxiliary_jobs;
std::set<std::string> ignored_transfer_jobs;

Expand All @@ -50,14 +83,7 @@ namespace wrench {
throw;
}

// handle exceptions when opening the json file
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try {
file.open(filename);
file >> j;
} catch (const std::ifstream::failure &e) {
throw std::invalid_argument("WfCommonsWorkflowParser::createWorkflowFromJson(): Invalid Json file");
}
nlohmann::json j = nlohmann::json::parse(json_string);

// Check schema version
nlohmann::json schema_version;
Expand Down Expand Up @@ -313,7 +339,6 @@ namespace wrench {
}
}
}
file.close();
workflow->enableTopBottomLevelDynamicUpdates(true);
workflow->updateAllTopBottomLevels();

Expand Down

0 comments on commit 3dd6886

Please sign in to comment.