Introduction
Sooner or later, the user of the Matlab / Simulink package is faced with the problem of insufficient performance of the computer on which it works. I faced also.
The first thing that came to mind was the modernization of iron. I work on an old laptop, and so I started thinking about a stationary PC. But this did not promise a big performance increase, and indeed this is a gamer's method but not an engineer.
Details under the cut >>
')
Based on the fact that this was my first experience in using parallel computing, the topic is also intended for beginners. To connoisseurs of parallel computing I would like to express my deep gratitude for the kind advice and comments of my actions.
So:
- New computer.
As I mentioned above, for a comfortable “scientific” work I needed just a “gaming” PC, having a multi- core processor and a graphics accelerator with a cuda capability of at least 1.3 . Expensive and not scalable. I was sure that I would master the unbridled power rather quickly, and it would not be enough again. - Optimization / minimization / refinement of models and code.
I have already traveled this path before I ran into the ceiling of the capabilities of my laptop. The method has completely exhausted itself when the time for modeling the situation has become longer than the standard coffee / tea drinking time. “You can start the simulation and go to sleep!”, The knowledgeable will say, but for this you need to have an already optimized model and a clear idea of ​​how it will behave. I also needed performance in the initial stages of development. - Use of the computing cluster.
There was no cluster at hand, and on such as Uranus you need to knock for a long time. And the formulation of the problem is not very suitable for the use of third-party resources. I was not ready to run the task once and collect the results. This was still far away.
As a result, it was decided to build a small one, but
with a blackjack cluster.
Iron search
Hoping for the predominance of good in our world, I turned to colleagues and friends for help. As a result, some volunteered and provided their PCs for my experiment. There were several options, but I had to choose only two cars. I will try to explain why:
- Everyone had a core i7 processor onboard. Four cores gave 2 virtual ones. So I had the opportunity to create 16 virtual WORKERs based on them, which is pretty good. Plus, the entire memory was operational in one 6 and in the other 8 Gb.
- They were in the same local area network, which was simply necessary to minimize the time spent on transferring data between virtual laboratories. To connect with this network, I raised the VPN channel, and to work with each PC I set up a standard remote desktop.
The cons were also present:
- Both PCs worked under Windows 7 x64, whereas my laptop was with the x86 operating system. One of the mandatory requirements for a Matlab cluster is the uniform bitness of the operating systems used. As a result, I lost the opportunity to add two more WORKERs to the cluster based on the processor of my laptop.
- The video cards' s juda capability were less than 1.3, and they also failed to include them in the bundle.
But since the advantages still outweighed, the first stone of the cluster on the knee was laid.
Build a cluster
Software Requirements
I have highlighted the requirements for iron. Software requirements are as follows:
- Matlab on every machine.
Do not do without the platform. - Distributed Computing toolbox (DCT) on each machine.
- MATLAB Distributed Computing Engine (MDCE) on each machine.
Both toolboxes work only together. - The compiler is different from the standard Matlab compiler.
On machines with a 64bit operating system, if we are going to use them as a host to compile the Simulink model into C code. Matlab offers a long list of supported compilers, some of which are free. I used Microsoft Visual C ++ 2010. - Simulink and other extensions depending on the type of activity.
Cluster startup
First, install and run MDCE as a service on each machine. This can be done both without leaving Matlab (using the "!" Sign performs the Matlab command as a system command) or using the command line. The * .bat files for this are relative to the Matlab installation directory along the path \ toolbox \ distcomp \ bin \.
Install and run MDCE on each machine:
cd('C:\Program Files\MATLAB\R2010b\toolbox\distcomp\bin\')
!mdce install
!mdce start
We start the scheduler, which will manage parallel computing:
!startjobmanager -name jm -v
The -v parameter is responsible for the detailed display of the startup process in the Matlab command window. Scheduler can be run remotely on any PC in our possession.
We start the cycle of so-called workers (worker), which will carry out the tasks assigned to them in parallel:
clientHost = 'slovak';
node = {'slovak', 'puls'};
for i = 1:length(node)
for j = 1:8
str = ['!startworker -name w_' num2str(j) '_' node{i} ' -jobmanagerhost ' clientHost ' -jobmanager jm -remotehost ' node{i} ' -v'];
eval(str)
end
end
The 'slovak' host is the computer on which the scheduler is running. In my case, this is one of the working PCs. I had to rename, because the previous name was in Cyrillic, which Matlab does not tolerate.
After the creation of work
horses, we can admire our cluster:
!nodestatus -infolevel 3
The -infolevel 3 parameter for detailed information about nodes.
...
Job manager:
Name jm
Running on host Slovak
Number of workers 16
...
You can manage the cluster using the GUI. To do this, in the folder with the batch file there is a file admincenter.bat, which launches the administration utility. In our case, it looks like this:

At the time of writing the article, PC puls “fell off” and therefore only 8 workers in the admin center.
Next we need to find the created scheduler using Matlab:
jm = findResource('scheduler','type','jobmanager', ...
'LookupURL', 'slovak:27350', 'Name', 'jm');
After this step, you can solemnly cut the ribbon and confidently assume that our cluster is created and ready to work. Next, you need to properly distribute the work between the nodes, to organize access to shared resources and much more. I also want to note that at this stage we can run parallel tasks only from Matlab. In order to parallelize the Simulink model I had to dance with a tambourine more than once. As a result, I radically changed the concept of all my work specifically for the convenience of parallel solution, but this is a topic for a separate topic.
Information on the topic was drawn from the following resources:
- Matlab website
- Matlab User Blogs
- Russian-language user forum Matlab
- N.N. Olenev, R.V. Pechenkin, A.M. Chernetsov Parallel Programming in MATLAB and Its Applications Moscow: EC of the Russian Academy of Sciences, 2007. 120 p.
- Method of
scientific trial and error
Thank you for attention!
PS: All the work done was done with the Matlab R2010b version, but when I glanced at the distcomp folder of the new version of the R2011a, at first glance, the work with the mathworks team was not a small one. Unfortunately, the new version is not yet available, but as soon as I get the opportunity I will try to highlight the innovations that it can offer us. Although now I'm more busy generating C code from the Simulink model for microcontrollers.