Skip to content

Commit

Permalink
Fixing issue with machine name
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Apr 22, 2024
1 parent b38818d commit 2396ecc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
26 changes: 25 additions & 1 deletion armi/bookkeeping/report/reportingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _writeCaseInformation(o, cs):
(Operator_ArmiCodebase, context.ROOT),
(Operator_WorkingDirectory, os.getcwd()),
(Operator_PythonInterperter, sys.version),
(Operator_MasterMachine, os.environ.get("COMPUTERNAME", "?")),
(Operator_MasterMachine, getNodeName()),
(Operator_NumProcessors, context.MPI_SIZE),
(Operator_Date, context.START_TIME),
]
Expand Down Expand Up @@ -235,6 +235,30 @@ def _writeReactorCycleInformation(o, cs):
_writeReactorCycleInformation(o, cs)


def getNodeName():
"""Get the name of this comput node.
First, look in context.py. Then try various Linux tools. Then try Windows commands.
Returns
-------
str
Compute node name.
"""
hostNames = [
context.MPI_NODENAME,
context.MPI_NODENAMES[0],
subprocess.run("hostname", capture_output=True, text=True, shell=True).stdout,
subprocess.run("uname -n", capture_output=True, text=True, shell=True).stdout,
os.environ.get("COMPUTERNAME", context.LOCAL),
]
for nodeName in hostNames:
if nodeName and nodeName != context.LOCAL:
return nodeName

return context.LOCAL


def _getSystemInfoWindows():
"""Get system information, assuming the system is Windows.
Expand Down
10 changes: 10 additions & 0 deletions armi/bookkeeping/report/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from armi.bookkeeping.report.reportingUtils import (
_getSystemInfoLinux,
_getSystemInfoWindows,
getNodeName,
getSystemInfo,
makeBlockDesignReport,
setNeutronBalancesReport,
Expand Down Expand Up @@ -103,6 +104,15 @@ def test_getSystemInfo(self):

self.assertGreater(len(out), sum(len(sstr) + 5 for sstr in substrings))

def test_getNodeName(self):
"""Test that the getNodeName() method returns a non-empty string.
It is hard to know what string SHOULD be return here, and it would depend on how the OS is
set up on your machine or cluster. But this simple test needs to pass as-is on Windows
and Linux.
"""
self.assertGreater(len(getNodeName()), 0)


class TestReport(unittest.TestCase):
def setUp(self):
Expand Down
5 changes: 3 additions & 2 deletions armi/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ def setMode(cls, mode):
# MPI_SIZE is the total number of CPUs
MPI_RANK = 0
MPI_SIZE = 1
MPI_NODENAME = "local"
MPI_NODENAMES = ["local"]
LOCAL = "local"
MPI_NODENAME = LOCAL
MPI_NODENAMES = [LOCAL]


try:
Expand Down

0 comments on commit 2396ecc

Please sign in to comment.