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: http://www.open-mpi.org/community/lists/users/2012/02/18383.php

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 node

    // 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 + i, MPI_COMM_WORLD);           
                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, MPI_COMM_WORLD, &Stat);
            // 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