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: jody (jody.xha_at_[hidden])
Date: 2010-07-10 16:55:30

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 */
    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,
        /* 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,

        printf("Receiver got %d integers:", recv_message_size);
        for (i = 0; i < recv_message_size; i++) {
            printf(" %d", recv_buf[i]);

        /* clean up */

    } 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]);

        /* send message size to receiver */
        MPI_Send(&send_message_size, 1, MPI_INT, RECEIVER, TAG_LEN,
        /* now send messagge */
        MPI_Send(send_buf, send_message_size, MPI_INT, RECEIVER,

        /* clean up */



I hope this helps

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]