1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
mpi::communicator world;
int receiveInt()
{
while(1==1){
int i;
world.recv(0,0,i);
cout<<"int "<<i<<endl;
}
}
int receiveStr()
{
while(1==1){
string str;
world.recv(0,1,str);
cout<<"str "<<str<<endl;
}
}
int main(int argc, char* argv[])
{
mpi::environment env(argc, argv);
if (world.rank() == 0) {
int i=0;
while(1==1)
{
i++;
sleep(1);
world.send(1,0,i);
string str = "Hello world!";
world.send(1,1,str);
i++;
}
}
else
{
boost::thread thrd1(receiveInt);
boost::thread thrd2 (receiveStr);
thrd2.join();
thrd1.join();
}
} |
Partager