Open MPI logo

Open MPI User's Mailing List Archives

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

Subject: Re: [OMPI users] OpenMPI how large its buffer size ?
From: Jack Bryan (dtustudy68_at_[hidden])
Date: 2010-07-10 22:19:01


Hi,
thanks for the program from Jody.
David indicated the question that I want to ask.
But, Jody's approach is ok when the MPI built-in buffer size is large enough to hold the message such as 100kB in the buffer.
In asynchronous communication, when the sender posts a mpi_isend, the message is put in a buffer provided by the MPI.
At this point, the receiver may still not post its corresponding mpi_irecv. So, the buffer size is important here.
Without knowing the buffer size, I may get " truncate error " on Open MPI.
How to know the size of the buffer automatically created by Open MPI in the background ?
Any help is appreciated.
Jack,
July 10 2010
From: solarbikedz_at_[hidden]
Date: Sat, 10 Jul 2010 16:46:12 -0700
To: users_at_[hidden]
Subject: Re: [OMPI users] OpenMPI how large its buffer size ?

I believe his question is regarding when under non-blocking send/recv, how does MPI know how much memory to allocate to receive the message, since the size is determined AFTER the irecv is posted. So if the send post isend, but the receiver hasn't post irecv, what would the MPI do with the message.

I believe MPI would automatically create a buffer in the background to store the message.

On Sat, Jul 10, 2010 at 1:55 PM, jody <jody.xha_at_[hidden]> wrote:

Perhaps i misunderstand your question...

Generally, it is the user's job to provide the buffers both to send and receive.

If you call MPI_Recv, you must pass a buffer that is large enough to

hold the data sent by the

corresponding MPI_Send. I.e., if you know your sender will send

messages of 100kB,

then you must provide a buffer of size 100kB to the receiver.

If the message size is unknown at compile time, you may have to send

two messages:

first an integer which tells the receiver how large a buffer it has to

allocate, and then

the actual message (which then nicely fits into the freshly allocated buffer)

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#include "mpi.h"

#define SENDER 1

#define RECEIVER 0

#define TAG_LEN 77

#define TAG_DATA 78

#define MAX_MESSAGE 16

int main(int argc, char *argv[]) {

    int num_procs;

    int rank;

    int *send_buf;

    int *recv_buf;

    int send_message_size;

    int recv_message_size;

    MPI_Status st;

    int i;

    /* initialize random numbers */

    srand(time(NULL));

    MPI_Init(&argc, &argv);

    MPI_Comm_size(MPI_COMM_WORLD, &num_procs);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (rank == RECEIVER) {

        /* the receiver */

        /* wait for message length */

        MPI_Recv(&recv_message_size, 1, MPI_INT, SENDER, TAG_LEN,

MPI_COMM_WORLD, &st);

        /* create a buffer of the required size */

        recv_buf = (int*) malloc(recv_message_size*sizeof(int));

        /* get data */

        MPI_Recv(recv_buf, recv_message_size, MPI_INT, SENDER,

TAG_DATA, MPI_COMM_WORLD, &st);

        printf("Receiver got %d integers:", recv_message_size);

        for (i = 0; i < recv_message_size; i++) {

            printf(" %d", recv_buf[i]);

        }

        printf("\n");

        /* clean up */

        free(recv_buf);

    } else if (rank == SENDER) {

        /* the sender */

        /* random message size */

        send_message_size = (int)((1.0*MAX_MESSAGE*rand())/(1.0*RAND_MAX));

        /* create a buffer of the required size */

        send_buf = (int*) malloc(send_message_size*sizeof(int));

        /* create random message */

        for (i = 0; i < send_message_size; i++) {

            send_buf[i] = rand();

        }

        printf("Sender has %d integers:", send_message_size);

        for (i = 0; i < send_message_size; i++) {

            printf(" %d", send_buf[i]);

        }

        printf("\n");

        /* send message size to receiver */

        MPI_Send(&send_message_size, 1, MPI_INT, RECEIVER, TAG_LEN,

MPI_COMM_WORLD);

        /* now send messagge */

        MPI_Send(send_buf, send_message_size, MPI_INT, RECEIVER,

TAG_DATA, MPI_COMM_WORLD);

        /* clean up */

        free(send_buf);

    }

    MPI_Finalize();

}

I hope this helps

  Jody

On Sat, Jul 10, 2010 at 7:12 AM, Jack Bryan <dtustudy68_at_[hidden]> wrote:

> Dear All:

> How to find the buffer size of OpenMPI ?

> I need to transfer large data between nodes on a cluster with OpenMPI 1.3.4.

> Many nodes need to send data to the same node .

> Workers use mpi_isend, the receiver node use mpi_irecv.

> because they are non-blocking, the messages are stored in buffers of

> senders.

> And then, the receiver collect messages from its buffer.

> If the receiver's buffer is too small, there will be truncate error.

> Any help is appreciated.

> Jack

> July 9 2010

>

> ________________________________

> Hotmail is redefining busy with tools for the New Busy. Get more from your

> inbox. See how.

> _______________________________________________

> users mailing list

> users_at_[hidden]

> http://www.open-mpi.org/mailman/listinfo.cgi/users

>

_______________________________________________

users mailing list

users_at_[hidden]

http://www.open-mpi.org/mailman/listinfo.cgi/users

-- 
David Zhang
University of California, San Diego
 		 	   		  
_________________________________________________________________
Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1