def get_master_port(args):
    """Get master port from `args.init_method`.

    :param argparse.ArgumentParser args: `args` is a argparse that should
         contain `init_method`, `rank` and `world_size`.
    :return: The port that master used to communicate with slaves.
    :rtype: str or None

    """
    if args.init_method is not None:
        address = args.init_method.split(":")
        port = address[-1]
        return port
    else:
        return None