⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multicore.html

📁 Multicore - Parallel Processing on Multiple Cores
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<meta http-equiv="content-Type" content="text/html; charset=ISO-8859-1">
	<title>Multicore</title>
</head>
<body>

<h2><font color="#000080">
<a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13775">
Multicore - Parallel Processing on Multiple Cores</a>

</font></h2>

<h3><font color="#000080">
Preamble
</font></h3>

I have put a lot of effort into this contribution to Matlab Central. As I 
used the code successfully for myself for quite some time, I am sure that it can 
be rather valuable for the one or the other. If you find any errors or bugs, 
if you have problems in using the function or if you find the documentation 
insufficiently detailed:

<h4><font color="#AA0000">
Please contact me and give me the chance to help you before giving a bad 
rating on Matlab Central!
</font></h4>

Contact details at the bottom of this page.

<h3><font color="#000080">Discussion group
</font></h3>

Please take the chance to discuss with other users about the package in the discussion group:<br><br>

<a href="http://groups.yahoo.com/group/multicore_for_matlab/">http://groups.yahoo.com/group/multicore_for_matlab/</a>

<h3><font color="#000080">Introduction
</font></h3>

The latest Matlab releases (starting with R2007a) include support for multiple 
cores. However, Matlab will only take advantage of multiple cores in evaluating 
certain computations like an FFT or a FIR filtering operation. Matlab will never 
be able to determine if, for example, consecutive function calls in a for-loop 
are independent of each other.

With this package, I provide some MATLAB-functions realizing parallel processing 
on multiple cores on a single machine or on multiple machines that have access 
to a common directory.<br><br>

If you have multiple function calls that are independent of each other and you 
can reformulate your code as<br><br>

<font face="Courier New" color="#000080"> resultCell = 
cell(size(parameterCell));<br> for k=1:numel(parameterCell)<br> 
&nbsp;&nbsp;resultCell{k} = myfun(parameterCell{k});<br> end<br> </font> <br>

then, replacing the loop by<br><br>

<font face="Courier New" color="#000080"> resultCell = 
startmulticoremaster(@myfun, parameterCell);<br> </font> <br>

allows you to evaluate your loop in parallel in several Matlab processes. All you 
need to do in the other Matlab processes is to run<br><br>

<font face="Courier New" color="#000080">startmulticoreslave;<br> </font> <br>

Please refer to the help comments in file startmulticoremaster.m for possible 
input arguments and more details about how the parallelization works.<br><br>

No special toolboxes are used, no compilation of mex-files is necessary, 
everything is programmed in plain and platform-independent Matlab. If one of 
your slave processes dies - don't care, the master process will go on working on 
the given task.<br><br>

<font color="#000080"><b>Note:</b></font> The Matlab multithreading capability 
(R2007a and higher) might terminate all the advantage gained by using the multicore 
package. So make sure that you <font color="#000080"><b>UNcheck &quot;Enable multihreaded 
computation&quot;</b></font> under File/Preferences/General/Multithreading in all 
involved Matlab sessions.

<h3><font color="#000080">Quick start</font></h3>

For a quick start, first unzip all files into a directory, start Matlab and change 
to this directoy. Then have a look at the heavily commented demo function <font 
color="#000080">multicoredemo.m</font>. Start <font color="#000080">multicoredemo.m
</font> in one Matlab process and <font color="#000080">startmulticoreslave.m</font> in 
another Matlab session.

<h3><font color="#000080">Keywords</font></h3>

Parallel processing, distributed computing, multiple cores.<br>

<h3><font color="#000080">Functions contained in this package</font></h3>

<b><font color="#000080">startmulticoremaster.m</font></b><br>
Takes the function handle (or a cell array of function handles) and the 
parameters and computes the output. Files containing information about which
function to execute with which parameters are saved in a directory and read
by the slave processes. The results saved by the slave processes are later
read.<br><br>

<b><font color="#000080">startmulticoreslave.m</font></b><br>
Loads the files generated by function startmulticoremaster.m and evaluates
the given function. Results are saved in files in the same directory.<br><br>

<b><font color="#000080">multicoredemo.m and testfun.m</font></b><br>
To get into the code, have a look at the demo. You can start it without input 
arguments for a demo on a multi-core machine, or with a common directory to
use for a multi-machine demo.<br><br>

<b><font color="#000080">
setfilesemaphore.m, removefilesemaphore.m and deletewithsemaphores.m
</font></b><br>
A crucial thing is to avoid that several Matlab processes try to open/delete/write 
a file at the same time. Using a simple semaphore technique, exclusive file
access is guaranteed. Also here, no platform-dependent or C-programmed stuff is used.
<br><br>

<b><font color="#000080">existfile.m, existfile.c</font></b><br>
Check if a file exists. To use the faster mex-file, type 
<font face="Courier New" color="#000080">&quot;mex -setup&quot;</font>, 
select the builtin Lcc compiler and type
<font face="Courier New" color="#000080">&quot;mex existfile.c&quot;</font>
to compile the file. However, the package also works without using the mex-file.<br><br>

<b><font color="#000080">findfiles.m</font></b><br>
Returns a list of file names matching a given specification in a cell array.<br><br>

<b><font color="#000080">getusername.m, gethostname.m</font></b><br>
Return the user and host name.<br><br>

<b><font color="#000080">tempdir2.m</font></b><br>
Return the name of a temporary directory.<br><br>

<b><font color="#000080">datenum2.m, translatedatestr.m</font></b><br>
Compensate for some shortcomings in Matlab regarding date conversion.<br><br>

And some more ...

<h3><font color="#000080">Known Issues</font></h3>  

If processing is cancelled by the user (Ctrl-C), catching Matlab just in saving/deleting 
a temporary file, you might get some file access warnings. This is because Matlab 
seems not to release the file correctly (at least under Windows). Besides some annoying 
warnings, the multicore package should work correctly anyway. To get rid of the warning 
messages, you will have to restart the right Matlab process before the file can be deleted. 
<br><br>

The communication between the different Matlab sessions, which is done by saving/loading 
temporary files into a common directory, causes some overhead. Thus, if your function calls 
only need fractions of a second, the overhead may eat the advantage of the parallelization. 
However, the multicore package can do several function evaluations after each other in every 
process before communicating again. In this way the overhead can be minimized. As a rule 
of thumb, the time needed for a bunch of function executions should not be lower than 2 
seconds. If this is the case in your application, the MULTICORE package might not be of any 
help to you.

<h3><font color="#000080">
Contact
</font></h3>  

If you have questions or find any bugs or errors, please drop me an 
<a href="mailto:mb_matlab@gmx.de?subject=multicore">E-mail</a>.<br><br>


Dr.-Ing. Markus Buehren<br>
Stuttgart, Germany<br>
<a href="mailto:mb_matlab@gmx.de?subject=multicore package">mb_matlab@gmx.de</a><br>
<a href="http://www.markusbuehren.de">http://www.markusbuehren.de</a><br>
<br>
<a href="http://groups.yahoo.com/group/multicore_for_matlab/" target="_blank">http://groups.yahoo.com/group/multicore_for_matlab/</a>

<h3><font color="#000080">
Version
</font></h3>  
Last modified 22.02.2009<br>
Latest version on <a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13775">Matlab Central</a>.

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -