Ticket #2991: bool_bcast.cpp

File bool_bcast.cpp, 732 bytes (added by micdestefano@…, 13 years ago)

Test program that demonstrates the bug and its possible solution

Line 
1#include <iostream>
2#include <boost/mpi/communicator.hpp>
3#include <boost/mpi/collectives.hpp>
4
5using namespace std;
6using namespace boost::mpi;
7
8int main(int argc,char *argv[]) {
9
10 environment env(argc, argv);
11 communicator world;
12
13 bool test(true);
14
15 if (world.rank() == 0) test = false;
16
17#ifndef LEAK_WORKAROUND
18 broadcast(world,test,0);
19#else
20 MPI_Datatype type;
21 BOOST_MPI_CHECK_RESULT(MPI_Type_contiguous,(sizeof(bool),MPI_BYTE,&type));
22 BOOST_MPI_CHECK_RESULT(MPI_Type_commit,(&type));
23 BOOST_MPI_CHECK_RESULT(MPI_Bcast,(reinterpret_cast<void*>(test),1,type,0,world));
24 BOOST_MPI_CHECK_RESULT(MPI_Type_free,(&type));
25#endif
26
27 cout << "\nrank " << world.rank() << ": test = " << test << endl;
28
29 return EXIT_SUCCESS;
30}