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 43 44
|
#include <stdio.h>
#include <mpi.h>
#include <iostream>
#include<vector>
#include <iterator>
#include <algorithm>
using namespace::std;
int main( int argc, char* argv[])
{vector<char> c(17);
MPI_Status status;
// Initialisation
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD,&rang);
if ( rang == 0) {
MPI_Recv(&c[0], 17, MPI_CHAR , MPI_ANY_SOURCE,MPI_ANY_TAG, MPI_COMM_WORLD,&status);
string s=&c[0];
cout<<s.c_str()<<endl;
}
else if(rang==1)
{
string leopard("salut");
string leopard2("toto");
string leopard3("tata");
vector<char> buffer;
std::copy(leopard.begin(),leopard.end(), std::back_inserter(buffer));
buffer.push_back('\0');
std::copy(leopard2.begin(),leopard2.end(), std::back_inserter(buffer));
buffer.push_back('\0');
std::copy(leopard3.begin(),leopard3.end(), std::back_inserter(buffer));
buffer.push_back('\0');
buffer.push_back('\0');
MPI_Send(&buffer, buffer.size(), MPI_CHAR , 0,1, MPI_COMM_WORLD);
}
} |