Skip to content
Snippets Groups Projects
Mapping.py 1.58 KiB
Newer Older
Rishi Sharma's avatar
Rishi Sharma committed
class Mapping:
    """
    This class defines the bidirectional mapping between:
        1. The unique identifier
        2. machine_id and rank
Rishi Sharma's avatar
Rishi Sharma committed
    """

    def __init__(self, n_procs):
        """
        Constructor
Rishi Sharma's avatar
Rishi Sharma committed

        Parameters
        ----------
        n_procs : int
            Total number of processes

Rishi Sharma's avatar
Rishi Sharma committed
        """
        self.n_procs = n_procs

    def get_n_procs(self):
        """
        Gives the global sum of all processes that are spawned on the machines

        Returns
        -------
        int
            the number of global processes
        """

        return self.n_procs

Rishi Sharma's avatar
Rishi Sharma committed
    def get_uid(self, rank: int, machine_id: int):
        """
        Gives the global unique identifier of the node
Rishi Sharma's avatar
Rishi Sharma committed
        Parameters
        ----------
        rank : int
            Node's rank on its machine
        machine_id : int
            node's machine in the cluster
Rishi Sharma's avatar
Rishi Sharma committed
        Returns
        -------
        int
            the unique identifier
Rishi Sharma's avatar
Rishi Sharma committed
        """

        raise NotImplementedError

    def get_machine_and_rank(self, uid: int):
        """
        Gives the rank and machine_id of the node
Rishi Sharma's avatar
Rishi Sharma committed
        Parameters
        ----------
        uid : int
            globally unique identifier of the node
Rishi Sharma's avatar
Rishi Sharma committed
        Returns
        -------
        2-tuple
Rishi Sharma's avatar
Rishi Sharma committed
            a tuple of rank and machine_id
Rishi Sharma's avatar
Rishi Sharma committed
        """

        raise NotImplementedError

    def get_local_procs_count(self):
        """
        Gives number of processes that run on the node

        Returns
        -------
        int
            the number of local processes

        """

        raise NotImplementedError