From: neuromath on
Hello,

I have a system of hundreds of coupled ODEs that are being solved
explicitly. I am using a standard RK4 algorithm to solve my system at
each time step, and the solution at each time step is solely dependent
upon the preceding time step:

y_n = y_n(y_(n-1), dt)

What I am trying to do is basically the following: I want one
processor to solve one part of y_n and another processor to solve
another part of y_n. Because these parts are independent of each
other, it might benefit from distributed computing. We have access to
the Parallel Computing Toolbox of MATLAB, and this is all being done
on the workers of a local machine. For one time step, my pseudocode
might look something like:

proc0 solve y_n(1:10) which depends on most of y_(n-1) but not on y_n
proc1 solve y_n(11:20) which depends on most of y_(n-1) but not on y_n

put y_n back together for the next iteration. In my code, there is a
very clear delineation of what would make sense to break up into
pieces. For instance, I could say, proc0 should just solve the y_n
associated with Cell A. proc1 will solve all the y_n associated with
Cell B.

I didn't think parfor was a good candidate for this, since I cannot
simply iterate over all time steps, and y_n depends on y_(n-1).
Additionally, all of the y_n have to be reconstituted in the way I'm
thinking about this. Currently, my vector field is defined all in one
file, but this can be split up into N_files as makes sense. If so, I
suppose I could do:

parfor n = 2:N_t
k_cellA_1 = vf_A(y0)
k_cellB_1 = vf_B(y0)
k1 = [k_cellA_1, k_cellB_1]
yt1 = y0 + dt/2 * k1

.
.
.
end

I would want parfor to put vf_A and vf_B on two different processors.
Would parfor or something else be the best solution?

Any suggestions on how this might be achieved would be greatly
appreciated.