Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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))
Пример #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
Пример #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))
Пример #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))
Пример #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))
Пример #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)
Пример #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)
Пример #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)
Пример #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
Пример #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)
Пример #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
Пример #21
0
 def sendUsrData(self, udata):
     """Send data to the front-end."""
     lmon.call(self.lib.LMON_be_sendUsrData, lmon.udata_serialize(udata))
Пример #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)
Пример #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
Пример #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
Пример #25
0
 def kill(self, session):
     """Destroy all resources associated with the session."""
     lmon.call(self.lib.LMON_fe_kill, session)
Пример #26
0
 def detach(self, session):
     """Detach from the resource manager but leave daemons running."""
     lmon.call(self.lib.LMON_fe_detach, session)
Пример #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
Пример #28
0
 def init(self):
     """Invoke LMON_fe_init."""
     lmon.call(self.lib.LMON_fe_init, lmon.LMON_VERSION)
Пример #29
0
 def kill(self, session):
     """Destroy all resources associated with the session."""
     lmon.call(self.lib.LMON_fe_kill, session)
Пример #30
0
 def shutdownDaemons(self, session):
     """Detach from the resource manager and shut down daemons."""
     lmon.call(self.lib.LMON_fe_shutdownDaemons, session)
Пример #31
0
 def detach(self, session):
     """Detach from the resource manager but leave daemons running."""
     lmon.call(self.lib.LMON_fe_detach, session)
Пример #32
0
 def barrier(self):
     """Make a barrier."""
     lmon.call(self.lib.LMON_be_barrier)
Пример #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
Пример #34
0
 def barrier(self):
     """Make a barrier."""
     lmon.call(self.lib.LMON_be_barrier)
Пример #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))
Пример #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
Пример #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)
Пример #38
0
 def sendUsrData(self, udata):
     """Send data to the front-end."""
     lmon.call(self.lib.LMON_be_sendUsrData, lmon.udata_serialize(udata))
Пример #39
0
 def shutdownDaemons(self, session):
     """Detach from the resource manager and shut down daemons."""
     lmon.call(self.lib.LMON_fe_shutdownDaemons, session)
Пример #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))
Пример #41
0
 def init(self):
     """Invoke LMON_fe_init."""
     lmon.call(self.lib.LMON_fe_init, lmon.LMON_VERSION)
Пример #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)
Пример #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
Пример #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)
Пример #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
Пример #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)
Пример #47
0
 def finalize(self):
     """Finalize this session."""
     lmon.call(self.lib.LMON_be_finalize)
Пример #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
Пример #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)
Пример #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
Пример #51
0
 def finalize(self):
     """Finalize this session."""
     lmon.call(self.lib.LMON_be_finalize)
Пример #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)
Пример #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
Пример #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)
Пример #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)
Пример #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
Пример #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
Пример #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))
Пример #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))
Пример #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)