简体   繁体   中英

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. Any help is appreciated.

Here is the lot of my messages in 1 master + 1 slave situation. 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()中的另一个缓冲区。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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