/* test of communication methods in MPI */ #include "mpi.h" #include #include using namespace std; int main(int argc, char **argv) { char in[1]; // Send 1 character at a time int out; // Interprete as an integer int numprocs; int myid; int i; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); if(myid == 0) { cout << "We have " << numprocs << " processors" << endl; MPI_Recv(&out, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, NULL); cout << "Received this number from proc 1: " << out << endl; char *p = (char *) &out; printf("The ASCII codes of the 4 characters in out are: %u %u %u %u\n", p[0], p[1], p[2], p[3]); } else if ( myid == 1 ) { in[0] = '2'; MPI_Send(&in, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD); // out = 4; // MPI_Send(&out, 1, MPI_INT, 0, 0, MPI_COMM_WORLD); } MPI_Finalize(); }