简体   繁体   English

MPI没有收到与阻止发送/接收时发送的缓冲区相同的缓冲区

[英]MPI not receiving the same buffer I sent with blocking send/recv

I am not receiving the same buffer I sent. 我没有收到与发送相同的缓冲区。 Even with blocking Send/Recv. 即使阻止发送/接收。 I use contigously allocated buffers. 我使用连续分配的缓冲区。

I basically change the 1st row in that buffer in every message. 我基本上在每个消息中都更改了该缓冲区中的第一行。 The buffer with a change is OK after send by the master, but it's wrong after I receive it in a slave. 由主机发送后,具有更改的缓冲区可以,但是在从属设备中接收到缓冲区后,它是错误的。

I have already spent more than 15 hours on this. 我已经花了15多个小时。 Any help is appreciated. 任何帮助表示赞赏。

Here is the lot of my messages in 1 master + 1 slave situation. 这是我在1个主控+ 1个从属情况下的许多消息。 Notice how the 1st line at master changes but rest of the buffer remains the same. 注意主节点上的第一行如何更改,但缓冲区的其余部分保持不变。 At slave's side the rest of the buffer changes too. 在从站侧,其余缓冲区也将更改。 There it is: log messages 它是: 日志消息

size_t order = 0;
floattype **getWork(floattype **work, floattype **tmatrix)
{
     size_t tmp = 1;

     // leading row
     work[0] = tmatrix[order++];

     // get needed rows
     for(size_t row = 1; row < 5; row++)
     {
          work[tmp++] = tmatrix[row];
     }

     return work;
 }


void master(size_t chunksize, floattype **extendedmatrix, size_t paramcount, size_t rowcount)
{
     int ntasks, node;
     size_t reply;
     floattype **tmatrix = transponeMatrix(extendedmatrix, paramcount, rowcount);
     floattype **work = AllocMatrix(rowcount, chunksize + 1);


     MPI_Status status;
     MPI_Comm_size(MPI_COMM_WORLD, &ntasks);


     // init all slaves
     for (node = 1; node < ntasks; ++node) 
     {      
          getWork(work, tmatrix);

          MPI_Send(work[0], 32, MPI_DOUBLE, node, WORKTAG, MPI_COMM_WORLD);
     }

     size_t rpt = 0;

     while (rpt < 3) 
     {
        rpt++;
        MPI_Recv(&reply, 1, MPI_UNSIGNED_LONG, MPI_ANY_SOURCE, INFOTAG, MPI_COMM_WORLD, &status); 

        getWork(work, tmatrix);

        MPI_Send(work[0], 32, MPI_DOUBLE, status.MPI_SOURCE, WORKTAG, MPI_COMM_WORLD);  
     }
 }

void slave(size_t chunksize, size_t paramcount, size_t rowcount)
{
    floattype **received = AllocMatrix(rowcount, chunksize + 1);
        size_t reply = 0;

    MPI_Status status;

    while (true) {
         MPI_Recv(received[0], 32, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);

         // lets finish
         if (status.MPI_TAG == DIETAG) {
             FreeMatrix(received);

             return;
         }


         MPI_Send(&reply, 1, MPI_UNSIGNED_LONG, 0, INFOTAG, MPI_COMM_WORLD);
    }

}

错误的内存分配...应该使用memcpy()将内存块从一个缓冲区复制到getWork()中的另一个缓冲区。

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

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