# Parallelization in Octave using parcellfun/pararrayfun

My computer has many processors and I would like to run some octave scripts so that all the processors are being used.
One can use octave function called “pararrayfun” for this purpose. This function is part of “general” package on octave-forge.

On my ubuntu 11.10, I used “sudo apt-get install octave-general” to install this package and ran the following script

1; # this is kept to Prevent Octave from thinking that this is a function file:

close all;
clear all;

function y=test(a,b)
y=sin(a)+cos(b)
endfunction

num_process=8

a_test_inputs=[0:3.14/20:3.14];
b_test_inputs=[0:3.14/20:3.14]*2;

tic ();
tt_par= pararrayfun(num_process,@test,(a_test_inputs),(b_test_inputs));
parallel_elapsed_time = toc ()

tic ();
tt_ser= test((a_test_inputs),(b_test_inputs));
serial_elapsed_time = toc ()

plot(a_test_inputs,tt_par,'-o',a_test_inputs,tt_ser,'-s');
legend('Parallel result','Serial result');

disp(sprintf('Elapsed time during serial computation is %e',serial_elapsed_time))
disp(sprintf('Elapsed time during parallel computation is %e',parallel_elapsed_time))

## 2 thoughts on “Parallelization in Octave using parcellfun/pararrayfun”

1. Mike says:

I did not know you could define a function in a script file. Cool. Do you think this would work on a windows system? I might give it a try.

2. Pingback: John Henry