Created
July 22, 2021 20:07
-
-
Save kiyoon/add4a18a5224728fb5d9d9296d0b8a54 to your computer and use it in GitHub Desktop.
Get Slurm master node address from $SLURM_NODELIST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### get the first node name as master address | |
### e.g. master(aislab-[2-5],gnoded1) == aislab-2 | |
import argparse | |
def get_parser(): | |
parser = argparse.ArgumentParser(description="Extract master node name from Slurm node list", | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
parser.add_argument("nodelist", help="Slurm nodelist") | |
return parser | |
if __name__ == '__main__': | |
parser = get_parser() | |
args = parser.parse_args() | |
first_nodelist = args.nodelist.split(',')[0] | |
if '[' in first_nodelist: | |
a = first_nodelist.split('[') | |
first_node = a[0] + a[1].split('-')[0] | |
else: | |
first_node = first_nodelist | |
print(first_node) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment