Example
main(int argc, char* argv[]) {
MPI_Comm io_comm; /* I/O Communicator*/
int IO_KEY; /* I/O attribute key */
int* io_rank_ptr; /* Attributes are ptrs */
void* extra_arg; /* Unused */
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD,
/* Get a separate communicator for I/O fcts */
MPI_Comm_dup(MPI_COMM_WORLD,
/* Create the attribute key */
MPI_Keyval_create(MPI_DUP_FN,
MPI_NULL_DELETE_FN, &IO_KEY,
/* Allocate storage for the attribute content */
io_rank_ptr = (int*) malloc(sizeof(int));
/* Set the attribute content */
/* Cache the attribute with io_comm */
MPI_Attr_put(io_comm, IO_KEY, io_rank_ptr);
/* Retrieve the I/O process rank */
MPI_Attr_get(io_comm, IO_KEY,
/* If flag == 0, something went wrong: */
/* there's no attribute cached. */
if ((flag != 0) && (my_rank == *io_rank_attr)) {
printf("Greetings from the I/O Process!\n");
printf("My rank is %d\n", *io_rank_attr);