Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: [OMPI users] recv hangs up when iptables is enabled
From: jiakai (jia.kai66_at_[hidden])
Date: 2012-08-09 07:02:44

Hi all,
I encountered a strange problem: when running across nodes, the first
send/recv pairs work, but the second recv blocks indefinitely.

After some google, I found this:

I use my laptop as a wireless router, and I NAT all traffic from wlan0
to eth0 using iptables. After clearing all rules in iptables, the
problem gets solved.

Has anyone also had the same problem? Do you have any idea what causes this?

Test program:
#include <stdio.h>
#include <stdlib.h>

#include <mpi.h>

int main(int argc, char *argv[])
    const int MASTER = 0;
    const int TAG_GENERAL = 1;

    int i;
    int numTasks;
    int rank;
    int source;
    int dest;
    int rc;
    int count;
    int dataWaitingFlag;

    char inMsg;
    char outMsg;

    MPI_Status Stat;

    // Initialize the MPI stack and pass 'argc' and 'argv' to each slave

    // Gets number of tasks/processes that this program is running on
    MPI_Comm_size(MPI_COMM_WORLD, &numTasks);

    // Gets the rank (process/task number) that this program is running on
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    // If the master node
    if (rank == MASTER) {

        // Ssend out messages to all the sub-processes
        for (dest = 1; dest < numTasks; dest++) {
            outMsg = rand() % 256; // Generate random message to send
to slave nodes

            // Ssend a message to the destination
            for (i = 0; i < 5; i ++)
                rc = MPI_Ssend(&outMsg, 1, MPI_CHAR, dest, TAG_GENERAL +
                printf("Task %d: Sent message %d to task %d with tag %d\n",
                        rank, outMsg, dest, TAG_GENERAL + i);


    // Else a slave node
    else {
        // Wait until a message is there to be received

        // Get the message and put it in 'inMsg'
        for (i = 0; i < 5; i ++)
            rc = MPI_Recv(&inMsg, 1, MPI_CHAR, MASTER, TAG_GENERAL + i,
            // Get how big the message is and put it in 'count'
            rc = MPI_Get_count(&Stat, MPI_CHAR, &count);

            printf("Task %d: Received %d char(s) (%d) from task %d with
tag %d \n",
                    rank, count, inMsg, Stat.MPI_SOURCE, Stat.MPI_TAG);



???????? ?14?
Kai Jia
Dept. of Computer Science & Technology
Tsinghua University