Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use parallel 'for' loop in Octave or Scilab?

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.

like image 901
han17 Avatar asked Jul 26 '14 11:07

han17


People also ask

How do you run a parallely loop?

We can make a for-loop parallel using the multiprocessing pool. A process pool is a programming pattern for automatically managing a pool of worker processes. The multiprocessing. Pool class provides a process pool with helpful functions for executing for loops in parallel.

Can for loops be parallel?

Can any for loop be made parallel? No, not any loop can be made parallel. Iterations of the loop must be independent from each other. That is, one cpu core should be able to run one iteration without any side effects to another cpu core running a different iteration.

How does a parallel loop work?

In a parallel loop, the parallel processors execute the same code region, namely, the loop body, but with different data. Thus, parallel loops are a special kind of SPMD programming. Typically, parallel loops are used within a shared memory programming model, for example, OpenMP and Intel's Threading Building Blocks.


2 Answers

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

like image 90
ederag Avatar answered Sep 20 '22 18:09

ederag


In Scilab you can use parallel_run:

function a=g(arg1)
  a=arg1*arg1
endfunction

res=parallel_run(1:10, g);

Limitations

  • uses only one core on Windows platforms.
  • For now, parallel_run only handles arguments and results of scalar matrices of real values and the types argument is not used
  • one should not rely on side effects such as modifying variables from outer scope : only the data stored into the result variables will be copied back into the calling environment.
  • macros called by parallel_run are not allowed to use the JVM
  • no stack resizing (via gstacksize() or via stacksize()) should take place during a call to parallel_run
like image 21
spoorcc Avatar answered Sep 17 '22 18:09

spoorcc