Skip to content

Commit 842bc4a

Browse files
committed
Merge branch 'simgrid_master' into simgrid_master_mq
2 parents 84c478d + 3dd6886 commit 842bc4a

File tree

4 files changed

+100
-10
lines changed

4 files changed

+100
-10
lines changed

include/wrench/tools/wfcommons/WfCommonsWorkflowParser.h

100755100644
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,59 @@ namespace wrench {
7575
bool enforce_num_cores = false,
7676
bool ignore_avg_cpu = false,
7777
bool show_warnings = false);
78+
79+
80+
/**
81+
* @brief Create an abstract workflow based on a JSON file in the WfFormat (version 1.4) from WfCommons. This method
82+
* makes executive decisions when information in the JSON file is incomplete and/or contradictory. Pass true
83+
* as the last argument to see all warnings on stderr.
84+
*
85+
*
86+
* @param json_string: the JSON string
87+
* @param reference_flop_rate: a reference compute speed (in flops/sec), assuming a task's computation is purely flops.
88+
* This is needed because JSON files specify task execution times in seconds,
89+
* but the WRENCH simulation needs some notion of "amount of computation" to
90+
* apply reasonable scaling. (Because the XML platform description specifies host
91+
* compute speeds in flops/sec). The times in the JSON file are thus assumed to be
92+
* obtained on an machine with flop rate reference_flop_rate. NOTE: This is only used
93+
* if the JSON file does not provide information regarding the machine on which a task
94+
* was executed. In this case, the machine speed information is used.
95+
* @param ignore_machine_specs: If true, always use the above reference_flop_rate instead of using the machine speed information
96+
* if provided in the JSON file. (default if false)
97+
* @param redundant_dependencies: Workflows provided by WfCommons
98+
* sometimes include control/data dependencies between tasks that are already induced by
99+
* other control/data dependencies (i.e., they correspond to transitive
100+
* closures or existing edges in the workflow graphs). Passing redundant_dependencies=true
101+
* force these "redundant" dependencies to be added as edges in the workflow. Passing
102+
* redundant_dependencies=false will ignore these "redundant" dependencies. Most users
103+
* would likely pass "false".
104+
* @param ignore_cycle_creating_dependencies: if true, simply ignore dependencies that would make the workflow graph
105+
* acyclic. If false, throw an exception if the workflow graph would be made acyclic by
106+
* adding a dependency.
107+
* @param min_cores_per_task: If the JSON file does not specify a number of cores for a task, the minimum number of
108+
* cores on which the task can run is set to this value. (default is 1)
109+
* @param max_cores_per_task: If the JSON file does not specify a number of cores for a task, the maximum number of
110+
* cores on which the task can run is set to this value. (default is 1)
111+
* @param enforce_num_cores: Use the min_cores_per_task and max_cores_per_task values even if the JSON file specifies
112+
* a number of cores for a task. (default is false)
113+
* @param ignore_avg_cpu: In WfCommons tasks can include a avgCPU field. If this field is provided, it is used to determine
114+
* the fraction of the task's execution time that corresponds to CPU usage, which is then used
115+
* to compute the task's work in flop. If set to true, then the task's execution time reported in the
116+
* JSON will be assumed to be 100% CPU work. (default is false)
117+
* @param show_warnings: Show all warnings. (default is false)
118+
* @return a workflow
119+
*/
120+
121+
static std::shared_ptr<Workflow> createWorkflowFromJSONString(const std::string &json_string,
122+
const std::string &reference_flop_rate,
123+
bool ignore_machine_specs = false,
124+
bool redundant_dependencies = false,
125+
bool ignore_cycle_creating_dependencies = false,
126+
unsigned long min_cores_per_task = 1,
127+
unsigned long max_cores_per_task = 1,
128+
bool enforce_num_cores = false,
129+
bool ignore_avg_cpu = false,
130+
bool show_warnings = false);
78131
};
79132

80133
}// namespace wrench

include/wrench/workflow/Workflow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace wrench {
3535

3636
public:
3737
static std::shared_ptr<Workflow> createWorkflow();
38+
std::string getName() const;
3839
void clear();
3940

4041
/**
@@ -117,6 +118,7 @@ namespace wrench {
117118
friend class Simulation;
118119
friend class WorkflowTask;
119120

121+
std::string name;
120122
bool update_top_bottom_levels_dynamically;
121123

122124
Workflow();

src/wrench/workflow/Workflow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,17 @@ namespace wrench {
277277
* @brief Constructor
278278
*/
279279
Workflow::Workflow() {
280+
static int workflow_number = 0;
280281
this->update_top_bottom_levels_dynamically = true;
282+
this->name = "workflow_" + std::to_string(workflow_number++);
283+
}
284+
285+
/**
286+
* @brief Name getter
287+
* @return The workflow's name
288+
*/
289+
std::string Workflow::getName() const {
290+
return this->name;
281291
}
282292

283293
/**

tools/wfcommons/src/WfCommonsWorkflowParser.cpp

100755100644
Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,40 @@ namespace wrench {
3535
bool ignore_avg_cpu,
3636
bool show_warnings) {
3737
std::ifstream file;
38-
nlohmann::json j;
38+
// handle exceptions when opening the json file
39+
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
40+
try {
41+
file.open(filename);
42+
std::stringstream buffer;
43+
buffer << file.rdbuf();
44+
return WfCommonsWorkflowParser::createWorkflowFromJSONString(
45+
buffer.str(), reference_flop_rate, ignore_machine_specs,
46+
redundant_dependencies,
47+
ignore_cycle_creating_dependencies,
48+
min_cores_per_task,
49+
max_cores_per_task,
50+
enforce_num_cores,
51+
ignore_avg_cpu,
52+
show_warnings);
53+
} catch (const std::ifstream::failure &e) {
54+
throw std::invalid_argument("WfCommonsWorkflowParser::createWorkflowFromJson(): Invalid Json file");
55+
}
56+
}
57+
58+
/**
59+
* Documentation in .h file
60+
*/
61+
std::shared_ptr<Workflow> WfCommonsWorkflowParser::createWorkflowFromJSONString(const std::string &json_string,
62+
const std::string &reference_flop_rate,
63+
bool ignore_machine_specs,
64+
bool redundant_dependencies,
65+
bool ignore_cycle_creating_dependencies,
66+
unsigned long min_cores_per_task,
67+
unsigned long max_cores_per_task,
68+
bool enforce_num_cores,
69+
bool ignore_avg_cpu,
70+
bool show_warnings) {
71+
3972
std::set<std::string> ignored_auxiliary_jobs;
4073
std::set<std::string> ignored_transfer_jobs;
4174

@@ -50,14 +83,7 @@ namespace wrench {
5083
throw;
5184
}
5285

53-
// handle exceptions when opening the json file
54-
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
55-
try {
56-
file.open(filename);
57-
file >> j;
58-
} catch (const std::ifstream::failure &e) {
59-
throw std::invalid_argument("WfCommonsWorkflowParser::createWorkflowFromJson(): Invalid Json file");
60-
}
86+
nlohmann::json j = nlohmann::json::parse(json_string);
6187

6288
// Check schema version
6389
nlohmann::json schema_version;
@@ -313,7 +339,6 @@ namespace wrench {
313339
}
314340
}
315341
}
316-
file.close();
317342
workflow->enableTopBottomLevelDynamicUpdates(true);
318343
workflow->updateAllTopBottomLevels();
319344

0 commit comments

Comments
 (0)