Reputation: 81
I have two for loops running in my Matlab code. The inner loop is parallelized using Matlabpool in 12 processors (which is maximum Matlab allows in a single machine).
I dont have Distributed computing license. Please help me how to do it using Octave or Scilab. I just want to parallelize 'for' loop ONLY.
There are some broken links given while I searched for it in google.
Upvotes: 8
Views: 15444
Reputation: 14006
To see a list of Free and Open Source alternatives to MATLAB-SIMULINK please check its Alternativeto page or my answer here. Specifically for SIMULINK alternatives see this post.
something you should consider is the difference between vectorized, parallel, concurrent, asynchronous and multithreaded computing. Without going much into the details vectorized programing is a way to avoid ugly for-loops
. For example map
function and list comprehension on Python is vectorised computation. It is the way you write the code not necesarily how it is being handled by the computer. Parallel computation, mostly used for GPU computing (data paralleism), is when you run massive amount of arithmetic on big arrays, using GPU computational units. There is also task parallelism which mostly refers to ruing a task on multiple threads, each processed by a separate CPU core. Concurrent or asynchronous is when you have just one computational unit, but it does multiple jobs at the same time, without blocking the processor unconditionally. Basically like a mom cooking and cleaning and taking care of its kid at the same time but doing only one job at the time :)
Given the above description there are lot in the FOSS world for each one of these. For Scilab specifically check this page. There is MPI interface for distributed computation (multithreading/parallelism on multiple computers). OpenCL interfaces for GPU/data-parallel computation. OpenMP interface for multithreading/task-parallelism. The feval
functions is not parallelism but a way to vectorize a conventional function.Scilab matrix arithmetic and parallel_run
are vectorized or parallel depending to the platform, hardware and version of the Scilab.
Upvotes: 0
Reputation: 2509
parfor
is not really implemented in octave yet. The keyword is accepted, but is a mere synonym of for
(http://octave.1599824.n4.nabble.com/Parfor-td4630575.html).
The pararrayfun
and parcellfun
functions of the parallel package are handy on multicore machines.
They are often a good replacement to a parfor loop.
For examples, see http://wiki.octave.org/Parallel_package. To install, issue (just once)
pkg install -forge parallel
And then, once on each session
pkg load parallel
before using the functions
Upvotes: 15
Reputation: 2955
In Scilab you can use parallel_run:
function a=g(arg1)
a=arg1*arg1
endfunction
res=parallel_run(1:10, g);
Upvotes: 2
Reputation: 3779
In GNU Octave you can use the parfor
construct:
parfor i=1:10
# do stuff that may run in parallel
endparfor
For more info: help parfor
Upvotes: -1