Skip to content

Partitioned communications hang #12969

Open
@ggouaillardet

Description

@ggouaillardet

This issue was initially reported on Stack Overflow at https://stackoverflow.com/questions/79258925/openmpi5-partitioned-communication-with-multiple-neighbors

With the main branch, the following program running on 3 MPI tasks hang:

#include <mpi.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char *argv[]) {
  MPI_Init(&argc, &argv);
  int rank, size;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  if (size != 3) {
    if (rank == 0)
      printf("Need 3 workers, you have %d\n", size);
    return -1;
  }
/*
 *   Topology
 *     0 <-> 1 <-> 2
 *     */
  const int partitions = 1;
  const int count = 16;
  int buffer[partitions * count];
  MPI_Request request[2];

  memset(buffer, 0, sizeof(int) * partitions * count);
  if (rank == 1) {
    for (int i = 0; i < partitions * count; i++) {
      buffer[i] = i;
    }
  }

  int nor = 0;
  if (rank == 0) {
    MPI_Precv_init(buffer, partitions, count, MPI_INT, 1, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &request[nor++]);
  } else if (rank == 1) {
    MPI_Psend_init(buffer, partitions, count, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &request[nor++]);
    MPI_Psend_init(buffer, partitions, count, MPI_INT, 2, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &request[nor++]);
  } else if (rank == 2) {
    MPI_Precv_init(buffer, partitions, count, MPI_INT, 1, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &request[nor++]);
  }
  MPI_Startall(nor, request);

  if (rank == 1) {
    MPI_Pready(0, request[0]);
    MPI_Pready(0, request[1]);
  }

  MPI_Waitall(nor, request, MPI_STATUS_IGNORE);

  MPI_Barrier(MPI_COMM_WORLD);
  for (int i = 0; i < nor; i++) {
    MPI_Request_free(request + i);
  }
  MPI_Finalize();
  return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions