Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MPI_Scatter()错误_C_Mpi_Openmpi - Fatal编程技术网

MPI_Scatter()错误

MPI_Scatter()错误,c,mpi,openmpi,C,Mpi,Openmpi,我有一个串行代码,我正试图使用MPI将其转换为并行代码。但是,我似乎无法让MPI\u Scatter()函数在不崩溃的情况下正常工作。该函数在名为cells的数组上循环,并修改一些值 以下是原始序列号: int accelerate_flow(const t_param params, t_speed* cells, int* obstacles) { register int ii,jj; /* generic counters */ register float w1,w2;

我有一个串行代码,我正试图使用MPI将其转换为并行代码。但是,我似乎无法让
MPI\u Scatter()
函数在不崩溃的情况下正常工作。该函数在名为
cells
的数组上循环,并修改一些值

以下是原始序列号:

int accelerate_flow(const t_param params, t_speed* cells, int* obstacles)
{
  register int ii,jj;     /* generic counters */
  register float w1,w2;  /* weighting factors */
  /* compute weighting factors */
  w1 = params.density * params.accel * oneover9;
  w2 = params.density * params.accel * oneover36;

  int i;

  /* modify the first column of the grid */
  jj=0;

  for(ii=0;ii<params.ny;ii++)
  {

      if( !obstacles[ii*params.nx] && (cells[ii*params.nx].speeds[3] > w1 &&
          cells[ii*params.nx].speeds[6] > w2 && cells[ii*params.nx].speeds[7] > w2))  
      {
          /* increase 'east-side' densities */
          cells[ii*params.nx].speeds[1] += w1;
          cells[ii*params.nx].speeds[5] += w2;
          cells[ii*params.nx].speeds[8] += w2;
         /* decrease 'west-side' densities */
         cells[ii*params.nx].speeds[3] -= w1;
         cells[ii*params.nx].speeds[6] -= w2;
         cells[ii*params.nx].speeds[7] -= w2;
      }
  }

return EXIT_SUCCESS;

}
params.nx=300
params.ny=200


非常感谢您的帮助。谢谢。

MPI\u Scatter的第一个count参数是要发送到每个进程的元素数,而不是总数。这里,发送计数和接收计数将是相同的,并且将是nx×ny/ntasks;所以你会有

int count=params.nx*params.ny/ntasks;

MPI_Scatter(cells,    sizeof(t_speed)*count, MPI_BYTE, 
            recvCells,sizeof(t_speed)*count, MPI_BYTE, 0, MPI_COMM_WORLD);

请注意,只有当ntasks将nx*ny平均分割时,这才有效,否则您必须使用
Scatterv

非常感谢,这只是散射和聚集的一个简单大小错误。
typedef struct {
float speeds[NSPEEDS];
} t_speed;
int count=params.nx*params.ny/ntasks;

MPI_Scatter(cells,    sizeof(t_speed)*count, MPI_BYTE, 
            recvCells,sizeof(t_speed)*count, MPI_BYTE, 0, MPI_COMM_WORLD);