How it works...

According to the MPI execution model, our application consists of N (5 in this example) autonomous processes, each with their own local memory able to communicate data through the exchange of messages.

The communicator defines a group of processes that can communicate with each other. The MPI_COMM_WORLD work used here is the default communicator and includes all processes.

The identification of a process is based on ranks. Each process is assigned a rank for each communicator to which it belongs. The rank is an integer that is assigned, which starts from zero and identifies each individual process in the context of a specific communicator. The common practice is to define the process with a global rank of 0 as the master process. Through the rank, the developer can specify what the sending process is and what the recipient processes are instead.

It should be noted that, for illustration purposes only, the stdout output will not always be ordered, as multiple processes can apply at the same time by writing on the screen and the OS arbitrarily chooses the order. So, we are ready for a fundamental observation: every process involved in the execution of MPI runs the same compiled binary, so each process receives the same instructions to be executed.

To execute the code, type the following command line:

C:>mpiexec -n 5 python helloworld_MPI.py 

This is the result that we will get after executing this code (notice how the order of execution of the processes is not sequential):

hello world from process  1 
hello world from process  0 
hello world from process  2 
hello world from process  3
hello world from process  4
It should be noted that the number of processes to be used is strictly dependent on the characteristics of the machine on which the program must run.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.184.90