Skip to content

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

@Piccions

Description

@Piccions

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions