How can I rewrite this more efficiently taking advantage of flo
, dem
, and Nsup
being Listable
and utilize parallel computation?
MapThread[flo[#1, #2, #3] &, {Most /@ kr, Rest /@ Rk, Most /@ qsum}, 2]
kr = Table[RandomReal[50], {10}, {5}];
Rk = Table[RandomReal[150],{10}, {5}];
qsum = Table[RandomReal[6000], {10}, {5}];
flo =
Compile[{{p1, _Real, 0}, {p2, _Real, 0}, {p3, _Real, 0}},
Min[dem[p1], Nsup[p2, p3]],
Parallelization -> True,
RuntimeAttributes -> {Listable},
CompilationOptions -> {"InlineExternalDefinitions" -> True}];
dem =
Compile[{{p1, _Real, 0}},
Min[100 p1, 2500],
Parallelization -> True,
RuntimeAttributes -> {Listable}];
Nsup =
Compile[{{p1, _Real, 0}, {p2, _Real, 0}},
Min[(150 - p1) 100 - p2, 2500],
Parallelization -> True,
RuntimeAttributes -> {Listable}];
I am thinking it to be of the form (currently does not work)
flo1[kr, Rk, qsum];
floR1 =
Compile[{{p1, _Real, 0}, {p2, _Real, 0}, {p3, _Real, 0}},
MapThread[Min[demR[#1], NsupR[#2, #3]] &, {Most /@ p1, Rest /@ p2, Most /@ p3}, 2],
Parallelization -> True,
RuntimeAttributes -> {Listable},
CompilationOptions -> {"InlineCompiledFunctions" -> True}];
or something that avoids MapThread
altogether, because I suspect MapThread
does serial computation.