Skip to content

Commit 174732b

Browse files
author
Elias Werner
committed
fix multicellmode for very short cells
1 parent 78ad091 commit 174732b

1 file changed

Lines changed: 37 additions & 39 deletions

File tree

src/jumper/kernel.py

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@ def report_perfdata(self, performance_data_nodes, duration):
674674
async def scorep_execute(
675675
self,
676676
code,
677-
code_for_history,
678677
silent,
679678
user_expressions=None,
680679
allow_stdin=False,
@@ -702,7 +701,6 @@ async def scorep_execute(
702701
os.open(scorep_script_name, os.O_WRONLY | os.O_CREAT), "w"
703702
) as file:
704703
file.write(self.pershelper.subprocess_wrapper(code))
705-
706704
# For disk mode use implicit synchronization between kernel and
707705
# subprocess: await jupyter_dump, subprocess.wait(),
708706
# await jupyter_update Ghost cell - dump current Jupyter session for
@@ -752,6 +750,7 @@ async def scorep_execute(
752750
proc = subprocess.Popen(
753751
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=proc_env
754752
)
753+
755754
self.perfdata_handler.start_perfmonitor(proc.pid)
756755
# For memory mode jupyter_dump and jupyter_update must be awaited
757756
# concurrently to the running subprocess
@@ -810,6 +809,7 @@ async def scorep_execute(
810809
# explicit timestamps, but aligns the colorization of the plot based
811810
# on the number of perf measurements we have, which is individual per
812811
# node
812+
813813
time_indices = None
814814
if len(multicellmode_timestamps):
815815
# retrieve the index this cell will have in the global history
@@ -832,9 +832,15 @@ async def scorep_execute(
832832
)
833833
nb_ms %= 1.0
834834
# add time for last to last measurement
835+
835836
if nb_ms >= 0.0:
836-
sub_idx, val = time_indices[0][-1]
837-
time_indices[0][-1] = (sub_idx, val + nb_ms)
837+
if len(time_indices[0]):
838+
sub_idx, val = time_indices[0][-1]
839+
time_indices[0][-1] = (sub_idx, val + nb_ms)
840+
else:
841+
time_indices[0].append(
842+
(str(sub_idx) + "_" + str(0), nb_ms)
843+
)
838844

839845
nb_ms = 0.0
840846
for idx, val in enumerate(time_indices[0]):
@@ -903,7 +909,7 @@ async def scorep_execute(
903909
f"Instrumentation results can be found in {scorep_folder}"
904910
)
905911
else:
906-
# Find last creasted directory with scorep* name
912+
# Find last created directory with scorep* name
907913
# TODO: Directory isn't created local when running scorep-collector
908914
max_iterations = 5
909915
while max_iterations > 0:
@@ -938,7 +944,7 @@ async def scorep_execute(
938944
if performance_data_nodes:
939945
self.report_perfdata(performance_data_nodes, duration)
940946
self.perfdata_handler.append_code(
941-
datetime.datetime.now(), code_for_history, time_indices
947+
datetime.datetime.now(), code, time_indices
942948
)
943949
return self.standard_reply()
944950

@@ -1178,42 +1184,35 @@ async def do_execute(
11781184
elif code.startswith("%%finalize_multicellmode"):
11791185
# Cannot be put into a separate function due to tight coupling
11801186
# between do_execute and scorep_execute
1181-
if not self.scorep_available_:
1182-
self.cell_output(
1183-
"Score-P not available, cell ignored.", "stderr"
1184-
)
1185-
return self.standard_reply()
1186-
else:
1187-
if self.mode == KernelMode.MULTICELL:
1188-
self.mode = KernelMode.DEFAULT
1189-
try:
1190-
reply_status = await self.scorep_execute(
1191-
self.multicell_code,
1192-
silent,
1193-
store_history,
1194-
user_expressions,
1195-
allow_stdin,
1196-
cell_id=cell_id,
1197-
)
1198-
except Exception:
1199-
self.cell_output(
1200-
"KernelError: Multicell execution failed.",
1201-
"stderr",
1202-
)
1203-
return self.standard_reply()
1204-
self.multicell_code = ""
1205-
self.multicell_cellcount = 0
1206-
return reply_status
1207-
elif self.mode == KernelMode.WRITEFILE:
1208-
self.writefile_multicell = False
1209-
return self.standard_reply()
1210-
else:
1187+
if self.mode == KernelMode.MULTICELL:
1188+
self.mode = KernelMode.DEFAULT
1189+
try:
1190+
reply_status = await self.scorep_execute(
1191+
self.multicell_code,
1192+
silent,
1193+
user_expressions,
1194+
allow_stdin,
1195+
cell_id=cell_id,
1196+
)
1197+
except Exception as e:
12111198
self.cell_output(
1212-
f"KernelWarning: Currently in {self.mode},"
1213-
f" ignore command",
1199+
"KernelError: Multicell execution failed.",
12141200
"stderr",
12151201
)
12161202
return self.standard_reply()
1203+
self.multicell_code = ""
1204+
self.multicell_cellcount = -1
1205+
return reply_status
1206+
elif self.mode == KernelMode.WRITEFILE:
1207+
self.writefile_multicell = False
1208+
return self.standard_reply()
1209+
else:
1210+
self.cell_output(
1211+
f"KernelWarning: Currently in {self.mode},"
1212+
f" ignore command",
1213+
"stderr",
1214+
)
1215+
return self.standard_reply()
12171216
elif code.startswith("%%start_writefile"):
12181217
return self.scorep_not_available() or self.start_writefile(code)
12191218
elif code.startswith("%%abort_writefile"):
@@ -1227,7 +1226,6 @@ async def do_execute(
12271226
return await self.scorep_execute(
12281227
code.split("\n", 1)[1],
12291228
silent,
1230-
store_history,
12311229
user_expressions,
12321230
allow_stdin,
12331231
cell_id=cell_id,

0 commit comments

Comments
 (0)