Microsoft-MPI icon indicating copy to clipboard operation
Microsoft-MPI copied to clipboard

MPI_Isend() may send wrong data if its request has been freed

Open Piccions opened this issue 3 years ago • 0 comments

Freeing a request for an immediate send causes subsequent sends to reuse the same buffer even if the previous operation hasn't completed, leading to erroneous data being sent. I include a reproducer program that induces the bug.

#include <assert.h>
#include <mpi.h>

#define TRIGGER_BUG

int main(void)
{
	int thread_lvl = MPI_THREAD_SINGLE;
	MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, &thread_lvl);
	assert(thread_lvl >= MPI_THREAD_MULTIPLE);

	static const int one = 1;
	MPI_Request req_one;
	MPI_Isend(&one, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &req_one);
#ifdef TRIGGER_BUG
	MPI_Request_free(&req_one);
#endif

	static const int six = 6;
	MPI_Request req_six;
	MPI_Isend(&six, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &req_six);
#ifndef TRIGGER_BUG
	MPI_Request_free(&req_one);
#endif
	MPI_Request_free(&req_six);

	int recv_first = 0;
	MPI_Recv(&recv_first, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

	int recv_second = 0;
	MPI_Recv(&recv_second, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

	assert(recv_first + recv_second == 7);

	MPI_Finalize();
}

Piccions avatar Aug 07 '22 09:08 Piccions