Programming Taskbook


E-mail:

Password:

User registration   Restore password

Russian

SFedU SMBU

1100 training tasks on programming

©  M. E. Abramyan (Southern Federal University, Shenzhen MSU-BIT University), 1998–2024

 

PT for MPI-2 | Solution example | Basic concepts

PrevNext


Basic concepts of the MPI programming

Let’s start our introduction to parallel programming with the following simple task from the first group named MPI1Proc. This will allow us not only to get acquainted with the basic concepts of parallel programming based on message passing, but also allow to explore the features of the Programming Taskbook related to data input/output as well as debugging output.

MPI1Proc2. Input an integer A in each process of the MPI_COMM_WORLD communicator and output doubled value of A. Also output the total number of processes in the master process (that is, a rank-zero process). For data input and output use the input-output stream pt. In the master process, duplicate the data output in the debug section by displaying on separate lines the doubled value of A and the total number of processes (use two calls of the ShowLine function, which is defined in the taskbook along with the Show function).

The task formulation includes some basic notions of the MPI programming. While parallel running, some instances of executable file are launched. Each launched instance create a single process that can interact with other processes through messaging. MPI functions provide a variety of tools for the implementation of such interaction (the MPI abbreviation stands for "Message Passing Interface"). To identify each process in the process group the concept of rank is used. The rank of the process is a zero-based order number of the process in the process group. Thus, the first process has a rank 0, and the last process has a rank K – 1, where K is the number of processes in the group (called the size of the process group). The process group may include all or some running processes of parallel program.

A special object of the MPI library called a communicator is associated with any process group. Any process interaction is possible only through some communicator. Standard communicator containing all processes of parallel program has the MPI_COMM_WORLD name. "Empty" communicator that contains no process has the MPI_COMM_NULL name.

The process of rank 0 is often called the master process whereas the other processes are called the slave processes. Typically, the master process plays a special role in relation to the slave processes, sending its data to them or receiving data from all (or some) of the slave processes. In the MPI1Proc2 task all processes must perform the same action, namely, input one integer and output its doubled value, but the master process, in addition, must output the number of all running processes (in other words, the size of the MPI_COMM_WORLD communicator). Note that the processes do not need to exchange messages with each other in this simple task (as in the all other tasks of this group).


PrevNext

 

  Рейтинг@Mail.ru

Designed by
M. E. Abramyan and V. N. Braguilevsky

Last revised:
01.01.2024