0

MPI_BYTE runs perfect on one cluster but throws an error on the other one. Is there any reason for this, as sizeof(bool)=1 BYTE and I like 1 BYTE to be reduced. here is the code

int main( int argcs, char *pArgs[] )
{

 MPI_Init( &argcs, &pArgs );

   int my_rank, comsize;

    MPI_Comm_rank( MPI_COMM_WORLD, &my_rank );

    MPI_Comm_size( MPI_COMM_WORLD, &comsize );

    bool sb=false;

    if(my_rank==comsize-1)
    {
      sb=true;
    }

    bool rb=true;

    MPI_Request request0;

    double t1;

    t1 = MPI_Wtime();

MPI_Iallreduce( &sb, &rb, sizeof(bool), MPI_BYTE, MPI_MAX, MPI_COMM_WORLD, &request0 );

    MPI_Wait( &request0, MPI_STATUS_IGNORE );

    double   t2 = MPI_Wtime(); 

     MPI_Finalize();
}
JimBamFeng
  • 709
  • 1
  • 4
  • 20

1 Answers1

2

I do not think the standard allows you to use MPI_BYTE with a C bool.

FWIW, in Fortran you can use MPI_LOGICAL.

Your statement sizeof(bool) == 1 is indeed incorrect, please refer to Is sizeof(bool) defined? for the details.

From my point of view, your program is incorrect and has hence an undefined behavior.

I am afraid you have to manually convert bool to byte in C, and then you can use MPI_BYTE.

Gilles Gouaillardet
  • 8,193
  • 11
  • 24
  • 30