Привет! Расскажи как работает данный код

#include <stdio.h>
#include "mpi.h"
#include <iostream>
#include <Windows.h>
#include "math.h"
#include "stdlib.h"
#include <ctime>

using namespace std;

#define n 2
#define ochmax 7
#define lmax 20

int main(int* argc, char** argv)
{
	SetConsoleCP(1251);
	SetConsoleOutputCP(1251);

	int size, rank;
	if (MPI_Init(argc, &argv) != MPI_SUCCESS)
		return 1;
	if (MPI_Comm_size(MPI_COMM_WORLD, &size) != MPI_SUCCESS)
	{
		MPI_Finalize();
		return 2;
	}
	if (MPI_Comm_rank(MPI_COMM_WORLD, &rank) != MPI_SUCCESS)
	{
		MPI_Finalize();
		return 3;
	}

	srand(time(NULL));
	int balance = 100;
	int mag[ochmax][n];
	int z[n];
	int* p, * nmag, kmax = size - 1;
	int pr = 1;
	p = nmag = *mag;

	MPI_Status status;

	//определим начальные значения для банка и для клиентов
	if (!rank)
	{
		p = nmag = *mag;
		balance = 100;
		kmax = size - 1;
	}
	if (rank)
	{
		z[0] = rand() % 2;
		z[1] = (rand() % 100) * rank;
	}

	//основной жизненный цикл
	for (int l = 0; l < lmax; l++)
	{
		if (!rank)
			cout << l + 1 << " day!" << endl;
		MPI_Barrier(MPI_COMM_WORLD);
		if (!rank) //bank
		{
			kmax = size - 1 - (p - nmag) / 2;
			for (int i = 0; i < kmax; i++)
			{
				MPI_Recv(z, n, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
				if (z[0])
				{
					balance += z[1];
					pr = 1;
					MPI_Send(&pr, 1, MPI_INT, status.MPI_SOURCE, 0, MPI_COMM_WORLD);
					cout << "bank takes " << z[1] << "$ from client " << status.MPI_SOURCE << "!" << endl;
				}
				else
				{
					if (z[1] > balance - 5)
					{
						*p = status.MPI_SOURCE;
						p++;
						*p = z[1];
						p++;
						cout << "bank can not give " << z[1] << "$ to client " << status.MPI_SOURCE << "!" << endl;
					}
					else
					{
						balance -= z[1];
						pr = 1;
						MPI_Send(&pr, 1, MPI_INT, status.MPI_SOURCE, 0, MPI_COMM_WORLD);
						cout << "bank gives " << z[1] << "$ to client " << status.MPI_SOURCE << "!" << endl;
					}
				}
			}
			//work with queue
			int flag = 1;
			//cout << balance - 5 << endl;
			while ((p != nmag) && flag)
			{
				cout << "the queue is not empty! queue`s lenght = " << (p - nmag) / 2 << "!" << endl;
				int m = *nmag;
				int sum = *(nmag + 1);
				if (sum < balance - 5)
				{
					balance -= sum;
					pr = 1;
					MPI_Send(&pr, 1, MPI_INT, m, 0, MPI_COMM_WORLD);
					cout << "bank gives " << sum << "$ to client " << m << "!" << endl;
					//sdvig of queue
					for (int j = 0; j < (p - nmag) / 2; j++)
					{
						*(nmag + j * n) = *(nmag + j * n + 2);
						*(nmag + j * n + 1) = *(nmag + j * n + 3);
					}
					p -= 2;
				}
				else {
					break;
				}
			}
			for (int j = 0; j < (p - nmag) / 2; j++)
			{ 
				int m = *(nmag + j * 2);
				pr = 0;
				MPI_Send(&pr, 1, MPI_INT, m, 0, MPI_COMM_WORLD);
			}
			if ((p - nmag) / 2 == ochmax)
			{
				cout << "bank is a bankrupt!" << endl;
				for (int j = 0; j < (p - nmag) / 2; j++)
				{
					int m = *(nmag + j * 2);
					pr = -1;
					MPI_Send(&pr, 1, MPI_INT, m, 0, MPI_COMM_WORLD);
				}
				break;
			}
		}
		else //clients
		{
			if (pr == -1)
				break;
			else
			{
				if (pr)
				{
					MPI_Send(z, n, MPI_INT, 0, 0, MPI_COMM_WORLD);
					if (z[0])
						cout << "client " << rank << " puts " << z[1] << "$ in the bank!" << endl;
					else
						cout << "client " << rank << " takes " << z[1] << "$ from the bank!" << endl;
				}
				MPI_Recv(&pr, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
				if (pr)
				{
					z[0] = rand() % 2;
					z[1] = (rand() % 100) * rank;
				}
			}
		}
	}

	MPI_Finalize();

	system("pause");
	return 0;
}