Search code examples
c++openmpi

how can i solve an error with MPI_Ssend with producer and consumer problem


So i need to solve the problem of multiple producer and consumers using open mpi. The compiler says that there are an error in MPI_Ssend, but where? (id_buffer == 4)

Error description

void funcion_productor(int productor_i)
{ 
  int b = 4;
  for ( unsigned int i= 0 ; i < num_items ; i++ )
  {
    // producir valor
    int valor_prod = producir(productor_i);
    // enviar valor
    cout << "Productor " << productor_i << " va a enviar valor " << 
    valor_prod << endl << flush;
    MPI_Ssend( &valor_prod, 1, MPI_INT, id_buffer, 0, MPI_COMM_WORLD );
    }
}

Solution

  • This is a very basic error, and obvious from the error message and the documentation (https://www.mpich.org/static/docs/v3.2/www3/MPI_Ssend.html).

    You have 3 processes, but your are sending to rank 4 (id_buffer) (so you should have at least 5 processes). Obviously a failure in your logic of receiver selection.