Skip to content

Commit 2b0b34d

Browse files
committed
Retrieve exec_hosts from bjobs
1 parent 484381b commit 2b0b34d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/ert/scheduler/lsf_driver.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ class JobData:
108108
iens: int
109109
job_state: AnyJob
110110
submitted_timestamp: float
111+
exec_hosts: str
111112

112113

113114
def parse_bjobs(bjobs_output: str) -> Dict[str, JobState]:
114115
data: Dict[str, JobState] = {}
115116
for line in bjobs_output.splitlines():
116117
tokens = line.split(sep="^")
117-
if len(tokens) == 2:
118-
job_id, job_state = tokens
118+
if len(tokens) == 3:
119+
job_id, job_state, _ = tokens
119120
if job_state not in get_args(JobState):
120121
logger.error(
121122
f"Unknown state {job_state} obtained from "
@@ -126,6 +127,17 @@ def parse_bjobs(bjobs_output: str) -> Dict[str, JobState]:
126127
return data
127128

128129

130+
def parse_bjobs_exec_hosts(bjobs_output: str) -> Dict[str, str]:
131+
data: Dict[str, str] = {}
132+
for line in bjobs_output.splitlines():
133+
tokens = line.split(sep="^")
134+
if len(tokens) == 3:
135+
job_id, _, exec_hosts = tokens
136+
if exec_hosts != "-":
137+
data[job_id] = exec_hosts
138+
return data
139+
140+
129141
def build_resource_requirement_string(
130142
exclude_hosts: Sequence[str],
131143
realization_memory: int,
@@ -360,6 +372,7 @@ async def submit(
360372
iens=iens,
361373
job_state=QueuedJob(job_state="PEND"),
362374
submitted_timestamp=time.time(),
375+
exec_hosts="-",
363376
)
364377
self._iens2jobid[iens] = job_id
365378

@@ -421,7 +434,7 @@ async def poll(self) -> None:
421434
str(self._bjobs_cmd),
422435
"-noheader",
423436
"-o",
424-
"jobid stat delimiter='^'",
437+
"jobid stat exec_host delimiter='^'",
425438
*current_jobids,
426439
stdout=asyncio.subprocess.PIPE,
427440
stderr=asyncio.subprocess.PIPE,
@@ -438,6 +451,12 @@ async def poll(self) -> None:
438451
f"bjobs gave returncode {process.returncode} and error {stderr.decode()}"
439452
)
440453
bjobs_states = _parse_jobs_dict(parse_bjobs(stdout.decode(errors="ignore")))
454+
bjobs_exec_hosts = parse_bjobs_exec_hosts(stdout.decode(errors="ignore"))
455+
456+
print("exec hosts", bjobs_exec_hosts)
457+
458+
for jobid, exec_hosts in bjobs_exec_hosts:
459+
self._jobs[jobid].exec_hosts = exec_hosts
441460

442461
job_ids_found_in_bjobs_output = set(bjobs_states.keys())
443462
if (

0 commit comments

Comments
 (0)