Skip to content

Commit 046c3dd

Browse files
committed
swift/t with flowcept
1 parent 13441dc commit 046c3dd

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

wfcommons/wfbench/translator/swift_t.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self,
4343
self.files_map = {}
4444
self.tasks_map = {}
4545
self.cmd_counter = 1
46-
self.last_file = ""
46+
self.out_files = []
4747

4848
# find applications
4949
self.apps = []
@@ -103,7 +103,9 @@ def translate(self, output_folder: pathlib.Path) -> None:
103103

104104
# flowcept end
105105
if self.workflow.workflow_id:
106-
self.script += f"string fc = sprintf(flowcept, \"{self.workflow.workflow_id}\", \"{self.workflow.name}\", \"{self.last_file}\");\n" \
106+
out_files = ", ".join(f'"{item}"' for item in self.out_files)
107+
self.script += f"string out_files[] = [{out_files}];\n"
108+
self.script += f"string fc = sprintf(flowcept, \"{self.workflow.workflow_id}\", \"{self.workflow.name}\", out_files);\n" \
107109
"python_persist(fc);\n"
108110

109111
run_workflow_code = self._merge_codelines("templates/swift_t_templates/workflow.swift", self.script)
@@ -223,11 +225,12 @@ def _add_tasks(self, category: str) -> None:
223225
f" string of_{self.cmd_counter} = sprintf(\"0%s\", co_{self.cmd_counter});\n" \
224226
f" {category}__out[i] = string2int(of_{self.cmd_counter});\n" \
225227
"}\n\n"
226-
self.last_file = f"{self.output_folder.absolute()}/data/{category}_{num_tasks - 1}_output.txt"
228+
self.out_files.append(f"{self.output_folder.absolute()}/data/{category}_{num_tasks - 1}_output.txt")
227229
else:
228-
self.last_file = f"{self.output_folder.absolute()}/data/{category}_0_output.txt"
230+
out_file = f"{self.output_folder.absolute()}/data/{category}_0_output.txt"
231+
self.out_files.append(out_file)
229232
args = args.replace(
230-
", of", f", \"{self.last_file}\"").replace("[i]", "[0]")
233+
", of", f", \"{out_file}\"").replace("[i]", "[0]")
231234
self.script += f"string cmd_{self.cmd_counter} = sprintf(command, \"{self.cpu_benchmark}\", \"{category}\", {args});\n" \
232235
f"string co_{self.cmd_counter} = python_persist(cmd_{self.cmd_counter});\n" \
233236
f"string of_{self.cmd_counter} = sprintf(\"0%s\", co_{self.cmd_counter});\n" \

wfcommons/wfbench/translator/templates/swift_t_templates/workflow.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ time.sleep(30)
1414
global const string flowcept =
1515
"""
1616
import logging
17-
import os.path
1817
import subprocess
1918
import time
2019
from flowcept.flowcept_api.flowcept_controller import Flowcept
20+
from pathlib import Path
2121
2222
logging.basicConfig(
2323
level=logging.INFO,
@@ -28,7 +28,7 @@ logging.basicConfig(
2828
2929
workflow_id = "%s"
3030
workflow_name = "%s"
31-
file_path = "%s"
31+
out_files = "%A"
3232
3333
logging.info("Flowcept Starting")
3434
flowcept_agent = Flowcept(workflow_id=workflow_id, workflow_name=workflow_name, bundle_exec_id=workflow_id)
@@ -39,18 +39,22 @@ except Exception:
3939
import traceback
4040
traceback.print_exc()
4141
42-
while not os.path.exists(file_path):
42+
remaining_files = set(out_files)
43+
44+
while remaining_files:
45+
found_files = {f for f in remaining_files if Path(f).exists()}
46+
if found_files:
47+
remaining_files -= found_files
48+
if not remaining_files:
49+
break
4350
time.sleep(1)
4451
45-
if os.path.isfile(file_path):
46-
time.sleep(240)
47-
try:
48-
flowcept_agent.stop()
49-
except Exception:
50-
import traceback
51-
traceback.print_exc()
52-
else:
53-
raise ValueError(f"{file_path} is not a file!")
52+
time.sleep(240)
53+
try:
54+
flowcept_agent.stop()
55+
except Exception:
56+
import traceback
57+
traceback.print_exc()
5458
5559
logging.info("Flowcept Completed")
5660
""";

0 commit comments

Comments
 (0)