simple implementation of all to all communication using send/recv @ 12/23/2010

programming & research
I was writing a Pregel framework for SCC when I encountered the problem of all to all communication. I used RCCE communication library as the underlying communication. However, RCCE provides very limited functionality, not much aside from blocking send/recv actually. Pregel requires all to all communication to exchange the messages sent from vertexes. That's why I started searching for a way to implement all to all communication using send/recv.

After googling for a while, I find that most of the algorithms are just too complex for me. So I dug into the RCCE_Comm library, which provides a RCCE_Alltoall function to perform all to all communication on fixed size data structures. The code seems very straightforward, and I gladly used the same algorithm in my implementation.

Here is the code snippets:

    int np=get_num_workers();
    int me=get_worker_id();
    for(int i=0;i<np;i++){
        int partner=(i-me+np)%np;
        if( me!=partner ){
            if( me<partner ){
                send( send_buf, send_size, partner );
                recv( recv_buf, recv_size, partner );
            }
            else{
                recv( recv_buf, recv_size, partner ); 
                send( send_buf, send_size, partner );           
            }
        }
    }

发布于 12/23/2010 18:49:08 | 评论:0

看帖要回帖...