Esempio n. 1
0
    def test07(self):
        """Verify several MPI messages from a child process."""

        MSG_NUM = 100
        msgs = [MESSAGE1_indexed % i for i in range(MSG_NUM)]
        random.shuffle(msgs)

        register_mpi()

        fork = tfork2()
        if fork.isChild:
            #
            # In child
            #
            register_mpi()

            #
            # Send all messages
            #
            for msg in msgs:
                send_mpi_message(0, msg)

            #
            # Allow the
            #
            fork.release()
            fork.sync()

            fork.exit()

        #
        # In parent
        # ---------
        # Release the child
        #
        fork.sync()

        #
        # Check received messages
        #
        for msg in msgs:
            self.verifyMessage(rank=1,
                               timeout=NULL_TIMEOUT,
                               expected_message=msg)

        #
        # Wait for the child to exit
        #
        fork.release()
        fork.wait()
Esempio n. 2
0
    def test14(self):
        """Test correct timeout handling (timeout happens)"""
        SLEEP_TIME = 2

        MPI.register_mpi()

        #
        # Fork the parent
        #
        fork = tfork2()
        if fork.isChild:
            #
            # In child
            #
            MPI.register_mpi()
            fork.release()

            time.sleep(SLEEP_TIME)
            MPI.send_mpi_message(rank=0, message=MESSAGE1)

            #
            # Exit the child
            #
            fork.exit()

        #
        # In parent
        # ---------
        # Check received message
        #
        fork.sync()

        #
        # Verify message and sleep time.
        #
        self.errnoCheck(
            cmd=MPI.receive_mpi_message,
            args=(1, .8 * SLEEP_TIME, DEFAULT_MESSAGE_SIZE),
            expected_errno=errno.ETIMEDOUT,
            msg=
            'The receive_mpi_message call should have timed out, but it did not'
        )

        #
        # Wait for the child to terminate
        #
        fork.wait()
Esempio n. 3
0
def test3():
    """Timeout test"""

    SLEEP_TIME = 5

    MPI.register_mpi()

    #
    # Fork the parent
    #
    fork = tfork2()
    if fork.isChild:
        #
        # In child
        #
        print("in child")
        fork.release()

        time.sleep(1.1 * SLEEP_TIME)

        print("child sending hello")
        MPI.send_mpi_message(rank=0, message='hello')
        #
        # Exit the child
        #
        fork.exit()

    #
    # In parent
    # ---------
    # Check received message
    #
    print("parent doing sync")
    fork.sync()

    t0 = time.time()
    print("parent trying to receive msg")
    print 'recieved message=%s of length=%d' % MPI.receive_mpi_message(
        rank=1, timeout=2 * SLEEP_TIME, message_size=100)
    dt = time.time() - t0
    print 'dt = %g, should be bigger than %g' % (dt, SLEEP_TIME)

    #
    # Wait for the child to terminate
    #
    fork.wait()
Esempio n. 4
0
    def test13(self):
        """Test correct timeout handling (timeout doesn't happen)"""
        SLEEP_TIME = 2

        MPI.register_mpi()

        #
        # Fork the parent
        #
        fork = tfork2()
        if fork.isChild:
            #
            # In child
            #
            MPI.register_mpi()
            fork.release()

            time.sleep(SLEEP_TIME)

            MPI.send_mpi_message(rank=0, message=MESSAGE1)

            #
            # Exit the child
            #
            fork.exit()

        #
        # In parent
        # ---------
        # Check received message
        #
        fork.sync()

        #
        # Verify message and sleep time.
        #
        self.verifyMessage(rank=1,
                           timeout=2 * SLEEP_TIME,
                           expected_message=MESSAGE1,
                           sleep_time=SLEEP_TIME)

        #
        # Wait for the child to terminate
        #
        fork.wait()
Esempio n. 5
0
    def test06(self):
        """Verify simple MPI messaging to a child process."""

        msg = MESSAGE1_indexed % random.randint(0, 255)

        register_mpi()

        fork = tfork2()
        if fork.isChild:
            #
            # In child
            # ---------
            register_mpi()

            #
            # Allow the parent to send message.
            #
            fork.release()
            fork.sync()
            self.verifyMessage(rank=0,
                               timeout=NULL_TIMEOUT,
                               expected_message=msg)

            #
            # Exit the child
            #
            fork.exit()

        #
        # In parent
        # ---------
        # Send message
        #
        fork.sync()
        send_mpi_message(1, msg)
        fork.release()

        #
        # Release the child (to exit)
        #
        fork.wait()
Esempio n. 6
0
    def test04(self):
        """Verify simple MPI messaging from a (live) child process."""

        msg = MESSAGE1_indexed % random.randint(0, 255)

        register_mpi()

        fork = tfork2()
        if fork.isChild:
            #
            # In child
            #
            register_mpi()
            send_mpi_message(rank=0, message=msg)

            #
            # Wait for the parent to read message.
            #
            fork.release()
            fork.sync()

            #
            # Exit the child
            #
            fork.exit()

        #
        # In parent
        # ---------
        # Check received message
        #
        fork.sync()
        self.verifyMessage(rank=1, timeout=NULL_TIMEOUT, expected_message=msg)

        #
        # Release the child (to exit)
        #
        fork.release()
        fork.wait()
Esempio n. 7
0
    def test15(self):
        """Verify multiple timeouts."""

        CHILD_NUM = 10
        delta_times = [random.random() * 2 for i in range(CHILD_NUM)]
        sleep_times = [delta_times[0]]
        for i in range(1, CHILD_NUM):
            sleep_times.append(sleep_times[i - 1] + delta_times[i])
        timeout_time = int(sleep_times[-1] * 2)
        register_mpi()

        forks = []
        for i in range(CHILD_NUM):
            fork = tfork2()
            if fork.isChild:
                #
                # In child
                #
                register_mpi()

                #
                # Sync with the parent.
                # This is done so that the rank will be according to the
                # order of child creation
                #
                fork.release()
                fork.sync()

                #
                # Check the received message
                #
                self.verifyMessage(rank=0,
                                   timeout=timeout_time,
                                   expected_message=MESSAGE1_indexed % i,
                                   sleep_time=sleep_times[i])

                fork.exit()

            #
            # In parent
            #
            fork.sync()
            forks.append(fork)

        #
        # Release all childs
        #
        for fork in forks:
            fork.release()

        #
        # Send messages to all child processes
        #
        for i in range(CHILD_NUM):
            time.sleep(delta_times[i])
            send_mpi_message(i + 1, MESSAGE1_indexed % i)

        #
        # Wait for childs exit
        #
        for fork in forks:
            fork.wait()
Esempio n. 8
0
    def test11(self):
        """Test correct rank indexing."""

        #
        # Open several childs and register them
        #
        CHILD_NUM = 200

        forks = []
        for i in range(CHILD_NUM):
            fork = tfork2()
            if fork.isChild:
                #
                # In child, register in synchrnoized order.
                #
                fork.sync()
                rank = register_mpi()
                fork.send(str(rank))

                #
                # Sync with the parent.
                # This is done so that the rank will be according to the
                # order of child creation
                #
                fork.sync()
                fork.exit()

            #
            # In parent
            #
            forks.append(fork)

        #
        # Synchronized registration
        #
        ranks = []
        for fork in forks:
            fork.release()
            ranks.append(int(fork.receive()))

        #
        # Wait till all childs exit
        #
        for fork in forks:
            fork.release()
            fork.wait()

        #
        # Verify that the ranks are correctly indexed
        #
        self.assertEqual(
            ranks, range(CHILD_NUM),
            'The processes where rank not in order: %s' % str(ranks))

        #
        # verify that the rank index returns to 0
        #
        rank = register_mpi()
        self.assert_(
            rank == 0,
            'Expected reset of rank indexing. Assigned rank: %d' % rank)
Esempio n. 9
0
    def test10(self):
        """Verify error handling."""

        #
        # Try sending a message from a non registered process
        #
        self.errnoCheck(
            cmd=MPI.send_mpi_message,
            args=(0, MESSAGE1),
            expected_errno=errno.ESRCH,
            msg='Sending a message from a non registered process is not allowed'
        )

        fork = tfork2()
        if fork.isChild:
            #
            # In child
            # Sync with the parent.
            #
            fork.release()
            fork.sync()

            #
            # Try receiving by a non registered process
            #
            self.errnoCheck(
                cmd=MPI.receive_mpi_message,
                args=(0, NULL_TIMEOUT, DEFAULT_MESSAGE_SIZE),
                expected_errno=errno.ESRCH,
                msg=
                'Receiving a message by a non registered process is not allowed'
            )

            register_mpi()

            fork.exit()

        #
        # In parent
        #
        fork.sync()
        register_mpi()

        #
        # Try sending a message to a non existing rank
        #
        self.errnoCheck(cmd=MPI.send_mpi_message,
                        args=(1, MESSAGE1),
                        expected_errno=errno.ESRCH,
                        msg='Sending a message to a non existing rank')
        fork.release()

        #
        # Wait for the child to exit
        #
        fork.wait()

        #
        # Try sending a message to a terminated process
        #
        self.errnoCheck(cmd=MPI.send_mpi_message,
                        args=(1, MESSAGE1),
                        expected_errno=errno.ESRCH,
                        msg='Sending a message to a terminated process')

        #
        # Try receiving a non existing message (should cause a timeout)
        #
        self.errnoCheck(cmd=MPI.receive_mpi_message,
                        args=(0, NULL_TIMEOUT, DEFAULT_MESSAGE_SIZE),
                        expected_errno=errno.ETIMEDOUT,
                        msg='Cannot receive a non existing message')
Esempio n. 10
0
    def test09(self):
        """Verify multiple MPI messaging to multiple child processes."""

        CHILD_NUM = 200
        MSG_NUM = 1000
        msgs = [MESSAGE1_indexed % i for i in range(CHILD_NUM * MSG_NUM)]
        random.shuffle(msgs)

        register_mpi()

        forks = []
        for i in range(CHILD_NUM):
            fork = tfork2()
            if fork.isChild:
                #
                # In child
                #
                register_mpi()

                #
                # Sync with the parent.
                # This is done so that the rank will be according to the
                # order of child creation
                #
                fork.release()
                fork.sync()

                #
                # Check the received message
                #
                for j in range(i * MSG_NUM, (i + 1) * MSG_NUM):
                    self.verifyMessage(rank=0,
                                       timeout=NULL_TIMEOUT,
                                       expected_message=msgs[j])

                fork.exit()

            #
            # In parent
            #
            fork.sync()
            forks.append(fork)

        #
        # Send messages to all child processes
        #
        for i in range(CHILD_NUM):
            for j in range(i * MSG_NUM, (i + 1) * MSG_NUM):
                send_mpi_message(i + 1, msgs[j])

        #
        # Release all childs
        #
        for fork in forks:
            fork.release()

        #
        # Wait for childs exit
        #
        for fork in forks:
            fork.wait()