15 MPI_Comm_rank(icomm, &myrank);
16 MPI_Comm_size(icomm, &numprocs);
17 char *name =
new char [MPI_MAX_PROCESSOR_NAME],
18 *chbuf =
new char [MPI_MAX_PROCESSOR_NAME];
21 MPI_Get_processor_name( name, &reslen);
24 cout <<
" " << myrank <<
" runs on " << name << endl;
25 for (
int i = 1; i < numprocs; ++i) {
29 ierr = MPI_Recv(chbuf, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, icomm, &stat);
32 cout <<
" " << stat.MPI_SOURCE <<
" runs on " << chbuf;
34 MPI_Get_count(&stat, MPI_CHAR, &count);
35 cout <<
" (length: " << count <<
" )" << endl;
41 ierr = MPI_Send(name, strlen(name) + 1, MPI_CHAR, dest, myrank, icomm);
53 MPI_Comm_rank(icomm, &myrank);
54 MPI_Comm_size(icomm, &numprocs);
55 string name(MPI_MAX_PROCESSOR_NAME,
'#'),
56 recvbuf(MPI_MAX_PROCESSOR_NAME,
'#');
59 MPI_Get_processor_name(name.data(), &reslen);
63 cout <<
" " << myrank <<
" runs on " << name << endl;
64 for (
int i = 1; i < numprocs; ++i) {
68 ierr = MPI_Recv(recvbuf.data(), MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, icomm, &stat);
72 MPI_Get_count(&stat, MPI_CHAR, &count);
73 string const chbuf(recvbuf,0,count);
74 cout <<
" " << stat.MPI_SOURCE <<
" runs on " << chbuf;
75 cout <<
" (length: " << count <<
" )" << endl;
81 ierr = MPI_Send(name.data(), name.size(), MPI_CHAR, dest, myrank, icomm);