Install and start using the MPI library
Sometimes it is necessary to run an application on multiple machines (or processors) in order to improve performance (i.e. reduce execution time). You can create a computer network for subsequent launch of the application distributed across all nodes. When developing such an application, you need to organize messaging. I know two implementations:
In order to start working with the MPICH2 library, you need to download the product version compatible with your operating system here . For Windows, this is an installation package of the MSI format, so the installation of the library takes place in a standard way. It is important that the installation in this case must be carried out for all users of the system.
Now you need to add the two main library executables mpiexec.exe and smpd.exe to the list of firewall rules. This is necessary because, when organizing a cluster, a network is used and access to each network node must be allowed for MPI components. The specific settings depend on the type of firewall used.
The next step is to create a user in the system on behalf of which the library components will be executed. It is important that this user must have his password, because MPICH2 does not allow registering an executing user with an empty password. Registration is carried out using the wmpiregister.exe component located in the bin folder of the library and having a clear window interface:

However, this can be done using the console command [path to the library] / bin / mpiexec -register .
Installation is almost complete. It remains to verify the correctness of all the settings made. For this purpose, in the examples folderThere are examples of programs with parallel algorithms. To start, you can use the wmpiexec.exe component , which uses a window interface that does not need additional comments.

Another way to execute applications using MPI is through the console, for example, by writing a similar command [path_to_library] / bin / mpiexec -n 2 cpi.exe , where -n 2 indicates the number of processes involved (here there are 2), and cpi.exe - This is the name of the executable application. For ease of operation through the console, I advise adding the path to mpiexec.exe to the PATH environment variable. If the application is executed on a single-processor machine, then multiprocessing is emulated, i.e. You can check the performance of your applications "on the spot."
MVS 2005 is used as the development IDE. We will write a program that will welcome this world on behalf of various newborn processes. For this, an empty project is used with some project settings changed.
So, first of all, add the directories where the plug-in header files and library files will lie. If someone does not know, then this is done as follows:
The project is fully ready to work with MPI. I can advise you to create a filter for library files added to the project so that they do not interfere. Now add the cpp file with the application code:
We compile it and run the resulting binary via wmpiexec on 4 processes.

As you can see, the world welcomed every born process.
I deliberately cited the code without any comments, but only for the purpose of demonstrating the library. In the future I plan to devote an article to the list of MPI functions. Also interesting is the topic of excessive parallelism and, in general, the question of when to parallelize an application and when not. These studies will also be given later. Therefore, I had the main question - the scope of applicability in web technologies? So far, my interest in parallel computing has been caused by another problem: accelerating the modeling of various processes.
- using sockets and working with the OS API directly,
- use of MPI.
Installing MPICH2 Library under Windows
In order to start working with the MPICH2 library, you need to download the product version compatible with your operating system here . For Windows, this is an installation package of the MSI format, so the installation of the library takes place in a standard way. It is important that the installation in this case must be carried out for all users of the system.
Now you need to add the two main library executables mpiexec.exe and smpd.exe to the list of firewall rules. This is necessary because, when organizing a cluster, a network is used and access to each network node must be allowed for MPI components. The specific settings depend on the type of firewall used.
The next step is to create a user in the system on behalf of which the library components will be executed. It is important that this user must have his password, because MPICH2 does not allow registering an executing user with an empty password. Registration is carried out using the wmpiregister.exe component located in the bin folder of the library and having a clear window interface:

However, this can be done using the console command [path to the library] / bin / mpiexec -register .
Installation is almost complete. It remains to verify the correctness of all the settings made. For this purpose, in the examples folderThere are examples of programs with parallel algorithms. To start, you can use the wmpiexec.exe component , which uses a window interface that does not need additional comments.

Another way to execute applications using MPI is through the console, for example, by writing a similar command [path_to_library] / bin / mpiexec -n 2 cpi.exe , where -n 2 indicates the number of processes involved (here there are 2), and cpi.exe - This is the name of the executable application. For ease of operation through the console, I advise adding the path to mpiexec.exe to the PATH environment variable. If the application is executed on a single-processor machine, then multiprocessing is emulated, i.e. You can check the performance of your applications "on the spot."
Health Check
MVS 2005 is used as the development IDE. We will write a program that will welcome this world on behalf of various newborn processes. For this, an empty project is used with some project settings changed.
So, first of all, add the directories where the plug-in header files and library files will lie. If someone does not know, then this is done as follows:
- Select the menu item Tools => Options.
- In the “Show directories for:” dropdown, select the “Include files” item.
- Add [path_to_library] \ Include
- In the “Show directories for:” dropdown, select the “Library files” item.
- Add [path_to_library] \ Lib
- In Solution Explorer, right-click on the project and select add => existing item. Select all files with the extension .lib in the folder [path_to_library] \ Lib
The project is fully ready to work with MPI. I can advise you to create a filter for library files added to the project so that they do not interfere. Now add the cpp file with the application code:
#include "stdio.h"
#include "mpi.h"
#include "stdlib.h"
#include "math.h"
int ProcNum;
int ProcRank;
int main(int argc, char *argv[]){
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &ProcRank);
MPI_Comm_size(MPI_COMM_WORLD, &ProcNum);
printf("From process %i: Hello, World!\n", ProcRank);
MPI_Finalize();
}
* This source code was highlighted with Source Code Highlighter.
We compile it and run the resulting binary via wmpiexec on 4 processes.

As you can see, the world welcomed every born process.
I deliberately cited the code without any comments, but only for the purpose of demonstrating the library. In the future I plan to devote an article to the list of MPI functions. Also interesting is the topic of excessive parallelism and, in general, the question of when to parallelize an application and when not. These studies will also be given later. Therefore, I had the main question - the scope of applicability in web technologies? So far, my interest in parallel computing has been caused by another problem: accelerating the modeling of various processes.