I've discovered an MPI communicator called MPI_COMM_SELF. The problem is, I don't know, when is it useful. It appears to me, that just every process "thinks" about itself as root.
Could you explain me how does MPI_COMM_SELF
exactly work and in which situations is it useful?
I've found this slide-show, but the communicator is only briefly mentioned there.
I've tried this "Hello, world" example and all processes returned 0 as their PID.
#include <mpi.h>
#include <stdio.h>
int main() {
MPI_Init(NULL, NULL);
int world_rank;
MPI_Comm_rank(MPI_COMM_SELF, &world_rank);
printf("Hello, my PID is %d!\n",
world_rank);
MPI_Finalize();
return 0;
}
An MPI communicator is two pieces of information: a collection of processes, and a context for that collection. The defaulit communicators are MPI_COMM_WORLD -- every process -- and MPI_COMM_SELF -- just one process.
you can make more communicators with all, one, or some processes.
Why is context important? think libraries. A library using MPI could conflict with the client of that library, except a library will duplicate the communicator and thereby create a context where the library can communicate and never need to worry about what the client is doing.
MPI_COMM_SELF is a single process. If you call a collective routine, all processes in the communicator must participate.
MPI_COMM_SELF is particularly useful to MPI-IO routines, but only if you want "file per process". If you are sharing a file with multiple MPI processes (and you probably should do so), use a communicator encompassing those MPI processes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With