Exemplo n.º 1
0
 def recvUsrData(self, buf_size):
     """Receive data from the front-end."""
     udata = create_string_buffer(buf_size)
     lmon.call(self.lib.LMON_be_recvUsrData, cast(udata, c_void_p))
     if self.amIMaster():
         return lmon.udata_unserialize(udata.raw)
     return None
Exemplo n.º 2
0
 def getProctable(self, session, maxsize):
     """Return the process table and its size with LMON_fe_getProctable."""
     proctab_type = lmon.MPIR_PROCDESC_EXT * maxsize
     proctab = proctab_type()
     size = c_uint()
     lmon.call(self.lib.LMON_fe_getProctable, session, byref(proctab), byref(size), c_uint(maxsize))
     return proctab, size.value
Exemplo n.º 3
0
    def attachAndSpawnDaemons(self, session, hostname, pid, daemon, d_argv,
                              febe_data, befe_data):
        """Invoke LMON_fe_attachAndSpawnDaemons.

        See the manpages. d_argv is a list.
        befe_data is the size of the desired buffer or None.

        """
        # Need a trailing null entry on the array.
        d_argv += [None]
        _d_argv = lmon.create_array(c_char_p, d_argv)
        if febe_data is not None:
            _febe_data = lmon.udata_serialize(febe_data)
        else:
            _febe_data = cast(None, c_void_p)
        buf = None
        if befe_data is not None:
            buf = create_string_buffer(befe_data)
            _befe_data = cast(buf, c_void_p)
        else:
            _befe_data = cast(None, c_void_p)
        lmon.call(self.lib.LMON_fe_attachAndSpawnDaemons, session, hostname,
                  pid, daemon, _d_argv, _febe_data, _befe_data)
        if befe_data:
            return lmon.udata_unserialize(buf.value)
        else:
            return None
Exemplo n.º 4
0
 def recvUsrData(self, buf_size):
     """Receive data from the front-end."""
     udata = create_string_buffer(buf_size)
     lmon.call(self.lib.LMON_be_recvUsrData, cast(udata, c_void_p))
     if self.amIMaster():
         return lmon.udata_unserialize(udata.raw)
     return None
Exemplo n.º 5
0
    def attachAndSpawnDaemons(self, session, hostname, pid, daemon, d_argv,
                              febe_data, befe_data):
        """Invoke LMON_fe_attachAndSpawnDaemons.

        See the manpages. d_argv is a list.
        befe_data is the size of the desired buffer or None.

        """
        # Need a trailing null entry on the array.
        d_argv += [None]
        _d_argv = lmon.create_array(c_char_p, d_argv)
        if febe_data is not None:
            _febe_data = lmon.udata_serialize(febe_data)
        else:
            _febe_data = cast(None, c_void_p)
        buf = None
        if befe_data is not None:
            buf = create_string_buffer(befe_data)
            _befe_data = cast(buf, c_void_p)
        else:
            _befe_data = cast(None, c_void_p)
        lmon.call(self.lib.LMON_fe_attachAndSpawnDaemons, session, hostname,
                  pid, daemon, _d_argv, _febe_data, _befe_data)
        if befe_data:
            return lmon.udata_unserialize(buf.value)
        else:
            return None
Exemplo n.º 6
0
 def getMyProctab(self, maxsize):
     """Return the process table and size for this process."""
     proctab_type = lmon.MPIR_PROCDESC_EXT * maxsize
     proctab = proctab_type()
     size = c_int()
     lmon.call(self.lib.LMON_be_getMyProctab, byref(proctab), byref(size),
               maxsize)
     return proctab, size.value
Exemplo n.º 7
0
 def getMyProctab(self, maxsize):
     """Return the process table and size for this process."""
     proctab_type = lmon.MPIR_PROCDESC_EXT * maxsize
     proctab = proctab_type()
     size = c_int()
     lmon.call(self.lib.LMON_be_getMyProctab, byref(proctab), byref(size),
               maxsize)
     return proctab, size.value
Exemplo n.º 8
0
 def getProctable(self, session, maxsize):
     """Return the process table and its size."""
     proctab_type = lmon.MPIR_PROCDESC_EXT * maxsize
     proctab = proctab_type()
     size = c_uint()
     lmon.call(self.lib.LMON_fe_getProctable, session, byref(proctab),
               byref(size), c_uint(maxsize))
     return proctab, size.value
Exemplo n.º 9
0
    def handshake(self, udata):
        """Do the LaunchMON handshake.

        If udata is not None, it should be the length of the buffer to
        unserialize front-end data to.

        """
        if udata is None:
            lmon.call(self.lib.LMON_be_handshake, cast(None, c_void_p))
        else:
            buf = create_string_buffer(udata)
            lmon.call(self.lib.LMON_be_handshake, cast(buf, c_void_p))
            # Check if we actually received data.
            if buf.raw[0] != "\0":
                return lmon.udata_unserialize(buf.value)
            return None
Exemplo n.º 10
0
    def putToBeDaemonEnv(self, session, environ):
        """Set up the backend environment with LMON_fe_putToBeDaemonEnv.

        Environ is a list of tuples of keys and values.

        """
        env_list_type = lmon.lmon_daemon_env_t * len(environ)
        env_list = env_list_type()
        for k, env_item in enumerate(environ):
            env_list[k].envName = env_item[0]
            env_list[k].envValue = env_item[1]
            if k < (len(environ) - 1):
                env_list[k].next = pointer(env_list[k + 1])
            else:
                env_list[k].next = None
        lmon.call(self.lib.LMON_fe_putToBeDaemonEnv, session, env_list, len(environ))
Exemplo n.º 11
0
    def handshake(self, udata):
        """Do the LaunchMON handshake.

        If udata is not None, it should be the length of the buffer to
        unserialize front-end data to.

        """
        if udata is None:
            lmon.call(self.lib.LMON_be_handshake, cast(None, c_void_p))
        else:
            buf = create_string_buffer(udata)
            lmon.call(self.lib.LMON_be_handshake, cast(buf, c_void_p))
            # Check if we actually received data.
            if buf.raw[0] != "\0":
                return lmon.udata_unserialize(buf.value)
            return None
Exemplo n.º 12
0
    def putToBeDaemonEnv(self, session, environ):
        """Set up the backend environment with LMON_fe_putToBeDaemonEnv.

        Environ is a list of tuples of keys and values.

        """
        env_list_type = lmon.lmon_daemon_env_t * len(environ)
        env_list = env_list_type()
        for k, env_item in enumerate(environ):
            env_list[k].envName = env_item[0]
            env_list[k].envValue = env_item[1]
            if k < (len(environ) - 1):
                env_list[k].next = pointer(env_list[k + 1])
            else:
                env_list[k].next = None
        lmon.call(self.lib.LMON_fe_putToBeDaemonEnv, session, env_list,
                  len(environ))
Exemplo n.º 13
0
    def init(self, argc, argv):
        """Invoke LMON_be_init.

        argc is the number of arguments in argv.
        argv is a list of arguments to pass as argv.

        """
        _argc = c_int(argc)
        # This is horribly ugly code to properly reconstruct argv for LaunchMON.
        # We stuff the arguments in string buffers (since they can be modified).
        # We stuff those into an array.
        # We add an entry at the end with a bunch of null bytes, since the last
        # argv entry is supposed to be a null and otherwise LaunchMON will make
        # malloc *very* unhappy.
        # We create a pointer to this array.
        # We pass that pointer by reference (another pointer).
        tmp_argv = [cast(create_string_buffer(x), c_char_p) for x in argv]
        tmp_argv.append(cast(create_string_buffer(32), c_char_p))
        _argv = lmon.create_array(c_char_p, tmp_argv)
        argv_ref = c_void_p(addressof(_argv))
        lmon.call(self.lib.LMON_be_init, lmon.LMON_VERSION, byref(_argc),
                  byref(argv_ref))
Exemplo n.º 14
0
    def init(self, argc, argv):
        """Invoke LMON_be_init.

        argc is the number of arguments in argv.
        argv is a list of arguments to pass as argv.

        """
        _argc = c_int(argc)
        # This is horribly ugly code to properly reconstruct argv for LaunchMON.
        # We stuff the arguments in string buffers (since they can be modified).
        # We stuff those into an array.
        # We add an entry at the end with a bunch of null bytes, since the last
        # argv entry is supposed to be a null and otherwise LaunchMON will make
        # malloc *very* unhappy.
        # We create a pointer to this array.
        # We pass that pointer by reference (another pointer).
        tmp_argv = [cast(create_string_buffer(x), c_char_p) for x in argv]
        tmp_argv.append(cast(create_string_buffer(32), c_char_p))
        _argv = lmon.create_array(c_char_p, tmp_argv)
        argv_ref = c_void_p(addressof(_argv))
        lmon.call(self.lib.LMON_be_init, lmon.LMON_VERSION, byref(_argc),
                  byref(argv_ref))
Exemplo n.º 15
0
    def broadcast(self, udata, size):
        """Broadcast data.

        The master provides data and the size of it, and this returns None.
        The slaves can provide None for the data, and size is the size of the
        buffer, which is returned after unserialization.

        """
        if self.amIMaster():
            # Master sends the data, returns None.
            lmon.call(self.lib.LMON_be_broadcast, lmon.udata_serialize(udata),
                      size)
            return None
        else:
            # Slave returns the data.
            buf = create_string_buffer(size)
            lmon.call(self.lib.LMON_be_broadcast, cast(buf, c_void_p), size)
            # Depending on the application, there appears to be a spurious null
            # byte at the start of the data. I do not know why. This avoids it.
            if buf.raw[0] == "\0" and buf.raw[1] != "\0":
                buf = string_at(addressof(buf) + 1)
            else:
                buf = buf.value
            return lmon.udata_unserialize(buf)
Exemplo n.º 16
0
    def scatter(self, udata_array, elem_size):
        """Scatter data.

        The master provides udata_array, which is an array of data to scatter.
        The slaves may provide None for the data.
        elem_size is the size of each element. Due to serialization of data,
        this should be the maximum size of the data, and the elements are padded
        to this length.

        All callers return their respective data (including the master).

        """
        buf = create_string_buffer(elem_size)
        if self.amIMaster():
            # Master pads data if needed and sends.
            total_size = len(udata_array) * elem_size
            send_buf = create_string_buffer(total_size)
            buf_addr = addressof(send_buf)
            idx = 0
            for elem in udata_array:
                tmp_buf = create_string_buffer(
                    string_at(lmon.udata_serialize(elem)), elem_size)
                memmove(buf_addr + (idx * elem_size), tmp_buf, elem_size)
                idx += 1
            lmon.call(self.lib.LMON_be_scatter, cast(send_buf, c_void_p),
                      elem_size, cast(buf, c_void_p))
        else:
            lmon.call(self.lib.LMON_be_scatter, cast(None, c_void_p),
                      elem_size, cast(buf, c_void_p))
        # This is here for the same reason as in broadcast.
        # Note that it appears that the null byte is only present for children.
        if buf.raw[0] == "\0" and buf.raw[1] != "\0":
            buf = string_at(addressof(buf) + 1)
        else:
            buf = buf.value
        return lmon.udata_unserialize(buf)
Exemplo n.º 17
0
    def broadcast(self, udata, size):
        """Broadcast data.

        The master provides data and the size of it, and this returns None.
        The slaves can provide None for the data, and size is the size of the
        buffer, which is returned after unserialization.

        """
        if self.amIMaster():
            # Master sends the data, returns None.
            lmon.call(self.lib.LMON_be_broadcast, lmon.udata_serialize(udata),
                      size)
            return None
        else:
            # Slave returns the data.
            buf = create_string_buffer(size)
            lmon.call(self.lib.LMON_be_broadcast, cast(buf, c_void_p), size)
            # Depending on the application, there appears to be a spurious null
            # byte at the start of the data. I do not know why. This avoids it.
            if buf.raw[0] == "\0" and buf.raw[1] != "\0":
                buf = string_at(addressof(buf) + 1)
            else:
                buf = buf.value
            return lmon.udata_unserialize(buf)
Exemplo n.º 18
0
 def launchAndSpawnDaemons(self, session, hostname, launcher, l_argv, daemon, d_argv, febe_data,
                           befe_data):
     """Invoke LMON_fe_launchAndSpawnDaemons."""
     # Need trailing null entries on the arrays.
     l_argv += [None]
     d_argv += [None]
     _l_argv = lmon.create_array(c_char_p, l_argv)
     _d_argv = lmon.create_array(c_char_p, d_argv)
     if febe_data is not None:
         _febe_data = lmon.udata_serialize(febe_data)
     else:
         _febe_data = cast(None, c_void_p)
     buf = None
     if befe_data is not None:
         buf = create_string_buffer(befe_data)
         _befe_data = cast(buf, c_void_p)
     else:
         _befe_data = cast(None, c_void_p)
     lmon.call(self.lib.LMON_fe_launchAndSpawnDaemons, session, hostname, launcher, _l_argv,
               daemon, _d_argv, _febe_data, _befe_data)
     if befe_data:
         return lmon.udata_unserialize(buf.value)
     else:
         return None
Exemplo n.º 19
0
    def scatter(self, udata_array, elem_size):
        """Scatter data.

        The master provides udata_array, which is an array of data to scatter.
        The slaves may provide None for the data.
        elem_size is the size of each element. Due to serialization of data,
        this should be the maximum size of the data, and the elements are padded
        to this length.

        All callers return their respective data (including the master).

        """
        buf = create_string_buffer(elem_size)
        if self.amIMaster():
            # Master pads data if needed and sends.
            total_size = len(udata_array) * elem_size
            send_buf = create_string_buffer(total_size)
            buf_addr = addressof(send_buf)
            idx = 0
            for elem in udata_array:
                tmp_buf = create_string_buffer(
                    string_at(lmon.udata_serialize(elem)), elem_size)
                memmove(buf_addr + (idx * elem_size), tmp_buf, elem_size)
                idx += 1
            lmon.call(self.lib.LMON_be_scatter, cast(send_buf, c_void_p),
                      elem_size, cast(buf, c_void_p))
        else:
            lmon.call(self.lib.LMON_be_scatter, cast(None, c_void_p), elem_size,
                      cast(buf, c_void_p))
        # This is here for the same reason as in broadcast.
        # Note that it appears that the null byte is only present for children.
        if buf.raw[0] == "\0" and buf.raw[1] != "\0":
            buf = string_at(addressof(buf) + 1)
        else:
            buf = buf.value
        return lmon.udata_unserialize(buf)
Exemplo n.º 20
0
 def launchAndSpawnDaemons(self, session, hostname, launcher, l_argv,
                           daemon, d_argv, febe_data, befe_data):
     """Invoke LMON_fe_launchAndSpawnDaemons."""
     # Need trailing null entries on the arrays.
     l_argv += [None]
     d_argv += [None]
     _l_argv = lmon.create_array(c_char_p, l_argv)
     _d_argv = lmon.create_array(c_char_p, d_argv)
     if febe_data is not None:
         _febe_data = lmon.udata_serialize(febe_data)
     else:
         _febe_data = cast(None, c_void_p)
     buf = None
     if befe_data is not None:
         buf = create_string_buffer(befe_data)
         _befe_data = cast(buf, c_void_p)
     else:
         _befe_data = cast(None, c_void_p)
     lmon.call(self.lib.LMON_fe_launchAndSpawnDaemons, session, hostname,
               launcher, _l_argv, daemon, _d_argv, _febe_data, _befe_data)
     if befe_data:
         return lmon.udata_unserialize(buf.value)
     else:
         return None
Exemplo n.º 21
0
 def sendUsrData(self, udata):
     """Send data to the front-end."""
     lmon.call(self.lib.LMON_be_sendUsrData, lmon.udata_serialize(udata))
Exemplo n.º 22
0
 def regPackForBeToFe(self, callback):
     """Register a pack function."""
     self.pack_cb = self.pack_type(callback)
     lmon.call(self.lib.LMON_be_regPackForBeToFe, self.pack_cb)
Exemplo n.º 23
0
 def amIMaster(self):
     """Return whether this process is the master."""
     rc = lmon.call(self.lib.LMON_be_amIMaster)
     if rc == lmon.LMON_YES:
         return True
     return False
Exemplo n.º 24
0
 def createSession(self):
     """Create and return a session handle with LMON_fe_createSession."""
     session = c_int()
     lmon.call(self.lib.LMON_fe_createSession, byref(session))
     return session.value
Exemplo n.º 25
0
 def kill(self, session):
     """Destroy all resources associated with the session."""
     lmon.call(self.lib.LMON_fe_kill, session)
Exemplo n.º 26
0
 def detach(self, session):
     """Detach from the resource manager but leave daemons running."""
     lmon.call(self.lib.LMON_fe_detach, session)
Exemplo n.º 27
0
 def getProctableSize(self, session):
     """Return the size of the process table with LMON_fe_getProctableSize."""
     size = c_uint()
     lmon.call(self.lib.LMON_fe_getProctableSize, session, byref(size))
     return size.value
Exemplo n.º 28
0
 def init(self):
     """Invoke LMON_fe_init."""
     lmon.call(self.lib.LMON_fe_init, lmon.LMON_VERSION)
Exemplo n.º 29
0
 def kill(self, session):
     """Destroy all resources associated with the session."""
     lmon.call(self.lib.LMON_fe_kill, session)
Exemplo n.º 30
0
 def shutdownDaemons(self, session):
     """Detach from the resource manager and shut down daemons."""
     lmon.call(self.lib.LMON_fe_shutdownDaemons, session)
Exemplo n.º 31
0
 def detach(self, session):
     """Detach from the resource manager but leave daemons running."""
     lmon.call(self.lib.LMON_fe_detach, session)
Exemplo n.º 32
0
 def barrier(self):
     """Make a barrier."""
     lmon.call(self.lib.LMON_be_barrier)
Exemplo n.º 33
0
 def getProctableSize(self, session):
     """Return the size of the process table."""
     size = c_uint()
     lmon.call(self.lib.LMON_fe_getProctableSize, session, byref(size))
     return size.value
Exemplo n.º 34
0
 def barrier(self):
     """Make a barrier."""
     lmon.call(self.lib.LMON_be_barrier)
Exemplo n.º 35
0
 def sendUsrDataBe(self, session, febe_data):
     """Send user data to the backend."""
     lmon.call(self.lib.LMON_fe_sendUsrDataBe, session,
               lmon.udata_serialize(febe_data))
Exemplo n.º 36
0
 def createSession(self):
     """Create and return a session handle with LMON_fe_createSession."""
     session = c_int()
     lmon.call(self.lib.LMON_fe_createSession, byref(session))
     return session.value
Exemplo n.º 37
0
 def regUnpackForFeToBe(self, callback):
     """Register an unpack function."""
     self.unpack_cb = self.unpack_type(callback)
     lmon.call(self.lib.LMON_be_regUnpackForFeToBe, self.unpack_cb)
Exemplo n.º 38
0
 def sendUsrData(self, udata):
     """Send data to the front-end."""
     lmon.call(self.lib.LMON_be_sendUsrData, lmon.udata_serialize(udata))
Exemplo n.º 39
0
 def shutdownDaemons(self, session):
     """Detach from the resource manager and shut down daemons."""
     lmon.call(self.lib.LMON_fe_shutdownDaemons, session)
Exemplo n.º 40
0
 def ready(self, udata):
     """Inform the front-end that we are ready."""
     if udata is None:
         lmon.call(self.lib.LMON_be_ready, cast(None, c_void_p))
     else:
         lmon.call(self.lib.LMON_be_ready, lmon.udata_serialize(udata))
Exemplo n.º 41
0
 def init(self):
     """Invoke LMON_fe_init."""
     lmon.call(self.lib.LMON_fe_init, lmon.LMON_VERSION)
Exemplo n.º 42
0
 def regPackForBeToFe(self, callback):
     """Register a pack function."""
     self.pack_cb = self.pack_type(callback)
     lmon.call(self.lib.LMON_be_regPackForBeToFe, self.pack_cb)
Exemplo n.º 43
0
 def getMyProctabSize(self):
     """Return the size of the process table."""
     size = c_int()
     lmon.call(self.lib.LMON_be_getMyProctabSize, byref(size))
     return size.value
Exemplo n.º 44
0
 def recvUsrDataBe(self, session, buf_size):
     """Receive user data from the backend."""
     befe_data = create_string_buffer(buf_size)
     lmon.call(self.lib.LMON_fe_recvUsrDataBe, session,
               cast(befe_data, c_void_p))
     return lmon.udata_unserialize(befe_data.raw)
Exemplo n.º 45
0
 def getMyProctabSize(self):
     """Return the size of the process table."""
     size = c_int()
     lmon.call(self.lib.LMON_be_getMyProctabSize, byref(size))
     return size.value
Exemplo n.º 46
0
 def regPackForFeToBe(self, session, callback):
     """Register a pack function with LMON_fe_regPackForFeToBe."""
     cb = self.pack_type(callback)
     self.pack_cbs[session] = cb
     lmon.call(self.lib.LMON_fe_regPackForFeToBe, session, cb)
Exemplo n.º 47
0
 def finalize(self):
     """Finalize this session."""
     lmon.call(self.lib.LMON_be_finalize)
Exemplo n.º 48
0
 def getMyRank(self):
     """Return the rank of this process."""
     rank = c_int()
     lmon.call(self.lib.LMON_be_getMyRank, byref(rank))
     return rank.value
Exemplo n.º 49
0
 def regUnpackForFeToBe(self, callback):
     """Register an unpack function."""
     self.unpack_cb = self.unpack_type(callback)
     lmon.call(self.lib.LMON_be_regUnpackForFeToBe, self.unpack_cb)
Exemplo n.º 50
0
 def getSize(self):
     """Return the number of LaunchMON processes."""
     size = c_int()
     lmon.call(self.lib.LMON_be_getSize, byref(size))
     return size.value
Exemplo n.º 51
0
 def finalize(self):
     """Finalize this session."""
     lmon.call(self.lib.LMON_be_finalize)
Exemplo n.º 52
0
 def regPackForFeToBe(self, session, callback):
     """Register a pack function with LMON_fe_regPackForFeToBe."""
     cb = self.pack_type(callback)
     self.pack_cbs[session] = cb
     lmon.call(self.lib.LMON_fe_regPackForFeToBe, session, cb)
Exemplo n.º 53
0
 def getMyRank(self):
     """Return the rank of this process."""
     rank = c_int()
     lmon.call(self.lib.LMON_be_getMyRank, byref(rank))
     return rank.value
Exemplo n.º 54
0
 def regUnpackForBeToFe(self, session, callback):
     """Register an unpack function with LMON_fe_regUnpackForBeToFe."""
     cb = self.unpack_type(callback)
     self.unpack_cbs[session] = cb
     lmon.call(self.lib.LMON_fe_regUnpackForBeToFe, session, cb)
Exemplo n.º 55
0
 def regUnpackForBeToFe(self, session, callback):
     """Register an unpack function with LMON_fe_regUnpackForBeToFe."""
     cb = self.unpack_type(callback)
     self.unpack_cbs[session] = cb
     lmon.call(self.lib.LMON_fe_regUnpackForBeToFe, session, cb)
Exemplo n.º 56
0
 def getSize(self):
     """Return the number of LaunchMON processes."""
     size = c_int()
     lmon.call(self.lib.LMON_be_getSize, byref(size))
     return size.value
Exemplo n.º 57
0
 def amIMaster(self):
     """Return whether this process is the master."""
     rc = lmon.call(self.lib.LMON_be_amIMaster)
     if rc == lmon.LMON_YES:
         return True
     return False
Exemplo n.º 58
0
 def sendUsrDataBe(self, session, febe_data):
     """Send user data to the backend with LMON_fe_sendUsrDataBe (it is serialized)."""
     lmon.call(self.lib.LMON_fe_sendUsrDataBe, session, lmon.udata_serialize(febe_data))
Exemplo n.º 59
0
 def ready(self, udata):
     """Inform the front-end that we are ready."""
     if udata is None:
         lmon.call(self.lib.LMON_be_ready, cast(None, c_void_p))
     else:
         lmon.call(self.lib.LMON_be_ready, lmon.udata_serialize(udata))
Exemplo n.º 60
0
 def recvUsrDataBe(self, session, buf_size):
     """Receive user data from the backend with LMON_fe_recvUsrDataBe (it is unserialized)."""
     befe_data = create_string_buffer(buf_size)
     lmon.call(self.lib.LMON_fe_recvUsrDataBe, session, cast(befe_data, c_void_p))
     return lmon.udata_unserialize(befe_data.raw)