C MPI-发送和接收的数据之间的差异

C MPI-发送和接收的数据之间的差异,c,parallel-processing,mpi,communication,libpng,C,Parallel Processing,Mpi,Communication,Libpng,我正在使用MPI编写一个应用程序,其中主节点必须向从节点发送部分图像(使用libpng读取)。我编写了以下代码来分发 行: int num_rows_per_process=ceil((浮动)高度)/大小; 如果(秩==0) { //将块发送到其他节点 对于(int i=1;我只是一个建议,使用MPI_bcasta很容易实现这一点。您确定每个进程的行数对于所有进程都是相等的吗?如果图像大小不能被n整除,进程数会怎样? int num_rows_per_process = ceil(((float

我正在使用MPI编写一个应用程序,其中主节点必须向从节点发送部分图像(使用libpng读取)。我编写了以下代码来分发 行:

int num_rows_per_process=ceil((浮动)高度)/大小;
如果(秩==0)
{
//将块发送到其他节点

对于(int i=1;我只是一个建议,使用MPI_bcasta很容易实现这一点。您确定每个进程的行数对于所有进程都是相等的吗?如果图像大小不能被n整除,进程数会怎样?
int num_rows_per_process = ceil(((float)height)/size);

if(rank == 0)
{
    //Send the chunks to the other nodes
    for(int i=1;i<size;i++)
    {
        int y;
        for(y=0;y<num_rows_per_process;y++)
        {
            int row_index = i*num_rows_per_process+y;
            if(row_index >= height)
                break;
            MPI_Send(row_pointers[row_index], width, MPI_UNSIGNED_CHAR, i, row_index, MPI_COMM_WORLD);
        }
    }
}
else
{
    //Figure out how many rows will I get
    row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * num_rows_per_process); //For the other processes, these are sub rows
    for(int y=0;y<num_rows_per_process;y++)
        {
            int row_index = rank*num_rows_per_process+y;
            if(row_index >= height)
            {
                row_pointers[row_index] = NULL;
                continue;
            }
            row_pointers[y] = (png_byte*) malloc(row_bytes);
            MPI_Recv(row_pointers[y], width, MPI_UNSIGNED_CHAR, 0, row_index, MPI_COMM_WORLD, &status);
        }
}


MPI_Barrier(MPI_COMM_WORLD);