相关疑难解决方法(0)

MPI_ERR_TRUNCATE:广播

int打算从root(rank==(FIELD=0))广播.

int winner

if (rank == FIELD) {
    winner = something;
}

MPI_Barrier(MPI_COMM_WORLD);
MPI_Bcast(&winner, 1, MPI_INT, FIELD, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
if (rank != FIELD) {
    cout << rank << " informed that winner is " << winner << endl;
}
Run Code Online (Sandbox Code Playgroud)

但似乎我得到了

[JM:6892] *** An error occurred in MPI_Bcast
[JM:6892] *** on communicator MPI_COMM_WORLD
[JM:6892] *** MPI_ERR_TRUNCATE: message truncated
[JM:6892] *** MPI_ERRORS_ARE_FATAL: your MPI job will now abort
Run Code Online (Sandbox Code Playgroud)

发现我可以增加缓冲区大小 Bcast

MPI_Bcast(&winner, NUMPROCS, MPI_INT, FIELD, MPI_COMM_WORLD);
Run Code Online (Sandbox Code Playgroud)

NUMPROCS运行进程的数量在哪里.(实际上我觉得我只需要它2).然后它运行,但给出意想不到的输出......

1 …
Run Code Online (Sandbox Code Playgroud)

c++ mpi openmpi

5
推荐指数
1
解决办法
8603
查看次数

使用MPI_Bcast发送动态大小的动态数组

OpenMPI:我想读取根节点上的文件,并将该文件的内容发送到所有其他节点.我发现MPI_Bcast可以做到:

int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype,
    int root, MPI_Comm comm)
Run Code Online (Sandbox Code Playgroud)

我发现的所有示例都具有count已知值,但在我的情况下,计数值主要在根上已知.其他示例表示MPI_Bcast的相同调用检索其他节点上的数据.

我添加了这个:

typedef short Descriptor[128];
MPI_Datatype descriptorType;
MPI_Type_contiguous(sizeof(Descriptor), MPI_SHORT, &descriptorType);
MPI_Type_commit(&descriptorType);



 if(world_rank == 0)   {
  struct stat finfo;

  if(stat(argv[1], &finfo) == 0) {
        querySize = finfo.st_size/sizeof(Descriptor);
  }

 {
  //read binary query
  queryDescriptors = new Descriptor[querySize];
  fstream qFile(argv[1], ios::in | ios::binary);
  qFile.read((char*)queryDescriptors, querySize*sizeof(Descriptor));
  qFile.close();

  }
}

  MPI_Bcast((void*)&querySize, 1, MPI_INT, 0, MPI_COMM_WORLD);
  if (world_rank != 0)
  {
        queryDescriptors = new Descriptor[querySize];
  }
  MPI_Bcast((void*)queryDescriptors, querySize, descriptorType, 0, …
Run Code Online (Sandbox Code Playgroud)

c++ mpi

5
推荐指数
1
解决办法
2367
查看次数

标签 统计

c++ ×2

mpi ×2

openmpi ×1