简体   繁体   English

缓冲区大小大于Mpi_send中的计数

[英]Buffer size larger than count in Mpi_send

This may be a trivial thing but: 这可能是一件微不足道的事情,但是:

May the size of an underlying array be longer than the count argument send along with the buffer pointer in a MPI_Send( ... ) call? 在MPI_Send(...)调用中,底层数组的大小是否可能比count参数和缓冲区指针一起发送?

As for MPI_Recv( ... ) I've found sources that clearly state that this is legitimate (ie, the buffer is larger than the message). 至于MPI_Recv(...)我发现了明确说明这是合法的来源(即缓冲区大于消息)。

Plus, it seems to be OK when I compile and run the below program 另外,当我编译并运行以下程序时似乎没问题

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mpi.h>

int main(int argc, char **argv){
  int i;

  MPI_Init(&argc, &argv);

  int world_rank;
  MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
  if( world_size != 2 ) {
    printf("You're supposed to use exactly 2 processes, dude!\n");
    MPI_Abort( MPI_COMM_WORLD, 0 );
  }

  int *ids = (int*)( malloc( 10*sizeof(int) ) );

  if( world_rank == 0 ) {
    for( i=0; i<10; i++)
      ids[i]=i+1;
    MPI_Send( ids, 5, MPI_INT, 1, 0, MPI_COMM_WORLD);
  }else{
    for( i=0; i<10; i++)
      ids[i]=20-i;
    MPI_Recv( ids, 5, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  }
  for( i=0; i<10; i++)
    printf("me %d   %d %d\n",world_rank,i,ids[i]);

  free(ids);

  MPI_Finalize();

  return 0;
}

because I get following output with no error messages: 因为我得到以下输出,没有错误消息:

me 0   0 1
me 0   1 2
me 0   2 3
me 0   3 4
me 0   4 5
me 0   5 6
me 0   6 7
me 0   7 8
me 0   8 9
me 0   9 10
me 1   0 1
me 1   1 2
me 1   2 3
me 1   3 4
me 1   4 5
me 1   5 15
me 1   6 14
me 1   7 13
me 1   8 12
me 1   9 11

But I'd like to have reassurance because I'm still a newbie... 但是我想要保证,因为我还是个新手......

Since you are passing a buffer to MPI_Send and telling it how big the buffer is, the buffer is whatever size you say it is. 由于您正在将缓冲区传递给MPI_Send并告诉它缓冲区有多大,因此缓冲区的大小与您说的大小MPI_Send If you want to cut a big buffer into smaller buffers, that's your business. 如果你想将一个大缓冲区切成较小的缓冲区,这就是你的业务。 MPI_Send has no way to tell how you managed to allocate or create the buffer you're passing to it, and it doesn't care. MPI_Send没有办法告诉你如何设置分配或创建你传递给它的缓冲区,它并不关心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM